<?php

class ProcessTask extends Shell {
   
	var $uses = array('Site', 'Schedule', 'Criterium');
   
	const BATCH_PROCESS = 2;
	
	function execute()
	{
   		$this->out('Processing schedule');
   		$this->Schedule->recursive = 0;
		
		for ($i = 0; $i < 5; $i++)
		{
			$schedule = $this->Schedule->find('first');
			
            
			if (!empty($schedule))
			{
				switch ($schedule['Schedule']['criterium'])
				{
					case CriteriumValue::GOOGLE_PAGERANK :
						$rank = $this->GooglePagerank->getRank($schedule['Site']['url']);
						break;
					case CriteriumValue::ALEXA_RANK :
						$rank = $this->Alexa->getRank($schedule['Site']['url']);
						break;
					case CriteriumValue::W3C_VALIDITY :
						$rank = $this->W3c->getRank($schedule['Site']['url']);
						break;
				}
				
				$data = array(
	           		'criterium' => $schedule['Schedule']['criterium'],
	           		'site' => $schedule['Schedule']['site'],
	           		'value' => $rank,
	           		'time' => date('Y-m-d h:i:s'),
	            );
	            $this->Criterium->CriteriumValue->create();
	            $this->Criterium->CriteriumValue->save($data);
	            $this->Schedule->remove($schedule['Schedule']['id']);
			}
		}
	}
}

?>