contributions/voting/view/widgets/votingresult.widget.php
Go to the documentation of this file.00001 <?php 00002 /** 00003 * A widget to print a voting result 00004 */ 00005 class WidgetVotingResult implements IWidget { 00006 public $instance; 00007 public $params; 00008 00009 /** 00010 * Output voting result for given instance 00011 * 00012 * $params get set on view 00013 * 00014 * @param IDataObject $instance 00015 * @param array $params 00016 */ 00017 public static function output($instance, $params = array()) { 00018 $w = new WidgetVotingResult($instance, $params); 00019 return $w->render(); 00020 } 00021 00022 public function __construct($instance, $params) { 00023 $this->instance = $instance; 00024 $this->params = $params; 00025 } 00026 00027 public function render($policy = self::NONE) { 00028 Load::models('votesaggregates'); 00029 $inst = $this->instance; 00030 $dao_avg = ($inst instanceof DAOVotesaggregates) ? $inst : VotesAggregates::get_for_instance($inst); 00031 $avg = ($dao_avg) ? $dao_avg->get_average() : 0; 00032 $count = ($dao_avg) ? $dao_avg->numtotal : 0; 00033 00034 $view = ViewFactory::create_view(IViewFactory::MESSAGE, 'widgets/votingresult'); 00035 $view->assign('average', $avg); 00036 $view->assign('count', $count); 00037 $view->assign('instance', $inst); 00038 foreach(Arr::force($this->params, false) as $var => $value) { 00039 $view->assign($var, $value); 00040 } 00041 return $view->render(); 00042 } 00043 }