3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * CiviCRM's Smarty report section totals plugin
15 * Prints the correct report section total based on the given key and order in the section hierarchy
18 * @author Allen Shaw <allen@nswebsolutions.com>
19 * @copyright CiviCRM LLC https://civicrm.org/licensing
24 * Smarty block function for printing the correct report section total
26 * Smarty param: string $key value of the current section column
27 * Smarty param: int $depth the depth of the current section
28 * (sections declared first have lesser depth, starting at 0)
30 * @param array $params
31 * Template call's parameters.
32 * @param CRM_Core_Smarty $smarty
36 * the string, translated by gettext
38 function smarty_function_sectionTotal($params, &$smarty) {
39 /* section totals are stored in template variable 'sectionTotals',
40 * which is a two-dimensional array keyed to a string which is a delimited
41 * concatenation (using CRM_Core_DAO::VALUE_SEPARATOR) of ordered permutations
42 * of section header values, e.g.,
44 * 'foo[VALUE_SEAPARATOR]bar' => 5,
45 * 'foo[VALUE_SEAPARATOR]bar2' => 5
46 * Note: This array is created and assigned to the template in CRM_Report_Form::sectionTotals()
49 static $sectionValues = [];
51 // move back in the stack, if necessary
52 if (count($sectionValues) > $params['depth']) {
53 $sectionValues = array_slice($sectionValues, 0, $params['depth']);
56 // append the current value
57 $sectionValues[] = $params['key'];
59 // concatenate with pipes to build the right key
60 $totalsKey = implode(CRM_Core_DAO
::VALUE_SEPARATOR
, $sectionValues);
62 // return the corresponding total
63 return $smarty->_tpl_vars
['sectionTotals'][$totalsKey];