Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * CiviCRM's Smarty report section totals plugin | |
14 | * | |
16b10e64 | 15 | * Prints the correct report section total based on the given key and order in the section hierarchy |
6a488035 TO |
16 | * |
17 | * @package CRM | |
18 | * @author Allen Shaw <allen@nswebsolutions.com> | |
ca5cec67 | 19 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
20 | */ |
21 | ||
22 | /** | |
16b10e64 | 23 | * Smarty block function for printing the correct report section total |
6a488035 | 24 | * |
6a488035 TO |
25 | * Smarty param: string $key value of the current section column |
26 | * Smarty param: int $depth the depth of the current section | |
27 | * (sections declared first have lesser depth, starting at 0) | |
28 | * | |
6a0b768e TO |
29 | * @param array $params |
30 | * Template call's parameters. | |
16b10e64 | 31 | * @param CRM_Core_Smarty $smarty |
6a0b768e | 32 | * The Smarty object. |
6a488035 | 33 | * |
a6c01b45 | 34 | * @return string |
353ffa53 | 35 | * the string, translated by gettext |
6a488035 TO |
36 | */ |
37 | function smarty_function_sectionTotal($params, &$smarty) { | |
38 | /* section totals are stored in template variable 'sectionTotals', | |
16b10e64 CW |
39 | * which is a two-dimensional array keyed to a string which is a delimited |
40 | * concatenation (using CRM_Core_DAO::VALUE_SEPARATOR) of ordered permutations | |
41 | * of section header values, e.g., | |
42 | * 'foo' => 10, | |
43 | * 'foo[VALUE_SEAPARATOR]bar' => 5, | |
44 | * 'foo[VALUE_SEAPARATOR]bar2' => 5 | |
45 | * Note: This array is created and assigned to the template in CRM_Report_Form::sectionTotals() | |
46 | */ | |
6a488035 | 47 | |
be2fb01f | 48 | static $sectionValues = []; |
6a488035 TO |
49 | |
50 | // move back in the stack, if necessary | |
51 | if (count($sectionValues) > $params['depth']) { | |
52 | $sectionValues = array_slice($sectionValues, 0, $params['depth']); | |
53 | } | |
54 | ||
55 | // append the current value | |
56 | $sectionValues[] = $params['key']; | |
57 | ||
58 | // concatenate with pipes to build the right key | |
59 | $totalsKey = implode(CRM_Core_DAO::VALUE_SEPARATOR, $sectionValues); | |
60 | ||
6a488035 TO |
61 | // return the corresponding total |
62 | return $smarty->_tpl_vars['sectionTotals'][$totalsKey]; | |
63 | } |