2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Affero General Public License version 3 as published by the
8 * Free Software Foundation with the addition of the following permission added
9 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
18 * You should have received a copy of the GNU Affero General Public License along with
19 * this program; if not, see http://www.gnu.org/licenses or write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26 * The interactive user interfaces in modified source and object code versions
27 * of this program must display Appropriate Legal Notices, as required under
28 * Section 5 of the GNU Affero General Public License version 3.
30 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31 * these Appropriate Legal Notices must retain the display of the "Powered by
32 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33 * technical reasons, the Appropriate Legal Notices must display the words
34 * "Powered by SugarCRM".
35 ********************************************************************************/
40 * @see Zend_Gdata_Entry
42 require_once 'Zend/Gdata/Entry.php';
45 * @see Zend_Gdata_Contacts_Extension_Name
47 require_once 'Zend/Gdata/Contacts/Extension/Name.php';
50 * @see Zend_Gdata_Contacts_Extension_Birthday
52 require_once 'Zend/Gdata/Contacts/Extension/Birthday.php';
55 * @see Zend_Gdata_Contacts_Extension_PhoneNumber
57 require_once 'Zend/Gdata/Contacts/Extension/PhoneNumber.php';
60 * @see Zend_Gdata_Contacts_Extension_Email
62 require_once 'Zend/Gdata/Contacts/Extension/Email.php';
65 * @see Zend_Gdata_Contacts_Extension_Address
67 require_once 'Zend/Gdata/Contacts/Extension/Address.php';
70 * @see Zend_Gdata_Contacts_Extension_Address
72 require_once 'Zend/Gdata/Contacts/Extension/Organization.php';
75 * @see Zend_Extension_Where
77 require_once 'Zend/Gdata/Extension/Where.php';
80 * Represents a Contact entry in the Contact data API meta feed
83 class Zend_Gdata_Contacts_ListEntry extends Zend_Gdata_Entry
86 protected $_names = null;
87 protected $_birthday = null;
88 protected $_phones = array();
89 protected $_emails = array();
90 protected $_addresses = array();
91 protected $_organization = null;
94 public function __construct($element = null)
96 $this->registerAllNamespaces(Zend_Gdata_Contacts::$namespaces);
97 parent::__construct($element);
100 public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
102 $element = parent::getDOM($doc, $majorVersion, $minorVersion);
106 protected function takeChildFromDOM($child)
108 $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
109 switch ($absoluteNodeName) {
111 case $this->lookupNamespace('gd') . ':' . 'name';
112 $item = new Zend_Gdata_Contacts_Extension_Name();
113 $item->transferFromDOM($child);
114 $this->_names = $item;
117 case $this->lookupNamespace('gContact') . ':' . 'birthday';
118 $item = new Zend_Gdata_Contacts_Extension_Birthday();
119 $item->transferFromDOM($child);
120 $this->_birthday = $item;
123 case $this->lookupNamespace('gd') . ':' . 'phoneNumber';
124 $item = new Zend_Gdata_Contacts_Extension_PhoneNumber();
125 $item->transferFromDOM($child);
126 $this->_phones[] = $item;
129 case $this->lookupNamespace('gd') . ':' . 'email';
130 $item = new Zend_Gdata_Contacts_Extension_Email();
131 $item->transferFromDOM($child);
132 $this->_emails[] = $item;
135 case $this->lookupNamespace('gd') . ':' . 'structuredPostalAddress';
136 $item = new Zend_Gdata_Contacts_Extension_Address();
137 $item->transferFromDOM($child);
138 $this->_addresses[] = $item;
141 case $this->lookupNamespace('gd') . ':' . 'organization';
142 $item = new Zend_Gdata_Contacts_Extension_Organization();
143 $item->transferFromDOM($child);
144 $this->_organization = $item;
148 parent::takeChildFromDOM($child);
153 public function toArray()
155 $entry = array( 'first_name' => '', 'last_name' => '', 'full_name' => '', 'id' => '', 'birthday' => '','email1' => '','email2' => '',
156 'title' => '', 'account_name' => '', 'notes' => '', 'phone_main' => '','phone_mobile' => '',
157 'alt_address_street' => '','alt_address_postcode' => '','alt_address_city' => '','alt_address_state' => '','alt_address_country' => '',
158 'primary_address_street' => '','primary_address_postcode' => '','primary_address_city' => '','primary_address_state' => '','primary_address_country' => '',
159 'team_name' => '', 'assigned_user_name' => ''
162 if($this->_names != null)
163 $entry = array_merge($entry, $this->_names->toArray() );
165 //Get the self link so we can query for the contact details at a later date
166 foreach($this->_link as $linkEntry)
168 $linkRel = $linkEntry->getRel();
169 if( $linkRel != null && $linkRel == "self" )
176 foreach($this->_addresses as $address)
178 $entry = array_merge($entry, $address->toArray() );
181 foreach($this->_phones as $phoneEntry)
183 $key = "phone_" . $phoneEntry->getPhoneType();
184 $entry[$key] = $phoneEntry->getNumber();
188 $entry = array_merge($entry, $this->getEmailAddresses() );
191 if($this->_content != null)
192 $entry['notes'] = $this->getContent()->getText();
195 $entry['id'] = $this->getId()->getText();
198 if($this->_birthday != null)
199 $entry['birthday'] = $this->_birthday->getBirthday();
201 //Organization name and title
202 if($this->_organization != null)
204 $entry['account_name'] = $this->_organization->getOrganizationName();
205 $entry['title'] = $this->_organization->getOrganizationTitle();
211 protected function getEmailAddresses()
214 $primaryEmail = $this->getPrimaryEmail();
215 if($primaryEmail !== FALSE)
216 $results['email1'] = $primaryEmail;
219 $nonPrimaryEmail = $this->getNextNonPrimaryEmail();
220 if($nonPrimaryEmail !== FALSE)
221 $results['email1'] = $nonPrimaryEmail;
226 $secondaryEmail = $this->getNextNonPrimaryEmail();
227 if($secondaryEmail !== FALSE)
228 $results['email2'] = $secondaryEmail;
233 protected function getPrimaryEmail()
236 foreach($this->_emails as $emailEntry)
238 if( $emailEntry->isPrimary() )
239 return $emailEntry->getEmail();
244 protected function getNextNonPrimaryEmail()
247 foreach($this->_emails as $k => $emailEntry)
249 if( !$emailEntry->isPrimary() )
251 $results = $emailEntry->getEmail();
252 unset($this->_emails[$k]);