contributions/voting/model/classes/votes.facade.php
Go to the documentation of this file.00001 <?php 00002 Load::models('votesaggregates'); 00003 00004 /** 00005 * Facade class for votes 00006 */ 00007 class Votes { 00008 /** 00009 * Create adapter to find votes for instance 00010 * 00011 * @return DAOVotes 00012 */ 00013 public static function create_instance_adapter(IDataObject $inst) { 00014 $dao = new DAOVotes(); 00015 $dao->instance = $inst; 00016 return $dao; 00017 } 00018 00019 /** 00020 * Find all votes for instance 00021 * 00022 * @param IDataObject $inst 00023 * @return array 00024 */ 00025 public static function find_for_instance(IDataObject $inst) { 00026 $dao = self::create_instance_adapter($inst); 00027 return $dao->find_all(); 00028 } 00029 00030 /** 00031 * Calucate average for instance 00032 * 00033 * @param IDataObject $inst 00034 * @return int 00035 */ 00036 public static function get_average_for_instance(IDataObject $inst, $precision = 0) { 00037 $aggr = VotesAggregates::get_for_instance($inst); 00038 if ($aggr) { 00039 return $aggr->get_average($precision); 00040 } 00041 return 0; 00042 } 00043 00044 /** 00045 * Create a vote instance 00046 * 00047 * @param array $params 00048 * @param IDataObject $instance 00049 * @param DAOVotes $created 00050 * @return Status 00051 */ 00052 public static function create($params, $instance, &$created) { 00053 $params['instance'] = $instance; 00054 $cmd = CommandsFactory::create_command('votes', 'create', $params); 00055 $ret = $cmd->execute(); 00056 $created = $cmd->get_result(); 00057 return $ret; 00058 } 00059 }