<?php

/*ICS Activities, included with iCrew v4.1 (EXPREMIMENTAL)
	Add to activity when : 
	1. Two users are friends
	2. Friend files a report PIREPS.php Line 491.
	3. New News Item. Done.
	4. Awards Granted. NOT YET DONE.
	5. New Tour
	6. New Charter Leg
	7. New Route Done. All on Operations Admin Page.
	8. New Pilot Promotion. Done. RanksData.class.php
	9. New Profile Update (Hub Change?)
	10.New Aircraft, Airport All on Operations Admin Page.
	11. Aircraft Sent to maintenance. Done.
	12. Aircraft retrived from maintenance
	13. Changelogs
	14. New Screenshot. On Screenshots.php 
*/

/*$name = Auth::$userinfo->firstname.' added a News Item "'.$this->post->subject.'". Check it out <a href="http://icrew.ariaairways.org/index.php/news">here</a>';
		$posted_by = 'Admin Bot';
		$privacy = '0';
		ICSActs::new_ics_activity($name, $posted_by, $privacy);
	*/
	
	
class ICSActs extends CodonData {
	
	
	public static function humanTiming ($time)
{

    $time = time() - $time; // to get the time since that moment
    $time = ($time<1)? 1 : $time;
    $tokens = array (
        31536000 => 'year',
        2592000 => 'month',
        604800 => 'week',
        86400 => 'day',
        3600 => 'hour',
        60 => 'minute',
        1 => 'second'
    );

    foreach ($tokens as $unit => $text) {
        if ($time < $unit) continue;
        $numberOfUnits = floor($time / $unit);
        return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'');
    }

}
	public static function new_ics_activity($name, $posted_by, $privacy) {
		
		$sql = "INSERT INTO `icrewsystems_activities` (`name`, `by`, `date`, `privacy`) 
		VALUES ('".$name."', '".$posted_by."', CURRENT_TIMESTAMP, '".$privacy."')";
	
		 return DB::get_results($sql);
		 
	}
	
	public static function getAllact() {
		
		$sql = 'SELECT * FROM `icrewsystems_activities` ORDER BY `date` DESC';
				
		 return DB::get_results($sql);
		 
	}
	
	public static function widgets() {
		
		$sql = 'SELECT * FROM `icrewsystems_activities` ORDER BY `date` DESC LIMIT 40';
				
		 return DB::get_results($sql);
		 
	}
	
	
}
