Location: PHPKode > projects > Content*Builder > contentbuilder/lib/patPollsBarRenderer.php
<?php

/**
* patPolls simple bar graph renderer ( Use this renderer as default template for your own renderer )
* 
* Features: render poll results as bars
*
* @package		patPolls
* @access		public	
* @author		Stephan Schmidt <hide@address.com>, Sebastian Mordziol <hide@address.com>
* @version		0.01
*/
class	patPollsBarRenderer extends patPollsRenderer
{
	var	$options	=	array(	"maxWidth"	=>	400 );

/**
* renders the results from the poll using the barGraph template. This is the only function you normally need to extend to write your
* own renderer.
*
* @access		public
*/
	function	render()
	{
		// calculate ratio to display bar widths
		$maxvalue	=	$this->getMaxVotes();

		// check wether the total amount of writeins we display is higher than the max votes value
		$totalwriteins	=	$this->getWriteinVotes();
		if( $totalwriteins > $maxvalue ) {
			$maxvalue	=	$totalwriteins;
		}

		// now we can calculate the ratio
		$ratio = 0;
		if($maxvalue != 0 || $maxvalue != "") {
			$ratio		=	$this->getOption( "maxWidth" ) / $maxvalue;
		}
		
		// retrieve percentages
		$this->calculatePercentages();
		
		// write needed data into the variable sent to the template
		for( $i=0; $i<count( $this->answerdata ); $i++ )
		{
			$bardata[width][]	=	$this->answerdata[$i][count] * $ratio;
			$bardata[answer][]	=	$this->answerdata[$i][answer];
			$bardata[percent][]	=	round( 100 * $this->answerdata[$i][percent] * 100 ) / 100;
		}
		$bardata[width][]		=	$totalwriteins * $ratio;
		$bardata[answer][]		=	"writein";
		$bardata[percent][]		=	round( 100 * $totalwriteins / $this->getTotalVotes() * 100 ) / 100;

		for( $i=0; $i<count( $this->writeindata ); $i++ )
		{
			$writeins	.=	$this->writeindata[$i][answer]." (".$this->writeindata[$i][count]."), ";
		}
		
		$writeins		=	substr ( $writeins, 0, -2 ); 
		
		$this->poll->template->assign( "barData", $bardata );
		$this->poll->template->assign( "PR_SUM", $this->getTotalVotes() );
		$this->poll->template->assign( "PR_WRITEINS", $writeins );
		
		return $this->poll->template->fetch( "patPollsBarRenderer.tmpl", "", "", true );
	}
	
}
?>
Return current item: Content*Builder