Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
NotificationMashableInboxRules.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  const HTML_CONTENT_IFRAME_CLASS = 'notification-message-html-content-iframe';
40 
41  const HTML_CONTENT_IFRAME_DIV_CLASS = 'notification-message-html-content-div';
42 
43  const HTML_CONTENT_WRAPPER_DIV_CLASS = 'notification-message-html-content';
44 
45  const HTML_CONTENT_DIV_TOGGLE_BUTTON_CLASS = 'notification-message-html-content-toggle';
46 
47  public function getUnreadCountForCurrentUser()
48  {
49  $searchAttributeData = $this->getMetadataFilteredByFilteredBy(MashableInboxForm::FILTERED_BY_UNREAD);
50  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('Notification');
51  $where = RedBeanModelDataProvider::makeWhere('Notification', $searchAttributeData, $joinTablesAdapter);
52  return Notification::getCount($joinTablesAdapter, $where, null, true);
53  }
54 
55  public function getModelClassName()
56  {
57  return 'Notification';
58  }
59 
60  public function getListViewClassName()
61  {
62  return 'NotificationsForUserListView';
63  }
64 
65  public function getZeroModelViewClassName()
66  {
67  return null;
68  }
69 
70  public function getMachableInboxOrderByAttributeName()
71  {
72  return 'createdDateTime';
73  }
74 
75  public function getActionViewOptions()
76  {
77  return array();
78  }
79 
80  public function getMetadataFilteredByOption($option)
81  {
82  return self::getSearchAttributeData();
83  }
84 
85  public function getMetadataFilteredByFilteredBy($filteredBy)
86  {
87  if ($filteredBy == MashableInboxForm::FILTERED_BY_UNREAD)
88  {
89  $searchAttributeData['clauses'] = array(
90  1 => array(
91  'attributeName' => 'ownerHasReadLatest',
92  'operatorType' => 'doesNotEqual',
93  'value' => (bool)1
94  ),
95  2 => array(
96  'attributeName' => 'ownerHasReadLatest',
97  'operatorType' => 'isNull',
98  'value' => null
99  ),
100  3 => array(
101  'attributeName' => 'owner',
102  'operatorType' => 'equals',
103  'value' => Yii::app()->user->userModel->id
104  ),
105  );
106  $searchAttributeData['structure'] = '(1 or 2) and 3';
107  }
108  else
109  {
110  $searchAttributeData = null;
111  }
112  return $searchAttributeData;
113  }
114 
115  public function getModelStringContent(RedBeanModel $model)
116  {
117  $content = strval($model);
118  if ($content != null)
119  {
120  $content = $content . ' ';
121  }
122  if ($model->notificationMessage->id > 0)
123  {
124  if ($model->notificationMessage->htmlContent != null)
125  {
126  $contentForSpan = $this->resolveHtmlContent($model->notificationMessage->id);
127  }
128  elseif ($model->notificationMessage->textContent != null)
129  {
130  $contentForSpan = ZurmoHtml::tag(
131  'span',
132  array("class" => "last-comment"),
133  Yii::app()->format->text($model->notificationMessage->textContent)
134  );
135  }
136  $content .= $contentForSpan;
137  }
138  return $content;
139  }
140 
141  public function getModelCreationTimeContent(RedBeanModel $model)
142  {
143  return DateTimeUtil::getTimeSinceDisplayContent($model->createdDateTime);
144  }
145 
146  public function getSearchAttributeData($searchTerm = null)
147  {
148  $searchAttributeData['clauses'] = array(
149  1 => array(
150  'attributeName' => 'owner',
151  'relatedAttributeName' => 'id',
152  'operatorType' => 'equals',
153  'value' => Yii::app()->user->userModel->id,
154  ),
155  );
156  $searchAttributeData['structure'] = '1';
157  if ($searchTerm !== null)
158  {
159  $searchAttributeData['clauses'][2] = array(
160  'attributeName' => 'notificationMessage',
161  'relatedAttributeName' => 'htmlContent',
162  'operatorType' => 'contains',
163  'value' => $searchTerm,
164  );
165  $searchAttributeData['clauses'][3] = array(
166  'attributeName' => 'notificationMessage',
167  'relatedAttributeName' => 'textContent',
168  'operatorType' => 'contains',
169  'value' => $searchTerm,
170  );
171  $searchAttributeData['structure'] .= ' and (2 or 3)';
172  }
173  return $searchAttributeData;
174  }
175 
176  public function resolveMarkRead($modelId)
177  {
178  assert('$modelId > 0');
179  $this->resolveChangeHasReadLatestStatus($modelId, true);
180  }
181 
182  public function resolveMarkUnread($modelId)
183  {
184  assert('$modelId > 0');
185  $this->resolveChangeHasReadLatestStatus($modelId, false);
186  }
187 
188  private function resolveChangeHasReadLatestStatus($modelId, $newStatus)
189  {
190  $modelClassName = $this->getModelClassName();
191  $model = $modelClassName::getById($modelId);
192  if (Yii::app()->user->userModel == $model->owner)
193  {
194  $model->ownerHasReadLatest = $newStatus;
195  }
196  $model->ownerHasReadLatest = $newStatus;
197  $model->save();
198  }
199 
200  public function getMassOptions()
201  {
202  return array(
203  'deleteSelected' => array('label' => Zurmo::t('NotificationsModule', 'Delete selected'), 'isActionForAll' => false),
204  'deleteAll' => array('label' => Zurmo::t('NotificationsModule', 'Delete all'), 'isActionForAll' => true),
205  );
206  }
207 
208  public function resolveDeleteSelected($modelId)
209  {
210  assert('$modelId > 0');
211  $notification = Notification::GetById(intval($modelId));
213  $notification->delete();
214  }
215 
216  public function resolveDeleteAll()
217  {
218  $searchAttributeData['clauses'] = array(
219  1 => array(
220  'attributeName' => 'owner',
221  'relatedAttributeName' => 'id',
222  'operatorType' => 'equals',
223  'value' => Yii::app()->user->userModel->id,
224  ),
225  );
226  $searchAttributeData['structure'] = '1';
227  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('Notification');
228  $where = RedBeanModelDataProvider::makeWhere('Notification', $searchAttributeData, $joinTablesAdapter);
229  $models = Notification::getSubset($joinTablesAdapter, null, null, $where, null);
230  foreach ($models as $model)
231  {
233  $model->delete();
234  }
235  }
236 
237  public function hasCurrentUserReadLatest($modelId)
238  {
239  $modelClassName = $this->getModelClassName();
240  $model = $modelClassName::getById($modelId);
241  return $model->ownerHasReadLatest;
242  }
243 
244  protected function resolveHtmlContent($id)
245  {
246  $buttonContent = $this->resolveHtmlContentDivToggleButton();
247  $iframeContent = ZurmoHtml::tag('iframe', $this->resolveHtmlContentIFrameHtmlOptions($id), '');
248  $iframeDivContent = ZurmoHtml::tag('div', $this->resolveHtmlContentDivHtmlOptions() , $iframeContent);
249  $content = $buttonContent . ZurmoHtml::tag('div', $this->resolveHtmlContentWrapperDivHtmlOptions(), $iframeDivContent);
250  return $content;
251  }
252 
253  protected function resolveHtmlContentWrapperDivHtmlOptions()
254  {
255  return array(
256  'class' => static::HTML_CONTENT_WRAPPER_DIV_CLASS,
257  );
258  }
259 
260  protected function resolveHtmlContentDivHtmlOptions()
261  {
262  return array(
263  'class' => static::HTML_CONTENT_IFRAME_DIV_CLASS,
264  'style' => 'display:none;',
265  );
266  }
267 
268  protected function resolveHtmlContentIFrameHtmlOptions($id)
269  {
270  return array('class' => static::HTML_CONTENT_IFRAME_CLASS,
271  'src' => 'about:blank',
272  'width' => '100%',
273  'height' => '100%',
274  'frameborder' => 0,
275  'data-src' => $this->resolveNotificationMessageHtmlContentUrl($id));
276  }
277 
278  protected function resolveNotificationMessageHtmlContentUrl($id)
279  {
280  return Yii::app()->createUrl('notifications/default/renderMessageHtmlContent', array('id' => $id));
281  }
282 
283  protected function resolveHtmlContentDivToggleButton()
284  {
285  $this->registerHtmlContentDivToggleScript();
286  $label = Zurmo::t('NotificationsModule', 'Toggle Content');
287  $link = ZurmoHtml::link($label, '#', $this->resolveHtmlContentDivToggleButtonHtmlOptions());
288  return $link;
289  }
290 
291  protected function resolveHtmlContentDivToggleButtonHtmlOptions()
292  {
293  return array('class' => 'z-link ' . static::HTML_CONTENT_DIV_TOGGLE_BUTTON_CLASS);
294  }
295 
296  protected function registerHtmlContentDivToggleScript()
297  {
298  $scriptName = 'toggleHtmlContentIframeDiv';
299  if (!Yii::app()->clientScript->isScriptRegistered($scriptName))
300  {
301  Yii::app()->clientScript->registerScript($scriptName, "
302  $('." . static::HTML_CONTENT_DIV_TOGGLE_BUTTON_CLASS . "').unbind('click').bind('click', function(event)
303  {
304  var self = $(this);
305  var htmlContentDiv = self.parent().find('.notification-message-html-content-div');
306  var iframe = htmlContentDiv.find('.notification-message-html-content-iframe');
307  var iframeSourceUrl = iframe.attr('src');
308  var iframeDataSourceUrl = iframe.data('src');
309  if (!htmlContentDiv.is(':visible') && iframeSourceUrl == 'about:blank')
310  {
311  iframe.attr('src', iframeDataSourceUrl);
312  }
313  htmlContentDiv.slideToggle(300);
314  event.preventDefault();
315  });
316  ");
317  }
318  }
319  }
320 ?>
static resolveAccessCanCurrentUserDeleteModel(RedBeanModel $model, $fromAjax=false)
static getTimeSinceDisplayContent($dateTime, $durationDisplayFormat=false)
static makeWhere($modelClassName, array $metadata, &$joinTablesAdapter)
static getSubset(RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter=null, $offset=null, $count=null, $where=null, $orderBy=null, $modelClassName=null, $selectDistinct=false)
static getCount(RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter=null, $where=null, $modelClassName=null, $selectDistinct=false)
save($runValidation=true, array $attributeNames=null)
Generated on Thu Jul 2 2020 07:10:35
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.