commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / CRM / Core / Smarty / plugins / function.isValueChange.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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>
35 * @copyright CiviCRM LLC (c) 2004-2015
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 * Smarty param: string $key unique identifier for this property (REQUIRED)
44 * Smarty param: mixed $value the current value of the property
45 * Smarty param: string $assign name of template variable to which to assign result
46 *
47 *
48 * @param array $params
49 * Template call's parameters.
50 * @param CRM_Core_Smarty $smarty
51 * The Smarty object.
52 *
53 * @return NULL
54 */
55 function smarty_function_isValueChange($params, &$smarty) {
56 static $values = array();
57
58 if (empty($params['key'])) {
59 $smarty->trigger_error("Missing required parameter, 'key', in isValueChange plugin.");
60 return NULL;
61 }
62
63 $is_changed = FALSE;
64
65 if (!array_key_exists($params['key'], $values) || strcasecmp($params['value'], $values[$params['key']]) !== 0) {
66 // if we have a new value
67
68 $is_changed = TRUE;
69
70 $values[$params['key']] = $params['value'];
71
72 // clear values on all properties added below/after this property
73 $clear = FALSE;
74 foreach ($values as $k => $dontcare) {
75 if ($clear) {
76 unset($values[$k]);
77 }
78 elseif ($params['key'] == $k) {
79 $clear = TRUE;
80 }
81 }
82 }
83
84 if ($params['assign']) {
85 $smarty->assign($params['assign'], $is_changed);
86 }
87
88 return NULL;
89 }