.

VotesAggregates Class Reference

Facade class for vote aggregates. More...

List of all members.

Static Public Member Functions

static  aggregate_for_instance (IDataObject $instance)
  Aggregates average et al for given instance.
static  create_type_adapter ($instance_type)
  Create adapter to find all votes for a given instance type.
static  get_for_instance (IDataObject $inst)
  Get votes aggregates for instance.
static  get_top_voted_of_type ($type, $limit)
  Returns n top voted aggregsates of given type.

Detailed Description

Facade class for vote aggregates.

Definition at line 5 of file votesaggregates.facade.php.


Member Function Documentation

static VotesAggregates::aggregate_for_instance ( IDataObject instance  )  [static]

Aggregates average et al for given instance.

Returns array with following properties:

  • average: Average vote
  • numtotal: Total number of votes
  • instance: The instance given
Parameters:
IDataObject  $instance
Returns:
array

Definition at line 27 of file votesaggregates.facade.php.

00027                                                                              {
00028                 $dao = Votes::create_instance_adapter($instance);
00029                 /* 
00030                  * @var $query DBQuerySelect
00031                  * @var $dao DAOVotes 
00032                  */
00033                 $query = $dao->create_select_query();
00034                 $query->set_fields(array(
00035                         'SUM(value * weight)' => 'value',
00036                         'SUM(weight)' => 'count'
00037                 ));
00038                 $result = DB::query($query->get_sql());
00039                 
00040                 $data = $result->fetch();
00041                 $value = $data['value'];
00042                 $count = $data['count'];
00043                 $avg = ($count > 0) ? $value / $count : 0;
00044 
00045                 $ret = array(
00046                         'instance' => $instance,
00047                         'average' => $avg, 
00048                         'numtotal' => $count
00049                 );
00050                 return $ret;
00051         }
static VotesAggregates::create_type_adapter ( instance_type  )  [static]

Create adapter to find all votes for a given instance type.

Parameters:
string  $instance_type
Returns:
DAOVotesaggregates

Definition at line 59 of file votesaggregates.facade.php.

00059                                                                    {
00060                 $dao = new DAOVotesaggregates();
00061                 $dao->add_where('instance', DBWhere::OP_LIKE, "$instance_type%");
00062                 return $dao;
00063         }
static VotesAggregates::get_for_instance ( IDataObject inst  )  [static]

Get votes aggregates for instance.

Parameters:
IDataObject  $inst
Returns:
DAOVotesaggregates

Definition at line 12 of file votesaggregates.facade.php.

00012                                                                    {
00013                 return DB::get_item('votesaggregates', 'instance', InstanceReferenceSerializier::instance_to_string($inst));
00014         }
static VotesAggregates::get_top_voted_of_type ( type,
limit  
) [static]

Returns n top voted aggregsates of given type.

Parameters:
string  $type
integer  $limit
Returns:
array

Definition at line 72 of file votesaggregates.facade.php.

00072                                                                     {
00073                 $dao = self::create_type_adapter($type);
00074                 /* @var $dao DAOVotesaggregates */
00075                 $dao->sort('average', DAOVotesaggregates::DESC);
00076                 $dao->limit(0, $limit);
00077                 return $dao->find_array();
00078         }

The documentation for this class was generated from the following file: