Pages::getGroups($field)

Version 4.1

Get pages in groups

Get pages in groups by given field.

Return list of pages in Group -object, which extends Pages.

Return value

Object Pages

Arguments

$field
Field name to group pages by

Example

List hours by employee:

foreach ( $Hours->getGroups('employee') as $Group ){
    $txt .= "Employee: {$Group->getTitle()}, ID: {$Group->getValue()}";
    foreach ( $Group as $Hour ){
       $txt .= "Hour: {$Hour->getTitle()}";
    }
}

Full documentation

List by order date

List all ordered orders by order date:

$Orders = $this->get('pages','order')
    ->addWhere('status','Ordered')
    ->setOrder('order_date');

foreach ( $Orders->getGroups('order_date') as $Group ){
   $txt .= "<h2>{$Group->getTitle()}</h2>";
   $li = "";
   foreach ( $Group as $Order ){
       $li .= "<li>{$Order->getTitle()}</li>";
   }
   $txt .= "<ul>{$li}</ul>";
}

Multidimensional group

You can call getGroups() to the group:

foreach ( $Workhours->getGroups('employee') as $employeeHours ){

    $txt .= "<h2>Employee: {$employeeHours->getTitle()}</h3>";
    foreach ( $employeeHours->getGroups('work_date') as $dayHours ){

        $txt .= "<h3>Day {$dayHours->getTitle()}</h3>";
        foreach ( $dayHours as $Hour ){
            $txt .= "<p>Hour: {$Hour->duration}</p>";
        }
    }
}

Use Pages functions

Group is a Pages object, so you can use all it's functions on Group. List orders by date: How many orders and total amount:

foreach ( $Orders->getGroups('order_date') as $Group ){
   $txt .= "{$Group->order_date}: {$Group->count()} orders, {$Group->calculate('total')} eur";
}

Group method list

Method return description
getTitle() string Visible text of the groupfield value.
getValue() mixed Group field value.
getField() Field Group field (the first page in group).