Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
MashableInboxRules.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  abstract class MashableInboxRules
41  {
46  public $shouldRenderCreateAction = false;
47 
53  abstract public function getUnreadCountForCurrentUser();
54 
61  abstract public function hasCurrentUserReadLatest($modelId);
62 
67  abstract public function getMetadataFilteredByFilteredBy($filteredBy);
68 
73  abstract public function getMetadataFilteredByOption($option);
74 
79  abstract public function getActionViewOptions();
80 
81  abstract public function getModelClassName();
82 
86  abstract public function getMachableInboxOrderByAttributeName();
87 
92  abstract public function resolveMarkRead($modelId);
93 
98  abstract public function resolveMarkUnread($modelId);
99 
104  public function getSearchAttributeData($searchTerm)
105  {
106  return null;
107  }
108 
113  public function getMetadataForMashableInbox()
114  {
115  return null;
116  }
117 
122  public function getListViewClassName()
123  {
124  $modelClassName = $this->getModelClassName();
125  $moduleClassName = $modelClassName::getModuleClassName();
126  return $moduleClassName::getPluralCamelCasedName() . 'ListView';
127  }
128 
133  public function getZeroModelViewClassName()
134  {
135  $modelClassName = $this->getModelClassName();
136  $moduleClassName = $modelClassName::getModuleClassName();
137  return $moduleClassName::getPluralCamelCasedName() . 'ZeroModelsYetView';
138  }
139 
140  public function getListView($option, $filteredBy = MashableInboxForm::FILTERED_BY_ALL, $searchTerm = null, $starred = false)
141  {
142  $modelClassName = $this->getModelClassName();
143  $orderBy = $this->getMachableInboxOrderByAttributeName();
144  $pageSize = Yii::app()->pagination->resolveActiveForCurrentUserByType(
145  'listPageSize', get_class(Yii::app()->controller->module));
146  $metadataByOptionAndFilter = MashableUtil::mergeMetadata(
147  $this->getMetadataFilteredByOption($option),
148  $this->getMetadataFilteredByFilteredBy($filteredBy));
149  $metadata = MashableUtil::mergeMetadata(
150  $metadataByOptionAndFilter,
151  $this->getSearchAttributeData($searchTerm));
152  $dataProviderClassName = 'RedBeanModelDataProvider';
153  if ($starred)
154  {
155  $dataProviderClassName = 'StarredModelDataProvider';
156  }
158  $metadata,
159  $modelClassName,
160  $dataProviderClassName,
161  $orderBy,
162  true,
163  $pageSize
164  );
165  $listViewClassName = $this->getListViewClassName();
166  $listView = new $listViewClassName(
167  Yii::app()->controller->id,
168  Yii::app()->controller->module->id,
169  $modelClassName,
170  $dataProvider,
171  array());
172  return $listView;
173  }
174 
180  public function getModelStringContent(RedBeanModel $model)
181  {
182  $modelDisplayString = strval($model);
183  $params = array('label' => $modelDisplayString, 'wrapLabel' => false);
184  $moduleClassName = $model->getModuleClassName();
185  $moduleId = $moduleClassName::getDirectoryName();
186  $element = new DetailsLinkActionElement('default', $moduleId, $model->id, $params);
187  $content = $element->render();
188  $lastCommentNumber = count($model->comments) - 1;
189  if ($lastCommentNumber > 0)
190  {
191  $content .= ZurmoHtml::tag(
192  'span',
193  array("class" => "last-comment"),
194  $model->comments[$lastCommentNumber]->description
195  );
196  }
197  return $content;
198  }
199 
207  {
208  return DateTimeUtil::getTimeSinceDisplayContent($model->latestDateTime);
209  }
210 
215  public function getSummaryContentTemplate()
216  {
217  return "<span>{modelStringContent}</span><span class=\"list-item-details\">{modelCreationTimeContent}</span>";
218  }
219 
228  public function getMassOptions()
229  {
230  return array();
231  }
232 
238  public function hasUserReadLatest($model, User $user)
239  {
240  $haveNotReadRelationName = $this->getHaveNotReadRelationName();
241  if ($model->$haveNotReadRelationName->count() > 0)
242  {
243  foreach ($model->$haveNotReadRelationName as $personWhoHaveNotReadLatest)
244  {
245  if ($personWhoHaveNotReadLatest->person->getClassId('Item') == $user->getClassId('Item'))
246  {
247  return false;
248  }
249  }
250  }
251  return true;
252  }
253 
258  public function markUserAsHavingUnreadLatestModel($model, User $user)
259  {
260  if ($this->hasUserReadLatest($model, $user))
261  {
263  $model,
264  $this->makePersonWhoHasNotReadLatest($user));
265  }
266  $model->save();
267  }
268 
273  public function markUserAsHavingReadLatestModel($model, User $user)
274  {
275  $haveNotReadRelationName = $this->getHaveNotReadRelationName();
276  foreach ($model->$haveNotReadRelationName as $existingPersonWhoHaveNotReadLatest)
277  {
278  if ($existingPersonWhoHaveNotReadLatest->person->getClassId('Item') == $user->getClassId('Item'))
279  {
281  $model,
282  $existingPersonWhoHaveNotReadLatest);
283  }
284  }
285  $model->save();
286  }
287 
292  public function makePersonWhoHasNotReadLatest($personOrUserModel)
293  {
294  assert('$personOrUserModel instanceof User || $personOrUserModel instanceof Person');
295  $personWhoHaveNotReadLatestModelName = $this->getPersonWhoHasNotReadLatestModelName();
296  $personWhoHaveNotReadLatest = new $personWhoHaveNotReadLatestModelName();
297  $personWhoHaveNotReadLatest->person = $personOrUserModel;
298  return $personWhoHaveNotReadLatest;
299  }
300 
306  protected function getHaveNotReadRelationName()
307  {
308  return 'personsWhoHaveNotReadLatest';
309  }
310 
317  {
318  return 'PersonWhoHaveNotReadLatest';
319  }
320 
326  protected function addPersonWhoHasNotReadLatestToModel($model, $personWhoHasNotReadLatest)
327  {
328  $relationName = $this->getHaveNotReadRelationName();
329  $model->$relationName->add($personWhoHasNotReadLatest);
330  }
331 
337  protected function removePersonWhoHasNotReadLatestToModel($model, $personWhoHasNotReadLatest)
338  {
339  $relationName = $this->getHaveNotReadRelationName();
340  $model->$relationName->remove($personWhoHasNotReadLatest);
341  }
342  }
343 ?>
hasUserReadLatest($model, User $user)
getModelCreationTimeContent(RedBeanModel $model)
Definition: User.php:37
makePersonWhoHasNotReadLatest($personOrUserModel)
getSearchAttributeData($searchTerm)
getClassId($modelClassName)
static mergeMetadata($firstMetadata, $secondMetadata, $isAnd=true)
static getTimeSinceDisplayContent($dateTime, $durationDisplayFormat=false)
getModelStringContent(RedBeanModel $model)
hasCurrentUserReadLatest($modelId)
getMetadataFilteredByOption($option)
getMetadataFilteredByFilteredBy($filteredBy)
removePersonWhoHasNotReadLatestToModel($model, $personWhoHasNotReadLatest)
resolveMarkUnread($modelId)
getMachableInboxOrderByAttributeName()
addPersonWhoHasNotReadLatestToModel($model, $personWhoHasNotReadLatest)
static makeDataProvider(array $metadata, $listModelClassName, $dataProviderClassName, $sortAttribute, $sortDescending, $pageSize, $stateMetadataAdapterClassName=null)
resolveMarkRead($modelId)
markUserAsHavingUnreadLatestModel($model, User $user)
markUserAsHavingReadLatestModel($model, 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.