3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
35 class CRM_Contact_BAO_Contact_Optimizer
{
40 public static function edit(&$newValues, &$oldValues) {
41 // still need to do more work on this
45 self
::website($newValues, $oldValues);
52 public static function website(&$newValues, &$oldValues) {
53 $oldWebsiteValues = CRM_Utils_Array
::value('website', $oldValues);
54 $newWebsiteValues = CRM_Utils_Array
::value('website', $newValues);
56 if ($oldWebsiteValues == NULL ||
$newWebsiteValues == NULL) {
60 // check if we had a value in the old
61 $oldEmpty = $newEmpty = TRUE;
62 $old = $new = array();
64 foreach ($oldWebsiteValues as $idx => $value) {
65 if (!empty($value['url'])) {
67 $old[] = array('website_type_id' => $value['website_type_id'], 'url' => $value['url']);
71 foreach ($newWebsiteValues as $idx => $value) {
72 if (!empty($value['url'])) {
74 $new[] = array('website_type_id' => $value['website_type_id'], 'url' => $value['url']);
78 // if both old and new are empty, we can delete new and avoid a write
79 if ($oldEmpty && $newEmpty) {
80 unset($newValues['website']);
83 // if different number of non-empty entries, return
84 if (count($new) != count($old)) {
88 // same number of entries, check if they are exactly the same
89 foreach ($old as $oldID => $oldValues) {
91 foreach ($new as $newID => $newValues) {
93 $old['website_type_id'] == $new['website_type_id'] &&
94 $old['url'] == $new['url']
106 // if we've come here, this means old and new are the same
107 // we can skip saving new and return
108 unset($newValues['website']);
115 public static function email(&$newValues, &$oldValues) {
116 $oldEmailValues = CRM_Utils_Array
::value('email', $oldValues);
117 $newEmailValues = CRM_Utils_Array
::value('email', $newValues);
119 if ($oldEmailValues == NULL ||
$newEmailValues == NULL) {
123 // check if we had a value in the old
124 $oldEmpty = $newEmpty = TRUE;
125 $old = $new = array();
127 foreach ($oldEmailValues as $idx => $value) {
128 if (!empty($value['email'])) {
131 'email' => $value['email'],
132 'location_type_id' => $value['location_type_id'],
133 'on_hold' => $value['on_hold'] ?
1 : 0,
134 'is_primary' => $value['is_primary'] ?
1 : 0,
135 'is_bulkmail' => $value['is_bulkmail'] ?
1 : 0,
136 'signature_text' => $value['signature_text'] ?
$value['signature_text'] : '',
137 'signature_html' => $value['signature_html'] ?
$value['signature_html'] : '',
142 foreach ($newEmailValues as $idx => $value) {
143 if (!empty($value['email'])) {
146 'email' => $value['email'],
147 'location_type_id' => $value['location_type_id'],
148 'on_hold' => $value['on_hold'] ?
1 : 0,
149 'is_primary' => $value['is_primary'] ?
1 : 0,
150 'is_bulkmail' => $value['is_bulkmail'] ?
1 : 0,
151 'signature_text' => $value['signature_text'] ?
$value['signature_text'] : '',
152 'signature_html' => $value['signature_html'] ?
$value['signature_html'] : '',
157 // if both old and new are empty, we can delete new and avoid a write
158 if ($oldEmpty && $newEmpty) {
159 unset($newValues['email']);
162 // if different number of non-empty entries, return
163 if (count($new) != count($old)) {
167 // same number of entries, check if they are exactly the same
168 foreach ($old as $oldID => $oldValues) {
170 foreach ($new as $newID => $newValues) {
172 $old['email_type_id'] == $new['email_type_id'] &&
173 $old['url'] == $new['url']
185 // if we've come here, this means old and new are the same
186 // we can skip saving new and return
187 unset($newValues['email']);