Pages::getMax($field)

Version 3.8

Get the greatest value

Return value

Float

Arguments

$field
1. Name of the field
2. Formula to calculate value as in Pages::calculate()

Example

Get largest total amount from open invoices:

$max = $this->get('pages','invoice')->addWhere('status','Open')->getMax('total_amount');

Full documentation

This method is shorthand for:

$value = 0;
foreach ( $this->get('pages','Invoice')->hae('status=Open') as $Invoice ){
    if ( $Invoice->total_amount->isOver($value) ){
        $value = $Invoice->total_amount;
    }
}

Using formula

Get Open Invoice that had the largest amount before discount:

$max = $this->get('pages','Invoice')
  ->addWhere('status','Open')
  ->getMax('total_amount*(100+discount_percent)/100');

Fieldtype: Date

DateField: The newest invoice date of open invoices:

$max = $this->get('pages','Invoice')
   ->addWhere('status','Open')
   ->getMax('invoice_date');

Fieldtype: Selection

SelectionField: The latest status of customers Invoices:

$max = $this->get('pages','invoice')
   ->addWhere('customer', $customerId)
   ->getMax('status');