I am trying to get the field totals for all results after filtering with the CakeDC search plugin.
In my model I have:
public function getFieldAmountTotal( $fieldNames){
// Can't use recursive -1 because it includes current filtering
// This will only grab the total by id
// Can't not pull id because filtering on related tables
//$totalAmounts = $this->find( 'all', array('fields' => $fieldNames));
$totalAmounts = $this->find( 'all', array('fields' => $fieldNames, 'group' => 'MovieStar.id'));
$grandTotal = array();
foreach($fieldNames as $fieldName){
$grandTotal[$fieldName] = 0;
}
foreach($totalAmounts as $amount){
foreach($fieldNames as $fieldName){
$grandTotal[$fieldName] += $amount['MovieStar'][$fieldName];
}
}
debug('$grandTotal');
debug($grandTotal);
return $grandTotal;
}
This worked great when I was using the CakePHP filter plugin because all filtering was stored in the session and was automatically passed in.
How would I filter in the find using the current filter plugin form settings?