Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * CiviCRM's Smarty looped value change plugin | |
30 | * | |
31 | * Checks for change in value of given key | |
32 | * | |
33 | * @package CRM | |
34 | * @author Allen Shaw <allen@nswebsolutions.com> | |
06b69b18 | 35 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
36 | * $Id$ |
37 | */ | |
38 | ||
39 | /** | |
40 | * Smarty function for checking change in a property's value, for example | |
41 | * when looping through an array. | |
42 | * | |
43 | * | |
44 | * Smarty param: string $key unique identifier for this property (REQUIRED) | |
45 | * Smarty param: mixed $value the current value of the property | |
46 | * Smarty param: string $assign name of template variable to which to assign result | |
47 | * | |
48 | * | |
49 | * @param array $params template call's parameters | |
50 | * @param object $smarty the Smarty object | |
51 | * | |
52 | * @return NULL | |
53 | */ | |
54 | function smarty_function_isValueChange($params, &$smarty) { | |
55 | static $values = array(); | |
56 | ||
57 | if (empty($params['key'])) { | |
58 | $smarty->trigger_error("Missing required parameter, 'key', in isValueChange plugin."); | |
59 | return; | |
60 | } | |
61 | ||
62 | $is_changed = FALSE; | |
63 | ||
64 | if (!array_key_exists($params['key'], $values) || $params['value'] != $values[$params['key']]) { | |
65 | // if we have a new value | |
66 | ||
67 | $is_changed = TRUE; | |
68 | ||
69 | $values[$params['key']] = $params['value']; | |
70 | ||
71 | // clear values on all properties added below/after this property | |
72 | $clear = FALSE; | |
73 | foreach ($values as $k => $dontcare) { | |
74 | if ($clear) { | |
75 | unset($values[$k]); | |
76 | } | |
77 | elseif ($params['key'] == $k) { | |
78 | $clear = TRUE; | |
79 | } | |
80 | } | |
81 | } | |
82 | ||
83 | if ($params['assign']) { | |
84 | $smarty->assign($params['assign'], $is_changed); | |
85 | } | |
86 | ||
87 | return; | |
88 | } | |
89 |