All Data Structures Functions Variables Pages
Project.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 
37  class Project extends OwnedSecurableItem implements StarredInterface
38  {
39  /*
40  * Constants for project status
41  */
42  const STATUS_ACTIVE = 1;
43 
44  const STATUS_ARCHIVED = 2;
45 
50  public static function getByName($name)
51  {
52  return self::getByNameOrEquivalent('name', $name);
53  }
54 
58  public function __toString()
59  {
60  try
61  {
62  if (trim($this->name) == '')
63  {
64  return Zurmo::t('Core', '(Unnamed)');
65  }
66  return $this->name;
67  }
69  {
70  return '';
71  }
72  }
73 
77  public static function getModuleClassName()
78  {
79  return 'ProjectsModule';
80  }
81 
85  public static function canSaveMetadata()
86  {
87  return true;
88  }
89 
94  public static function translatedAttributeLabels($language)
95  {
97  return array_merge(parent::translatedAttributeLabels($language),
98  array(
99  'status' => Zurmo::t('ZurmoModule', 'Status', array(), null, $language),
100  'tasks' => Zurmo::t('TasksModule', 'TasksModulePluralLabel', $params, null, $language),
101  'accounts' => Zurmo::t('AccountsModule', 'AccountsModulePluralLabel', $params, null, $language),
102  'contacts' => Zurmo::t('ContactsModule', 'ContactsModulePluralLabel', $params, null, $language),
103  'opportunities' => Zurmo::t('OpportunitiesModule', 'OpportunitiesModulePluralLabel', $params, null, $language)
104  )
105  );
106  }
107 
111  public static function getDefaultMetadata()
112  {
113  $metadata = parent::getDefaultMetadata();
114  $metadata[__CLASS__] = array(
115  'members' => array(
116  'name',
117  'description',
118  'status'
119  ),
120  'relations' => array(
121  'opportunities' => array(static::MANY_MANY, 'Opportunity'),
122  'contacts' => array(static::MANY_MANY, 'Contact'),
123  'accounts' => array(static::MANY_MANY, 'Account'),
124  'tasks' => array(static::HAS_MANY, 'Task'),
125  'auditEvents' => array(static::HAS_MANY, 'ProjectAuditEvent'),
126  ),
127  'rules' => array(
128  array('name', 'required'),
129  array('name', 'type', 'type' => 'string'),
130  array('name', 'length', 'min' => 3, 'max' => 64),
131  array('description', 'type', 'type' => 'string'),
132  array('status', 'type', 'type' => 'integer'),
133  array('status', 'default', 'value' => Project::STATUS_ACTIVE),
134  array('status', 'required'),
135  ),
136  'elements' => array(
137  'status' => 'ProjectStatusDropDown',
138  ),
139  'customFields' => array(
140  ),
141  'defaultSortAttribute' => 'name',
142  'noAudit' => array(
143  ),
144  'nonConfigurableAttributes' => array()
145  );
146  return $metadata;
147  }
148 
152  public static function isTypeDeletable()
153  {
154  return true;
155  }
156 
160  public static function hasReadPermissionsOptimization()
161  {
162  return true;
163  }
164 
168  public static function getGamificationRulesType()
169  {
170  return 'ProjectGamification';
171  }
172 
176  public static function getStatusDropDownArray()
177  {
178  return array(
179  self::STATUS_ACTIVE => Zurmo::t('Core', 'Active'),
180  self::STATUS_ARCHIVED => Zurmo::t('ZurmoModule', 'Archived'),
181  );
182  }
183 
188  protected function beforeDelete()
189  {
190  if (parent::beforeDelete())
191  {
192  foreach ($this->tasks as $task)
193  {
194  $task->delete();
195  }
196  foreach ($this->auditEvents as $auditEvent)
197  {
198  $auditEvent->delete();
199  }
200  return true;
201  }
202  return false;
203  }
204 
208  protected function afterSave()
209  {
210  if ($this->getIsNewModel())
211  {
212  ProjectAuditEvent::logAuditEvent(ProjectAuditEvent::PROJECT_CREATED, $this, $this->name);
213  ProjectsNotificationUtil::submitProjectNotificationMessage($this, ProjectAuditEvent::PROJECT_CREATED);
214  }
215  elseif ($this->status == Project::STATUS_ARCHIVED && isset($this->originalAttributeValues['status']))
216  {
217  ProjectAuditEvent::logAuditEvent(ProjectAuditEvent::PROJECT_ARCHIVED, $this, $this->name);
218  ProjectsNotificationUtil::submitProjectNotificationMessage($this, ProjectAuditEvent::PROJECT_ARCHIVED);
219  }
220  parent::afterSave();
221  }
222  }
223 ?>
static getTranslationParamsForAllModules()
Definition: LabelUtil.php:75
static translatedAttributeLabels($language)
Definition: Project.php:94
static getGamificationRulesType()
Definition: Project.php:168
static getModuleClassName()
Definition: Project.php:77
static canSaveMetadata()
Definition: Project.php:85
static hasReadPermissionsOptimization()
Definition: Project.php:160
static logAuditEvent($eventName, Project $project, $data=null, User $user=null)
static getStatusDropDownArray()
Definition: Project.php:176
beforeDelete()
Definition: Project.php:188
static getDefaultMetadata()
Definition: Project.php:111
static isTypeDeletable()
Definition: Project.php:152
static getByName($name)
Definition: Project.php:50
static submitProjectNotificationMessage(Project $project, $action, Task $task=null, User $relatedUser=null)
afterSave()
Definition: Project.php:208
__toString()
Definition: Project.php:58
Generated on Thu Apr 2 2020 07:10:44