Pages::getAvg($field[,$weight,$addEmpty])

Version 3.8

Get the average value

Calcualte given formula for all pages and return the average value.

Return value

Float

Arguments

$field
1. Name of the field
2. Formula to calculate value as in Pages::calculate()
$weight
Field which value is used to count weighted average.
$addEmpty
bool If empty values should be taken into count or not
Default: True

Example

Orders average Total Amount:

$this->get('pages','order')->addWhere('status','Ordered')->getAvg('total_amount');

Full documentation

Using formula

Average of calculated value:

$this->get('pages','order')->addWhere('status','Ordered')->getAvg('price*amount');

Weighted average:

Use credits to count weighted average

$this->get('pages','exams')->addWhere('student',$studentId)->getAvg('grade','credits');