<?php

	class CronSynchronizerModel {
		protected $bUseCron = false;
		protected $created_at = 0;
		protected $cron_delay = 0;
		protected $max_exec_time = 0;

		public function __construct( $use_cron = false ) {
			$this->bUseCron = $use_cron;
			$this->created_at = fo3_time();
			$this->max_exec_time = ini_get( "max_execution_time" );
			$this->cron_delay = 60;
		}

		public function timeLeftFromScript() {
			$timelapsed = fo3_time() - $this->created_at;
			$timeleft = $this->max_exec_time - $timelapsed;
			return $timeleft;
		}

		public function timeLeftFromCron() {
			if (!$this->bUseCron) return 999;	// ha nincs cron akkor nagyon sok idonk van
			$time = fo3_time();
			$nextcron = ((int)(($time+$this->cron_delay-1)/$this->cron_delay))*$this->cron_delay;
			return $nextcron-$time;
		}

		public function timeLeft( ) {
			$retval = array();
			$retval["script_time"] = $script_time = $this->timeLeftFromScript();
			$retval["cron_time"] = $cron_time = $this->timeLeftFromCron();
			$retval["overall_time"] = ($script_time>$cron_time) ? $cron_time : $script_time;
			return $retval;
		}
	}

?>
