Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ContactsUtil.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo 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 ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo 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
16  * details.
17  *
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
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified 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.
29  *
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 Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
43  {
49  public static function getStartingStateOrder(array $states)
50  {
51  $metadata = ContactsModule::getMetadata();
52  $startingState = $metadata['global']['startingStateId'];
53  $startingStateOrder = 0;
54  foreach ($states as $state)
55  {
56  if ($state->id == $startingState)
57  {
58  $startingStateOrder = $state->order;
59  break;
60  }
61  }
62  return $startingStateOrder;
63  }
64 
68  public static function getStartingState()
69  {
70  $metadata = ContactsModule::getMetadata();
71  return ContactState::getById($metadata['global']['startingStateId']);
72  }
73 
77  public static function getStartingStateId()
78  {
79  $metadata = ContactsModule::getMetadata();
80  return $metadata['global']['startingStateId'];
81  }
82 
87  public static function getContactStateDataKeyedByOrder()
88  {
89  $contactStatesData = array();
90  $states = ContactState::getAll('order');
91  foreach ($states as $state)
92  {
93  $contactStatesData[$state->order] = $state->name;
94  }
95  return $contactStatesData;
96  }
97 
103  {
104  $contactStatesLabels = null;
105  $states = ContactState::getAll('order');
106  foreach ($states as $state)
107  {
108  if ($state->serializedLabels !== null)
109  {
110  $labelsByLanguage = unserialize($state->serializedLabels);
111  foreach ($labelsByLanguage as $language => $label)
112  {
113  $contactStatesLabels[$language][$state->order] = $label;
114  }
115  }
116  }
117  return $contactStatesLabels;
118  }
119 
124  public static function getContactStateDataKeyedById()
125  {
126  $contactStatesData = array();
127  $states = ContactState::getAll('order');
128  foreach ($states as $state)
129  {
130  $contactStatesData[$state->id] = $state->name;
131  }
132  return $contactStatesData;
133  }
134 
141  {
142  $contactStatesData = array();
143  $states = ContactState::getAll('order');
144  $startingState = self::getStartingStateId();
145  $includeState = false;
146  foreach ($states as $state)
147  {
148  if ($startingState == $state->id || $includeState)
149  {
150  if ($startingState == $state->id)
151  {
152  $includeState = true;
153  }
154  $contactStatesData[$state->id] = $state->name;
155  }
156  }
157  return $contactStatesData;
158  }
159 
167  {
168  assert('is_string($language)');
169  $contactStatesData = array();
170  $states = ContactState::getAll('order');
171  $startingState = self::getStartingStateId();
172  $includeState = false;
173  foreach ($states as $state)
174  {
175  if ($startingState == $state->id || $includeState)
176  {
177  if ($startingState == $state->id)
178  {
179  $includeState = true;
180  }
181  $contactStatesData[$state->id] = static::resolveStateLabelByLanguage($state, $language);
182  }
183  }
184  return $contactStatesData;
185  }
186 
194  {
195  assert('is_string($language)');
196  $contactStatesData = array();
197  $states = ContactState::getAll('order');
198  foreach ($states as $state)
199  {
200  $contactStatesData[$state->id] = static::resolveStateLabelByLanguage($state, $language);
201  }
202  return $contactStatesData;
203  }
204 
210  public static function getContactStateDataFromStartingStateLabelByLanguage($language)
211  {
212  assert('is_string($language)');
213  $contactStatesData = array();
214  $states = ContactState::getAll('order');
215  $startingState = self::getStartingStateId();
216  $includeState = false;
217 
218  foreach ($states as $state)
219  {
220  if ($startingState == $state->id || $includeState)
221  {
222  if ($startingState == $state->id)
223  {
224  $includeState = true;
225  }
226  $state->name = static::resolveStateLabelByLanguage($state, $language);
227  $contactStatesData[] = $state;
228  }
229  }
230  return $contactStatesData;
231  }
232 
236  public static function setStartingStateById($startingStateId)
237  {
238  assert('is_int($startingStateId)');
239  $metadata = ContactsModule::getMetadata();
240  $metadata['global']['startingStateId'] = $startingStateId;
241  ContactsModule::setMetadata($metadata);
242  }
243 
248  public static function setStartingStateByOrder($startingStateOrder)
249  {
250  $states = ContactState::getAll('order');
251  foreach ($states as $order => $state)
252  {
253  if ($startingStateOrder == $state->order)
254  {
255  self::setStartingStateById($state->id);
256  return;
257  }
258  }
259  throw new NotSupportedException();
260  }
261 
271  public static function resolveContactStateAdapterByModulesUserHasAccessTo( $moduleClassNameFirstStates,
272  $moduleClassNameLaterStates,
273  $user)
274  {
275  assert('is_string($moduleClassNameFirstStates)');
276  assert('is_string($moduleClassNameLaterStates)');
277  assert('$user instanceof User && $user->id > 0');
278  $canAccessFirstStatesModule = RightsUtil::canUserAccessModule($moduleClassNameFirstStates, $user);
279  $canAccessLaterStatesModule = RightsUtil::canUserAccessModule($moduleClassNameLaterStates, $user);
280  if ($canAccessFirstStatesModule && $canAccessLaterStatesModule)
281  {
282  return null;
283  }
284  elseif (!$canAccessFirstStatesModule && $canAccessLaterStatesModule)
285  {
286  $prefix = substr($moduleClassNameLaterStates, 0, strlen($moduleClassNameLaterStates) - strlen('Module'));
287  return $prefix . 'StateMetadataAdapter';
288  }
289  elseif ($canAccessFirstStatesModule && !$canAccessLaterStatesModule)
290  {
291  $prefix = substr($moduleClassNameFirstStates, 0, strlen($moduleClassNameFirstStates) - strlen('Module'));
292  return $prefix . 'StateMetadataAdapter';
293  }
294  else
295  {
296  return false;
297  }
298  }
299 
305  public static function resolveStateLabelByLanguage(ContactState $state, $language)
306  {
307  assert('$state->id > 0');
308  assert('is_string($language)');
309  return $state->resolveTranslatedNameByLanguage($language);
310  }
311 
316  public static function resolveAddressesFromRelatedAccount(Contact & $contact)
317  {
318  if ($contact->account->id > 0)
319  {
320  if ($contact->account->billingAddress->id > 0)
321  {
322  foreach ($contact->account->billingAddress->getAttributeNames() as $attribute)
323  {
324  $contact->primaryAddress->{$attribute} = $contact->account->billingAddress->{$attribute};
325  }
326  }
327  if ($contact->account->shippingAddress->id > 0)
328  {
329  foreach ($contact->account->billingAddress->getAttributeNames() as $attribute)
330  {
331  $contact->secondaryAddress->{$attribute} = $contact->account->shippingAddress->{$attribute};
332  }
333  }
334  }
335  }
336 
344  public static function renderHtmlContentLabelFromContactAndKeyword($contact, $keyword)
345  {
346  assert('$contact instanceof Contact && $contact->id > 0');
347  assert('$keyword == null || is_string($keyword)');
348 
349  if (substr($contact->secondaryEmail->emailAddress, 0, strlen($keyword)) === $keyword)
350  {
351  $emailAddressToUse = $contact->secondaryEmail->emailAddress;
352  }
353  else
354  {
355  $emailAddressToUse = $contact->primaryEmail->emailAddress;
356  }
357  if ($emailAddressToUse != null)
358  {
359  return strval($contact) . '&#160&#160<b>' . strval($emailAddressToUse) . '</b>';
360  }
361  else
362  {
363  return strval($contact);
364  }
365  }
366 
371  public static function resolveMarketingListMembersByContact($contact)
372  {
373  if ($contact->id != null && $contact->id > 0)
374  {
375  $marketingListMembers = MarketingListMember::getByContactId($contact->id);
376  foreach ($marketingListMembers as $marketingListMember)
377  {
378  $marketingListMember->delete();
379  }
380  }
381  }
382 
390  public static function resolveCompanyNameForRelatedAccountName(Contact $contact)
391  {
392  if (LeadsUtil::isStateALead($contact->state) ||
393  !isset($contact->account) || $contact->account->id <= 0)
394  {
395  return $contact->companyName;
396  }
397  elseif (isset($contact->account) && $contact->account->id > 0)
398  {
399  try
400  {
401  $companyName = $contact->account->name;
402  }
404  {
405  $companyName = $contact->companyName;
406  }
407  return $companyName;
408  }
409  else
410  {
411  return null;
412  }
413  }
414  }
415 ?>
static resolveStateLabelByLanguage(ContactState $state, $language)
static getContactStateDataFromStartingStateKeyedByIdAndLabelByLanguage($language)
static getAllContactStatesDataFromStartingStateKeyedByIdAndLabelByLanguage($language)
static getMetadata(User $user=null)
Definition: Module.php:502
static resolveMarketingListMembersByContact($contact)
static getStartingStateId()
static getContactStateDataFromStartingStateLabelByLanguage($language)
resolveTranslatedNameByLanguage($language)
static resolveCompanyNameForRelatedAccountName(Contact $contact)
static getStartingState()
static setStartingStateByOrder($startingStateOrder)
static isStateALead(ContactState $state)
Definition: LeadsUtil.php:234
static canUserAccessModule($moduleClassName, $user)
Definition: RightsUtil.php:103
static getContactStateDataKeyedByOrder()
static getContactStateDataFromStartingStateOnAndKeyedById()
static getById($id, $modelClassName=null)
static setMetadata(array $metadata, User $user=null)
Definition: Module.php:533
static resolveContactStateAdapterByModulesUserHasAccessTo($moduleClassNameFirstStates, $moduleClassNameLaterStates, $user)
static resolveAddressesFromRelatedAccount(Contact &$contact)
static getByContactId($contactId)
static getAttributeNames()
Definition: BeanModel.php:405
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null)
static renderHtmlContentLabelFromContactAndKeyword($contact, $keyword)
static getContactStateLabelsKeyedByLanguageAndOrder()
static setStartingStateById($startingStateId)
static getContactStateDataKeyedById()
static getStartingStateOrder(array $states)
Generated on Tue Jul 14 2020 07:10:30
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.