All Data Structures Functions Variables Pages
SocialItem.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 getByDescription($description)
40  {
41  assert('is_string($description) && $description != ""');
42  return self::getSubset(null, null, null, "description = '$description'");
43  }
44 
45  public function onCreated()
46  {
47  parent::onCreated();
48  $this->unrestrictedSet('latestDateTime', DateTimeUtil::convertTimestampToDbFormatDateTime(time()));
49  }
50 
51  public function __toString()
52  {
53  if (trim($this->description) == '')
54  {
55  return Zurmo::t('Core', '(Unnamed)');
56  }
57  return $this->description;
58  }
59 
64  protected static function getModifiedSignalAttribute()
65  {
66  return 'description';
67  }
68 
69  public static function getModuleClassName()
70  {
71  return 'SocialItemsModule';
72  }
73 
74  public static function canSaveMetadata()
75  {
76  return false;
77  }
78 
79  public static function getDefaultMetadata()
80  {
81  $metadata = parent::getDefaultMetadata();
82  $metadata[__CLASS__] = array(
83  'members' => array(
84  'description',
85  'latestDateTime',
86  ),
87  'relations' => array(
88  'comments' => array(static::HAS_MANY, 'Comment', static::OWNED,
89  static::LINK_TYPE_POLYMORPHIC, 'relatedModel'),
90  'note' => array(static::HAS_ONE, 'Note'),
91  'files' => array(static::HAS_MANY, 'FileModel', static::OWNED,
92  static::LINK_TYPE_POLYMORPHIC, 'relatedModel'),
93  'toUser' => array(static::HAS_ONE, 'User', static::NOT_OWNED,
94  static::LINK_TYPE_SPECIFIC, 'toUser'),
95  ),
96  'rules' => array(
97  array('description', 'type', 'type' => 'string'),
98  array('description', 'required', 'on' => 'createPost'),
99  array('latestDateTime', 'required'),
100  array('latestDateTime', 'readOnly'),
101  array('latestDateTime', 'type', 'type' => 'datetime'),
102  ),
103  'elements' => array(
104  'description' => 'TextArea',
105  'files' => 'Files',
106  'latestDateTime' => 'DateTime'
107  ),
108  );
109  return $metadata;
110  }
111 
112  public static function isTypeDeletable()
113  {
114  return true;
115  }
116 
117  public static function getGamificationRulesType()
118  {
119  return 'SocialItemGamification';
120  }
121 
127  protected function beforeSave()
128  {
129  if (parent::beforeSave())
130  {
131  if ($this->comments->isModified() || $this->getIsNewModel())
132  {
133  $this->unrestrictedSet('latestDateTime', DateTimeUtil::convertTimestampToDbFormatDateTime(time()));
134  }
135  return true;
136  }
137  else
138  {
139  return false;
140  }
141  }
142 
143  public static function hasReadPermissionsOptimization()
144  {
145  return true;
146  }
147 
148  public function canUserDelete(User $user)
149  {
150  assert('$user->id > 0');
151  if ($this->toUser->isSame($user) || $this->owner->isSame($user) ||
152  Group::getByName(Group::SUPER_ADMINISTRATORS_GROUP_NAME)->contains($user))
153  {
154  return true;
155  }
156  return false;
157  }
158 
159  protected static function translatedAttributeLabels($language)
160  {
161  return array_merge(parent::translatedAttributeLabels($language),
162  array(
163  'comments' => Zurmo::t('CommentsModule', 'Comments', array(), null, $language),
164  'description' => Zurmo::t('ZurmoModule', 'Description', array(), null, $language),
165  'files' => Zurmo::t('ZurmoModule', 'Files', array(), null, $language),
166  'latestDateTime' => Zurmo::t('ZurmoModule', 'Latest Date Time', array(), null, $language),
167  'note' => Zurmo::t('NotesModule', 'Note', array(), null, $language),
168  'toUser' => Zurmo::t('SocialItemsModule', 'To User', array(), null, $language),
169  )
170  );
171  }
172  }
173 ?>
Definition: User.php:37
static getByName($name)
Definition: Group.php:57
unrestrictedSet($attributeName, $value)
static getModifiedSignalAttribute()
Definition: SocialItem.php:64
Generated on Thu Apr 9 2020 07:10:44