<?php

App::import('Controller', array('Webval'));

class ResultsController extends WebvalController {
	
	var $uses = array('Site');
	var $components = array('Auth', 'Alexa', 'GooglePagerank', 'FusionCharts.FusionCharts', 'W3c');
	var $helpers = array('FusionCharts.FusionCharts');
	
	function index()
	{
		$this->Site->recursive = 0;
		$sites = $this->Site->find('all');
		//debug($sites);
		$fp = FirePHP::getInstance(true);
		
		$this->Site->CriteriumValue->Criterium->recursive = 0;
		$criteria = $this->Site->CriteriumValue->Criterium->find('all');
		
		$siteNames = array();
		$datasets = array();
		foreach ($criteria as $key => $criterium)
		{
			$datasets[$criterium['Criterium']['id']] = array();
		}
		
		foreach ($sites as $site)
		{
			//$fp->log($site, 'site');
			$siteNames[] = $site['Site']['title'];
			foreach ($criteria as $criterium)
			{
				$value = $this->Site->CriteriumValue->find('first',
					array('conditions' => array(
						'CriteriumValue.site' => $site['Site']['id'],
						'CriteriumValue.criterium' => $criterium['Criterium']['id'],
					))
				);
				//$fp->info($value, 'value');
				$datasets[$criterium['Criterium']['id']][] = array('value' => intval($value['CriteriumValue']['value']));
			}			
		}
		//$fp->info($datasets);
		
		$this->FusionCharts->create
			(
				'All Criteria',
				array
				(
					'type' => 'MSColumn3D',
					'width' => 800,
					'height' => 400,
					'id' => ''
				)
			);

		$this->FusionCharts->setChartParams
			(
				'All Criteria',
				array
				(
					'caption'					=> 'Všetky kritériá',
					'subcaption'				=> '',
					'xAxisName'					=> 'Stránka',
					'yAxisName'					=> 'Hodnota',
					'hoverCapBg'				=> 'DEDEBE',
					'hoverCapBorder'			=> '889E6D',
					'rotateNames'				=> '0',
					'yAxisMaxValue'				=> '10',
					'numDivLines'				=> '9',
					'divLineColor'				=> 'CCCCCC',
					'divLineAlpha'				=> '80',
					'decimalPrecision'			=> '0',
					'showAlternateHGridColor'	=> '1',
					'AlternateHGridAlpha'		=> '30',
					'AlternateHGridColor'		=> 'CCCCCC'
				)
			);

		$this->FusionCharts->setCategoriesParams
			(
				'All Criteria',
				array
				(
					'font' => 'Arial',
					'fontSize' => '11',
					'fontColor' => '000000'
				)
			);

		$this->FusionCharts->addCategories
			(
				'All Criteria',
				$siteNames
			);

		$this->FusionCharts->addDatasets
			(
				'All Criteria',
				array
				(
					'Google PageRank' => array
					(
						'params' => array('color' => 'FDC12E'),
						'data' => $datasets[CriteriumValue::GOOGLE_PAGERANK],
					),
					'Alexa' => array
					(
						'params' => array('color' => '56B9F9'),
						'data' => $datasets[CriteriumValue::ALEXA_RANK],
										),
					'W3C' => array
					(
						'params' => array('color' => 'C9198D'),
						'data' => $datasets[CriteriumValue::W3C_VALIDITY],
					)
				)
			);

	}
	
}
?>