<?php
$data    = array();
$sql     = "SELECT COUNT(*) as count from interessados $conditions";
$command = Yii::app()->db->createCommand($sql);
$total   = $command->queryAll();
if (isset($total[0]['count'])) {
	$total = (int) $total[0]['count'];
} else {
	$total = 0;
}
foreach ($model->getSituacoes() as $key => $situacao) {
	$cd      = empty($conditions)?" where INT_SITUACAO = ".$key:$conditions." AND INT_SITUACAO = ".$key;
	$sql     = "SELECT COUNT(*) as count from interessados $cd";
	$command = Yii::app()->db->createCommand($sql);
	$result  = $command->queryAll();
	if (isset($result[0]['count'])) {
		$result = $result[0]['count'];
	}

	$data[] = [$situacao, ((int) $result)];
}

$this->widget('ext.highcharts.HighchartsWidget', array(
		'scriptPosition' => CClientScript::POS_END,
		'scripts'        => array(
			'modules/exporting',
			/*'modules/offline-exporting',*/
			'modules/canvas-tools',
			/*'modules/export-csv',*/
			/*'modules/jspdf',*/
			'modules/export-clientside',
			'modules/pie',
		),
		'options' => array(
			'title'  => array(
				'text'  => 'Status atual',
			),
			'lang'                => array(
				'printChart'         => 'Imprimir Gráfico',
				'downloadPNG'        => '',
				'downloadJPEG'       => '',
				'downloadSVG'        => 'Download imagem (vetor SVG)',
				'downloadPDF'        => '',
				'contextButtonTitle' => 'Opções',
				'loading'            => 'Carregando...',
				'downloadCSV'        => '',
				'downloadXLS'        => 'Download excel (xls)',
				'viewData'           => '',
			),
			'chart'        => array(
				'type'        => 'pie',
				'style'       => array(
					'fontFamily' => 'Arial, Helvetica, sans-serif',
				),
				'plotBackgroundColor' => null,
				'plotBorderWidth'     => null,
				'plotShadow'          => false,
			),
			'series' => array(
				array(
					'name' => 'Interessados',
					'data' => $data,
				)
			),
			'plotOptions'        => array(
				'pie'               => array(
					'allowPointSelect' => true,
					'cursor'           => 'pointer',
					'dataLabels'       => array(
						'enabled'         => true,
						'format'          => '<b>{point.name}</b>: {point.y}/{point.total} ({point.percentage:.1f}%)',
						'color'           => '(Highcharts.theme && Highcharts.theme.contrastTextColor) || "black"',
					),
				)
			),
			'tooltip'      => array(
				'pointFormat' => '{series.name}: <b>{point.y}/{point.total} ({point.percentage:.1f}%)</b>',
			),
			'legend'  => array(
				'enable' => false,
			),
			'credits'  => array(
				'enabled' => false
			),
			'exporting'      => array(
				'printMaxWidth' => 1000,
				'width'         => 1000,
				'filename'      => Util::slug('grafico_atendimentos_'.date('d_m_Y_H_i_s'))
			)
		)
	)
);
?>