* @copyright CiviCRM LLC (c) 2004-2013 * $Id$ */ /** * Smarty block function for printintg the correct report section total * * * Smarty param: string $key value of the current section column * Smarty param: int $depth the depth of the current section * (sections declared first have lesser depth, starting at 0) * * @param array $params template call's parameters * @param object $smarty the Smarty object * * @return string the string, translated by gettext */ function smarty_function_sectionTotal($params, &$smarty) { /* section totals are stored in template variable 'sectionTotals', * which is a two-dimensional array keyed to a string which is a delimited * concatenation (using CRM_Core_DAO::VALUE_SEPARATOR) of ordered permutations * of section header values, e.g., * 'foo' => 10, * 'foo[VALUE_SEAPARATOR]bar' => 5, * 'foo[VALUE_SEAPARATOR]bar2' => 5 * Note: This array is created and assigned to the template in CRM_Report_Form::sectionTotals() */ static $sectionValues = array(); // move back in the stack, if necessary if (count($sectionValues) > $params['depth']) { $sectionValues = array_slice($sectionValues, 0, $params['depth']); } // append the current value $sectionValues[] = $params['key']; // concatenate with pipes to build the right key $totalsKey = implode(CRM_Core_DAO::VALUE_SEPARATOR, $sectionValues); // return the corresponding total return $smarty->_tpl_vars['sectionTotals'][$totalsKey]; }