Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
Opportunity.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 
38  {
39  public static function getByName($name)
40  {
41  return self::getByNameOrEquivalent('name', $name);
42  }
43 
48  public static function getStageClosedWonValue()
49  {
50  return 'Closed Won';
51  }
52 
53  public function onCreated()
54  {
55  parent::onCreated();
56  $this->unrestrictedSet('stageModifiedDateTime',
57  DateTimeUtil::convertTimestampToDbFormatDateTime(time()));
58  }
59 
60  public function onModified()
61  {
62  parent::onModified();
63  if (array_key_exists('value', $this->stage->originalAttributeValues) &&
64  $this->stage->originalAttributeValues['value'] != "" &&
65  $this->getScenario() != 'importModel')
66  {
67  $this->unrestrictedSet('stageModifiedDateTime',
68  DateTimeUtil::convertTimestampToDbFormatDateTime(time()));
69  }
70  Yii::app()->custom->resolveOpportunityCustomActionsOnModified($this);
71  }
72 
73  protected function beforeSave()
74  {
75  if (parent::beforeSave())
76  {
77  $automaticMappingDisabled = OpportunitiesModule::isAutomaticProbabilityMappingDisabled();
78  if (!isset($this->originalAttributeValues['probability']) && $automaticMappingDisabled === false)
79  {
80  $this->resolveStageToProbability();
81  }
83  Yii::app()->custom->resolveOpportunityCustomActionsBeforeSave($this);
84  return true;
85  }
86  else
87  {
88  return false;
89  }
90  }
91 
92  protected function afterSave()
93  {
94  Yii::app()->custom->resolveOpportunityCustomActionsAfterSave($this);
95  parent::afterSave();
96  }
97 
98  protected function beforeDelete()
99  {
100  if (parent::beforeDelete())
101  {
102  Yii::app()->custom->resolveOpportunityCustomActionsBeforeDelete($this);
103  return true;
104  }
105  return false;
106  }
107 
108  public function __toString()
109  {
110  try
111  {
112  if (trim($this->name) == '')
113  {
114  return Zurmo::t('Core', '(Unnamed)');
115  }
116  return $this->name;
117  }
119  {
120  return '';
121  }
122  }
123 
124  public static function getModuleClassName()
125  {
126  return 'OpportunitiesModule';
127  }
128 
129  public static function translatedAttributeLabels($language)
130  {
132  return array_merge(parent::translatedAttributeLabels($language), array(
133  'account' => Zurmo::t('AccountsModule', 'AccountsModuleSingularLabel', $params, null, $language),
134  'amount' => Zurmo::t('OpportunitiesModule', 'Amount', array(), null, $language),
135  'closeDate' => Zurmo::t('OpportunitiesModule', 'Close Date', array(), null, $language),
136  'contacts' => Zurmo::t('ContactsModule', 'ContactsModulePluralLabel', $params, null, $language),
137  'description' => Zurmo::t('ZurmoModule', 'Description', array(), null, $language),
138  'meetings' => Zurmo::t('MeetingsModule', 'MeetingsModulePluralLabel', $params, null, $language),
139  'name' => Zurmo::t('Core', 'Name', array(), null, $language),
140  'notes' => Zurmo::t('NotesModule', 'NotesModulePluralLabel', $params, null, $language),
141  'probability' => Zurmo::t('OpportunitiesModule', 'Probability', array(), null, $language),
142  'source' => Zurmo::t('ContactsModule', 'Source', array(), null, $language),
143  'stage' => Zurmo::t('ZurmoModule', 'Stage', array(), null, $language),
144  'tasks' => Zurmo::t('TasksModule', 'TasksModulePluralLabel', $params, null, $language),
145  'stageModifiedDateTime'
146  => Zurmo::t('OpportunitiesModule', 'Stage Modified Date Time', array(), null, $language)));
147  }
148 
149  public static function canSaveMetadata()
150  {
151  return true;
152  }
153 
154  public static function getDefaultMetadata()
155  {
156  $metadata = parent::getDefaultMetadata();
157  $metadata[__CLASS__] = array(
158  'members' => array(
159  'closeDate',
160  'description',
161  'name',
162  'probability',
163  'stageModifiedDateTime',
164  ),
165  'relations' => array(
166  'account' => array(static::HAS_ONE, 'Account'),
167  'amount' => array(static::HAS_ONE, 'CurrencyValue', static::OWNED,
168  static::LINK_TYPE_SPECIFIC, 'amount'),
169  'products' => array(static::HAS_MANY, 'Product'),
170  'contacts' => array(static::MANY_MANY, 'Contact'),
171  'stage' => array(static::HAS_ONE, 'OwnedCustomField', static::OWNED,
172  static::LINK_TYPE_SPECIFIC, 'stage'),
173  'source' => array(static::HAS_ONE, 'OwnedCustomField', static::OWNED,
174  static::LINK_TYPE_SPECIFIC, 'source'),
175  'projects' => array(static::MANY_MANY, 'Project'),
176  'notificationSubscribers' => array(static::HAS_MANY, 'NotificationSubscriber', static::OWNED,
177  static::LINK_TYPE_POLYMORPHIC, 'relatedModel'),
178  'comments' => array(static::HAS_MANY, 'Comment', static::OWNED,
179  static::LINK_TYPE_POLYMORPHIC, 'relatedModel'),
180  ),
181  'derivedRelationsViaCastedUpModel' => array(
182  'meetings' => array(static::MANY_MANY, 'Meeting', 'activityItems'),
183  'notes' => array(static::MANY_MANY, 'Note', 'activityItems'),
184  'tasks' => array(static::MANY_MANY, 'Task', 'activityItems'),
185  ),
186  'rules' => array(
187  array('amount', 'required'),
188  array('closeDate', 'required'),
189  array('closeDate', 'type', 'type' => 'date'),
190  array('description', 'type', 'type' => 'string'),
191  array('name', 'required'),
192  array('name', 'type', 'type' => 'string'),
193  array('name', 'length', 'min' => 1, 'max' => 64),
194  array('probability', 'type', 'type' => 'integer'),
195  array('probability', 'numerical', 'min' => 0, 'max' => 100),
196  array('probability', 'required'),
197  array('probability', 'default', 'value' => 0),
198  array('probability', 'probability'),
199  array('stage', 'required'),
200  array('stageModifiedDateTime', 'required'),
201  array('stageModifiedDateTime', 'readOnly'),
202  array('stageModifiedDateTime', 'type', 'type' => 'datetime'),
203  ),
204  'elements' => array(
205  'amount' => 'CurrencyValue',
206  'account' => 'Account',
207  'closeDate' => 'Date',
208  'description' => 'TextArea',
209  'stageModifiedDateTime' => 'DateTime',
210  ),
211  'customFields' => array(
212  'stage' => 'SalesStages',
213  'source' => 'LeadSources',
214  ),
215  'defaultSortAttribute' => 'name',
216  'rollupRelations' => array(
217  'contacts',
218  ),
219  'noAudit' => array(
220  'description'
221  ),
222  );
223  return $metadata;
224  }
225 
226  public static function isTypeDeletable()
227  {
228  return true;
229  }
230 
231  public static function isCacheable()
232  {
233  return Yii::app()->custom->resolveOpportunityIsCacheable();
234  }
235 
236  public static function getRollUpRulesType()
237  {
238  return 'Opportunity';
239  }
240 
241  public static function hasReadPermissionsOptimization()
242  {
243  return true;
244  }
245 
246  public static function getGamificationRulesType()
247  {
248  return 'OpportunityGamification';
249  }
250 
251  private function resolveStageToProbability()
252  {
253  if ($this->stage === null)
254  {
255  throw new NotSupportedException();
256  }
257  else
258  {
259  $this->probability = OpportunitiesModule::getProbabilityByStageValue($this->stage->value);
260  }
261  }
262 
268  public function isAllowedToSetReadOnlyAttribute($attributeName)
269  {
270  if ($this->getScenario() == 'importModel' || $this->getScenario() == 'searchModel')
271  {
272  if ($attributeName == 'stageModifiedDateTime')
273  {
274  return true;
275  }
276  else
277  {
278  return parent::isAllowedToSetReadOnlyAttribute($attributeName);
279  }
280  }
281  }
282 
286  protected function resolveAndSetDefaultSubscribers()
287  {
288  NotificationSubscriberUtil::addSubscriber($this->owner, $this, false);
289  }
290  }
291 ?>
static addSubscriber(User $user, OwnedSecurableItem $model, $hasReadLatest=false)
static getTranslationParamsForAllModules()
Definition: LabelUtil.php:75
resolveAndSetDefaultSubscribers()
static getProbabilityByStageValue($value)
isAllowedToSetReadOnlyAttribute($attributeName)
unrestrictedSet($attributeName, $value)
static getStageClosedWonValue()
Definition: Opportunity.php:48
Generated on Sat Jul 11 2020 07:10:32
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.