Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
LeadsUtil.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 
42  class LeadsUtil
43  {
44  const LEAD_CONVERSION_ACCOUNT_DATA_SESSION_KEY = 'leadConversionAccountPostData';
45 
54  public static function attributesToAccount(Contact $contact, Account $account)
55  {
56  assert('!empty($contact->id)');
57  $metadata = LeadsModule::getMetadata();
58  $map = $metadata['global']['convertToAccountAttributesMapping'];
59  foreach ($map as $contactAttributeName => $accountAttributeName)
60  {
61  $account->$accountAttributeName = $contact->$contactAttributeName;
62  }
63  return $account;
64  }
65 
82  public static function attributesToAccountWithNoPostData(Contact $contact, Account $account, array $postData)
83  {
84  assert('is_array($postData)');
85  assert('!empty($contact->id)');
86  $metadata = LeadsModule::getMetadata();
87  $map = $metadata['global']['convertToAccountAttributesMapping'];
88  foreach ($map as $contactAttributeName => $accountAttributeName)
89  {
90  if (!isset($postData[$accountAttributeName]))
91  {
92  $account->$accountAttributeName = $contact->$contactAttributeName;
93  }
94  }
95  return $account;
96  }
97 
98  public static function storeIntoSession($key, $value)
99  {
100  Yii::app()->session->add($key, $value);
101  }
102 
103  public static function getFromSession($key)
104  {
105  return Yii::app()->session->get($key);
106  }
107 
108  public static function removeFromSession($key)
109  {
110  Yii::app()->session->remove($key);
111  }
112 
113  public static function createAccountForLeadConversionFromAccountPostData($accountPostData, $contact, $controllerUtil)
114  {
115  if (isset($accountPostData['AccountSkip']) && $accountPostData['AccountSkip'] == true)
116  {
117  return null;
118  }
119  elseif (isset($accountPostData['SelectAccount']) && $accountPostData['SelectAccount'] == true)
120  {
121  $account = Account::getById(intval($accountPostData['accountId']));
122  return $account;
123  }
124  elseif (isset($accountPostData['CreateAccount']) && $accountPostData['CreateAccount'] == true)
125  {
126  unset($accountPostData['CreateAccount']);
127  $account = new Account();
128  $account = LeadsUtil::attributesToAccountWithNoPostData($contact, $account, $accountPostData);
129  $account = Yii::app()->custom->resolveLeadToAccountCustomAttributesWithNoPostData($contact,
130  $account, $accountPostData);
131  $savedSuccessfully = false;
132  $modelToStringValue = null;
133  $account = $controllerUtil->saveModelFromPost($accountPostData, $account, $savedSuccessfully,
134  $modelToStringValue, false);
135  if (!$account->getErrors())
136  {
137  $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($contact);
138  ExplicitReadWriteModelPermissionsUtil::resolveExplicitReadWriteModelPermissions($account, $explicitReadWriteModelPermissions);
139  if (!$account->save())
140  {
141  throw new NotSupportedException();
142  }
143  return $account;
144  }
145  }
146  }
147 
152  public static function getStartingState()
153  {
154  $states = ContactState::getAll('order');
155  if (count($states) == 0)
156  {
158  }
159  return $states[0];
160  }
161 
168  {
169  $leadStatesData = array();
170  $states = ContactState::getAll('order');
171  $startingState = ContactsUtil::getStartingStateId();
172  foreach ($states as $state)
173  {
174  if ($startingState == $state->id)
175  {
176  break;
177  }
178  $leadStatesData[$state->id] = $state->name;
179  }
180  return $leadStatesData;
181  }
182 
190  {
191  assert('is_string($language)');
192  $leadStatesData = array();
193  $states = ContactState::getAll('order');
194  $startingState = ContactsUtil::getStartingStateId();
195  foreach ($states as $state)
196  {
197  if ($startingState == $state->id)
198  {
199  break;
200  }
201  $leadStatesData[$state->id] = ContactsUtil::resolveStateLabelByLanguage($state, $language);
202  }
203  return $leadStatesData;
204  }
205 
212  public static function getLeadStateDataFromStartingStateLabelByLanguage($language)
213  {
214  assert('is_string($language)');
215  $leadStatesData = array();
216  $states = ContactState::getAll('order');
217  $startingState = ContactsUtil::getStartingStateId();
218  foreach ($states as $state)
219  {
220  if ($startingState == $state->id)
221  {
222  break;
223  }
224  $state->name = ContactsUtil::resolveStateLabelByLanguage($state, $language);
225  $leadStatesData[] = $state;
226  }
227  return $leadStatesData;
228  }
229 
234  public static function isStateALead(ContactState $state)
235  {
236  $leadStatesData = self::getLeadStateDataFromStartingStateOnAndKeyedById();
237  if ($state->id > 0 && isset($leadStatesData[$state->id]))
238  {
239  return true;
240  }
241  else
242  {
243  return false;
244  }
245  }
246 
251  public static function isStateALeadByStateName($stateName)
252  {
253  assert('is_string($stateName)');
254  $leadStatesData = self::getLeadStateDataFromStartingStateOnAndKeyedById();
255  foreach ($leadStatesData as $leadStateName)
256  {
257  if ($stateName == $leadStateName)
258  {
259  return true;
260  }
261  }
262  return false;
263  }
264  }
265 ?>
static makeBySecurableItem(SecurableItem $securableItem)
static resolveStateLabelByLanguage(ContactState $state, $language)
static getMetadata(User $user=null)
Definition: Module.php:502
static resolveExplicitReadWriteModelPermissions(SecurableItem $securableItem, ExplicitReadWriteModelPermissions $explicitReadWriteModelPermissions, $validate=false)
static getStartingStateId()
static getLeadStateDataFromStartingStateKeyedByIdAndLabelByLanguage($language)
Definition: LeadsUtil.php:189
static isStateALead(ContactState $state)
Definition: LeadsUtil.php:234
static attributesToAccountWithNoPostData(Contact $contact, Account $account, array $postData)
Definition: LeadsUtil.php:82
static getLeadStateDataFromStartingStateOnAndKeyedById()
Definition: LeadsUtil.php:167
static getById($id, $modelClassName=null)
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null)
static getLeadStateDataFromStartingStateLabelByLanguage($language)
Definition: LeadsUtil.php:212
static attributesToAccount(Contact $contact, Account $account)
Definition: LeadsUtil.php:54
static getStartingState()
Definition: LeadsUtil.php:152
static isStateALeadByStateName($stateName)
Definition: LeadsUtil.php:251
Generated on Wed Jul 8 2020 07:10:35
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.