Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
Notification.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 
40  class Notification extends Item implements MashableInboxInterface
41  {
42  public static function getMashableInboxRulesType()
43  {
44  return 'Notification';
45  }
46 
47  public function __toString()
48  {
49  if ($this->type == null)
50  {
51  return null;
52  }
53  $notificationRulesClassName = $this->type . 'NotificationRules';
54  if (@class_exists($notificationRulesClassName))
55  {
57  return $rule->getDisplayName();
58  }
59  else
60  {
61  return Zurmo::t('Core', '(Unnamed)');
62  }
63  }
64 
72  public static function getCountByTypeAndUser($type, User $user)
73  {
74  $models = self::getByTypeAndUser($type, $user);
75  return count($models);
76  }
77 
83  public static function getByTypeAndUser($type, User $user)
84  {
85  assert('is_string($type) && $type != ""');
86  assert('$user->id > 0');
87  $searchAttributeData = array();
88  $searchAttributeData['clauses'] = array(
89  1 => array(
90  'attributeName' => 'type',
91  'operatorType' => 'equals',
92  'value' => $type,
93  ),
94  2 => array(
95  'attributeName' => 'owner',
96  'relatedAttributeName' => 'id',
97  'operatorType' => 'equals',
98  'value' => $user->id,
99  ),
100  );
101  $searchAttributeData['structure'] = '1 and 2';
102  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('Notification');
103  $where = RedBeanModelDataProvider::makeWhere('Notification', $searchAttributeData, $joinTablesAdapter);
104  $models = self::getSubset($joinTablesAdapter, null, null, $where, null);
105  return $models;
106  }
107 
113  public static function getByNotificationMessageId($notificationMessageId)
114  {
115  assert('is_int($notificationMessageId)');
116  $searchAttributeData = array();
117  $searchAttributeData['clauses'] = array(
118  1 => array(
119  'attributeName' => 'notificationMessage',
120  'relatedAttributeName' => 'id',
121  'operatorType' => 'equals',
122  'value' => $notificationMessageId,
123  ),
124  );
125  $searchAttributeData['structure'] = '1';
126  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('Notification');
127  $where = RedBeanModelDataProvider::makeWhere('Notification', $searchAttributeData, $joinTablesAdapter);
128  $models = self::getSubset($joinTablesAdapter, null, null, $where, null);
129  return $models;
130  }
131 
137  public static function deleteByTypeAndUser($type, User $user)
138  {
139  $notifications = static::getByTypeAndUser($type, $user);
140  if (!empty($notifications))
141  {
142  foreach ($notifications as $notification)
143  {
144  static::deleteNotificationAndRelatedNotificationMessage($notification);
145  }
146  }
147  }
148 
154  public static function deleteNotificationAndRelatedNotificationMessage(Notification $notification)
155  {
156  try
157  {
158  if (isset($notification->notificationMessage) && $notification->notificationMessage instanceOf NotificationMessage)
159  {
160  $notificationMessageNotifications = Notification::getByNotificationMessageId($notification->notificationMessage->id);
161  if (count($notificationMessageNotifications) == 1)
162  {
163  $notification->notificationMessage->delete();
164  }
165  }
166  }
167  catch (NotFoundException $e)
168  {
169  }
170  $notification->delete();
171  }
172 
173  public static function getCountByUser(User $user)
174  {
175  assert('$user->id > 0');
176  $searchAttributeData = array();
177  $searchAttributeData['clauses'] = array(
178  1 => array(
179  'attributeName' => 'owner',
180  'relatedAttributeName' => 'id',
181  'operatorType' => 'equals',
182  'value' => $user->id,
183  ),
184  );
185  $searchAttributeData['structure'] = '1';
186  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('Notification');
187  $where = RedBeanModelDataProvider::makeWhere('Notification', $searchAttributeData, $joinTablesAdapter);
188  return self::getCount($joinTablesAdapter, $where, null, true);
189  }
190 
191  public static function getDefaultMetadata()
192  {
193  $metadata = parent::getDefaultMetadata();
194  $metadata[__CLASS__] = array(
195  'members' => array(
196  'type',
197  'ownerHasReadLatest',
198  ),
199  'relations' => array(
200  'notificationMessage' => array(static::HAS_ONE, 'NotificationMessage', static::NOT_OWNED),
201  'owner' => array(static::HAS_ONE, 'User', static::NOT_OWNED,
202  static::LINK_TYPE_SPECIFIC, 'owner'),
203  ),
204  'rules' => array(
205  array('owner', 'required'),
206  array('type', 'required'),
207  array('type', 'type', 'type' => 'string'),
208  array('type', 'length', 'min' => 1, 'max' => 64),
209  array('ownerHasReadLatest', 'boolean'),
210  ),
211  'elements' => array(
212  'owner' => 'User',
213  ),
214  'defaultSortAttribute' => null,
215  'noAudit' => array(
216  'owner',
217  'type',
218  'ownerHasReadLatest',
219  )
220  );
221  return $metadata;
222  }
223 
224  public static function isTypeDeletable()
225  {
226  return true;
227  }
228 
229  public static function getModuleClassName()
230  {
231  return 'NotificationsModule';
232  }
233 
234  protected static function translatedAttributeLabels($language)
235  {
236  return array_merge(parent::translatedAttributeLabels($language),
237  array(
238  'ownerHasReadLatest' => Zurmo::t('NotificationsModule', 'Owner Has Read Latest', array(), null, $language),
239  'notificationMessage' => Zurmo::t('Core', 'Notification Message', array(), null, $language),
240  'owner' => Zurmo::t('ZurmoModule', 'Owner', array(), null, $language),
241  'type' => Zurmo::t('Core', 'Type', array(), null, $language),
242  )
243  );
244  }
245  }
246 ?>
Definition: User.php:37
static makeWhere($modelClassName, array $metadata, &$joinTablesAdapter)
static getCountByTypeAndUser($type, User $user)
static getByNotificationMessageId($notificationMessageId)
static deleteNotificationAndRelatedNotificationMessage(Notification $notification)
Definition: Item.php:37
static deleteByTypeAndUser($type, User $user)
static getByTypeAndUser($type, User $user)
Generated on Wed Oct 21 2020 07:10:31
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.