Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
Conversation.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 
41  {
42  public static function getMashableActivityRulesType()
43  {
44  return 'Conversation';
45  }
46 
47  public static function getMashableInboxRulesType()
48  {
49  return 'Conversation';
50  }
51 
52  public static function getBySubject($subject)
53  {
54  assert('is_string($subject) && $subject != ""');
55  return self::getSubset(null, null, null, "subject = '$subject'");
56  }
57 
58  protected static function translatedAttributeLabels($language)
59  {
60  return array_merge(parent::translatedAttributeLabels($language),
61  array(
62  'description' => Zurmo::t('ZurmoModule', 'Description', array(), null, $language),
63  'latestDateTime' => Zurmo::t('ZurmoModule', 'Latest Date Time', array(), null, $language),
64  'subject' => Zurmo::t('Core', 'Subject', array(), null, $language),
65  'ownerHasReadLatest' => Zurmo::t('NotificationsModule', 'Owner Has Read Latest', array(), null, $language),
66  'isClosed' => Zurmo::t('ConversationsModule', 'Is Closed', array(), null, $language),
67  'comments' => Zurmo::t('CommentsModule', 'Comments', array(), null, $language),
68  'conversationItems' => Zurmo::t('ConversationsModule', 'Conversation Items', array(), null, $language),
69  'conversationParticipants' => Zurmo::t('ConversationsModule', 'Conversation Participants', array(), null, $language),
70  'files' => Zurmo::t('ZurmoModule', 'Files', array(), null, $language),
71  )
72  );
73  }
74 
75  public function __toString()
76  {
77  try
78  {
79  if (trim($this->subject) == '')
80  {
81  return Zurmo::t('Core', '(Unnamed)');
82  }
83  return $this->subject;
84  }
86  {
87  return '';
88  }
89  }
90 
95  protected static function getModifiedSignalAttribute()
96  {
97  return 'subject';
98  }
99 
100  public function resolveIsClosedForNull()
101  {
102  if ($this->isClosed == true)
103  {
104  return 1;
105  }
106  else
107  {
108  return 0;
109  }
110  }
111 
116  public static function getUnreadCountByUser(User $user)
117  {
118  $searchAttributeData = array();
119  $searchAttributeData['clauses'] = array(
120  1 => array(
121  'attributeName' => 'ownerHasReadLatest',
122  'operatorType' => 'doesNotEqual',
123  'value' => (bool)1
124  ),
125  2 => array(
126  'attributeName' => 'owner',
127  'operatorType' => 'equals',
128  'value' => $user->id
129  ),
130  3 => array(
131  'attributeName' => 'conversationParticipants',
132  'relatedAttributeName' => 'person',
133  'operatorType' => 'equals',
134  'value' => $user->getClassId('Item'),
135  ),
136  4 => array(
137  'attributeName' => 'conversationParticipants',
138  'relatedAttributeName' => 'hasReadLatest',
139  'operatorType' => 'doesNotEqual',
140  'value' => (bool)1
141  ),
142  );
143  $searchAttributeData['structure'] = '((1 and 2) or (3 and 4))';
144  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('Conversation');
145  $where = RedBeanModelDataProvider::makeWhere('Conversation', $searchAttributeData, $joinTablesAdapter);
146  return self::getCount($joinTablesAdapter, $where, null, true);
147  }
148 
149  public function onCreated()
150  {
151  parent::onCreated();
152  $this->unrestrictedSet('latestDateTime', DateTimeUtil::convertTimestampToDbFormatDateTime(time()));
153  }
154 
155  public static function getModuleClassName()
156  {
157  return 'ConversationsModule';
158  }
159 
160  public static function canSaveMetadata()
161  {
162  return true;
163  }
164 
165  public static function getDefaultMetadata()
166  {
167  $metadata = parent::getDefaultMetadata();
168  $metadata[__CLASS__] = array(
169  'members' => array(
170  'description',
171  'latestDateTime',
172  'subject',
173  'ownerHasReadLatest',
174  'isClosed'
175  ),
176  'relations' => array(
177  'comments' => array(static::HAS_MANY, 'Comment', static::OWNED,
178  static::LINK_TYPE_POLYMORPHIC, 'relatedModel'),
179  'conversationItems' => array(static::MANY_MANY, 'Item'),
180  'conversationParticipants' => array(static::HAS_MANY, 'ConversationParticipant',
181  static::OWNED),
182  'files' => array(static::HAS_MANY, 'FileModel', static::OWNED,
183  static::LINK_TYPE_POLYMORPHIC, 'relatedModel'),
184  ),
185  'rules' => array(
186  array('description', 'type', 'type' => 'string'),
187  array('latestDateTime', 'required'),
188  array('latestDateTime', 'readOnly'),
189  array('latestDateTime', 'type', 'type' => 'datetime'),
190  array('subject', 'required'),
191  array('subject', 'type', 'type' => 'string'),
192  array('subject', 'length', 'min' => 1, 'max' => 255),
193  array('ownerHasReadLatest', 'boolean'),
194  array('isClosed', 'boolean'),
195  ),
196  'elements' => array(
197  'conversationItems' => 'ConversationItem',
198  'description' => 'TextArea',
199  'files' => 'Files',
200  'latestDateTime' => 'DateTime',
201  ),
202  'defaultSortAttribute' => 'subject',
203  'noAudit' => array(
204  'description',
205  'latestDateTime',
206  'subject',
207  'ownerHasReadLatest',
208  ),
209  'conversationItemsModelClassNames' => array(
210  'Account',
211  'Opportunity',
212  ),
213  );
214  return $metadata;
215  }
216 
217  public static function isTypeDeletable()
218  {
219  return true;
220  }
221 
222  public static function hasReadPermissionsOptimization()
223  {
224  return true;
225  }
226 
227  public static function getGamificationRulesType()
228  {
229  return 'ConversationGamification';
230  }
231 
237  protected function beforeSave()
238  {
239  if (parent::beforeSave())
240  {
241  if ($this->comments->isModified() || $this->getIsNewModel())
242  {
243  $this->unrestrictedSet('latestDateTime', DateTimeUtil::convertTimestampToDbFormatDateTime(time()));
244  if ($this->getIsNewModel())
245  {
246  $this->ownerHasReadLatest = true;
247  }
248  }
249  if ($this->comments->isModified())
250  {
251  foreach ($this->comments as $comment)
252  {
253  if ($comment->id < 0)
254  {
255  if (Yii::app()->user->userModel != $this->owner)
256  {
257  $this->ownerHasReadLatest = false;
258  }
259  foreach ($this->conversationParticipants as $position => $participant)
260  {
261  //At this point the createdByUser is not populated yet in the comment, so we can
262  //use the current user.
263  if ($participant->person->getClassId('Item') != Yii::app()->user->userModel->getClassId('Item'))
264  {
265  $this->conversationParticipants[$position]->hasReadLatest = false;
266  }
267  }
268  }
269  }
270  }
271  return true;
272  }
273  else
274  {
275  return false;
276  }
277  }
278 
279  public static function hasRelatedItems()
280  {
281  return true;
282  }
283  }
284 ?>
Definition: User.php:37
getClassId($modelClassName)
static makeWhere($modelClassName, array $metadata, &$joinTablesAdapter)
static getModifiedSignalAttribute()
unrestrictedSet($attributeName, $value)
static getUnreadCountByUser(User $user)
Generated on Mon Jul 13 2020 07:10:32
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.