Pages::getGroups($field)
Version 4.1
Get pages in groups
Version 4.1
Get pages in groups
Get pages in groups by given field.
Return list of pages in Group -object, which extends Pages.
Object Pages
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()}";
}
}
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>";
}
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>";
}
}
}
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";
}
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). |