3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
35 class CRM_Contact_BAO_Contact_Optimizer
{
36 static function edit( &$newValues, &$oldValues ) {
37 // still need to do more work on this
41 self
::website( $newValues, $oldValues );
44 static function website( &$newValues, &$oldValues ) {
45 $oldWebsiteValues = CRM_Utils_Array
::value( 'website', $oldValues );
46 $newWebsiteValues = CRM_Utils_Array
::value( 'website', $newValues );
48 if ( $oldWebsiteValues == null ||
$newWebsiteValues == null ) {
52 // check if we had a value in the old
53 $oldEmpty = $newEmpty = true;
54 $old = $new = array( );
56 foreach ( $oldWebsiteValues as $idx => $value ) {
57 if ( ! empty( $value['url'] ) ) {
59 $old[] = array( 'website_type_id' => $value['website_type_id'], 'url' => $value['url'] );
63 foreach ( $newWebsiteValues as $idx => $value ) {
64 if ( ! empty( $value['url'] ) ) {
66 $new[] = array( 'website_type_id' => $value['website_type_id'], 'url' => $value['url'] );
70 // if both old and new are empty, we can delete new and avoid a write
71 if ( $oldEmpty && $newEmpty ) {
72 unset( $newValues['website'] );
75 // if different number of non-empty entries, return
76 if ( count( $new ) != count( $old ) ) {
80 // same number of entries, check if they are exactly the same
81 foreach ( $old as $oldID => $oldValues ) {
83 foreach ( $new as $newID => $newValues ) {
85 $old['website_type_id'] == $new['website_type_id'] &&
86 $old['url'] == $new['url']
89 unset( $new[$newID] );
98 // if we've come here, this means old and new are the same
99 // we can skip saving new and return
100 unset( $newValues['website'] );
103 static function email( &$newValues, &$oldValues ) {
104 $oldEmailValues = CRM_Utils_Array
::value( 'email', $oldValues );
105 $newEmailValues = CRM_Utils_Array
::value( 'email', $newValues );
107 if ( $oldEmailValues == null ||
$newEmailValues == null ) {
111 // check if we had a value in the old
112 $oldEmpty = $newEmpty = true;
113 $old = $new = array( );
115 foreach ( $oldEmailValues as $idx => $value ) {
116 if ( ! empty( $value['email'] ) ) {
119 'email' => $value['email'],
120 'location_type_id' => $value['location_type_id'],
121 'on_hold' => $value['on_hold'] ?
1 : 0,
122 'is_primary' => $value['is_primary'] ?
1 : 0,
123 'is_bulkmail' => $value['is_bulkmail'] ?
1 : 0,
124 'signature_text' => $value['signature_text'] ?
$value['signature_text'] : '',
125 'signature_html' => $value['signature_html'] ?
$value['signature_html'] : '',
130 foreach ( $newEmailValues as $idx => $value ) {
131 if ( ! empty( $value['email'] ) ) {
134 'email' => $value['email'],
135 'location_type_id' => $value['location_type_id'],
136 'on_hold' => $value['on_hold'] ?
1 : 0,
137 'is_primary' => $value['is_primary'] ?
1 : 0,
138 'is_bulkmail' => $value['is_bulkmail'] ?
1 : 0,
139 'signature_text' => $value['signature_text'] ?
$value['signature_text'] : '',
140 'signature_html' => $value['signature_html'] ?
$value['signature_html'] : '',
145 // if both old and new are empty, we can delete new and avoid a write
146 if ( $oldEmpty && $newEmpty ) {
147 unset( $newValues['email'] );
150 // if different number of non-empty entries, return
151 if ( count( $new ) != count( $old ) ) {
155 // same number of entries, check if they are exactly the same
156 foreach ( $old as $oldID => $oldValues ) {
158 foreach ( $new as $newID => $newValues ) {
160 $old['email_type_id'] == $new['email_type_id'] &&
161 $old['url'] == $new['url']
164 unset( $new[$newID] );
173 // if we've come here, this means old and new are the same
174 // we can skip saving new and return
175 unset( $newValues['email'] );