All Data Structures Functions Variables Pages
LatestActivitiesForPortletView.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  implements PortletViewInterface,
44  {
49  protected $params;
50 
51  protected $controllerId;
52 
53  protected $moduleId;
54 
55  protected $model;
56 
57  protected $uniqueLayoutId;
58 
59  protected $viewData;
60 
61  protected static $persistantUserPortletConfigs = array(
62  'rollup',
63  'ownedByFilter',
64  'filteredByModelName'
65  );
66 
67  abstract protected function getLatestActivitiesViewClassName();
68 
75  public function __construct($viewData, $params, $uniqueLayoutId)
76  {
77  assert('is_array($viewData) || $viewData == null');
78  assert('isset($params["relationModuleId"])');
79  assert('isset($params["relationModel"])');
80  assert('isset($params["portletId"])');
81  assert('is_string($uniqueLayoutId)');
82  $this->moduleId = $params['relationModuleId'];
83  $this->viewData = $viewData;
84  $this->params = $params;
85  $this->uniqueLayoutId = $uniqueLayoutId;
86  }
87 
88  public function getPortletParams()
89  {
90  return array();
91  }
92 
93  public static function getDefaultMetadata()
94  {
95  $metadata = array(
96  'perUser' => array(
97  'title' => "eval:Zurmo::t('ActivitiesModule', 'Latest Activities')",
98  ),
99  );
100  return $metadata;
101  }
102 
106  public static function getPortletDescription()
107  {
108  }
109 
110  public function getTitle()
111  {
112  $title = Zurmo::t('ActivitiesModule', 'Latest Activities');
113  return $title;
114  }
115 
116  public function renderContent()
117  {
118  return $this->renderLatestActivitiesContent();
119  }
120 
121  protected function renderLatestActivitiesContent()
122  {
123  $mashableModelClassNamesAndDisplayLabels = LatestActivitiesUtil::
125  static::includeHavingRelatedItemsWhenRenderingMashableModels());
126  if (count($mashableModelClassNamesAndDisplayLabels) > 0)
127  {
128  $uniquePageId = get_called_class();
129  $latestActivitiesConfigurationForm = $this->makeLatestActivitiesConfigurationForm();
130  $latestActivitiesConfigurationForm->mashableModelClassNamesAndDisplayLabels =
131  $mashableModelClassNamesAndDisplayLabels;
132  $this->resolveLatestActivitiesConfigFormFromRequest($latestActivitiesConfigurationForm);
133  $latestActivitiesViewClassName = $this->getLatestActivitiesViewClassName();
134  $dataProvider = $this->getDataProvider($uniquePageId, $latestActivitiesConfigurationForm);
135  $latestView = new $latestActivitiesViewClassName($dataProvider,
136  $latestActivitiesConfigurationForm,
137  'default', 'activities',
138  $this->getPortletDetailsUrl(),
139  $this->getNonAjaxRedirectUrl(),
140  $uniquePageId,
141  $this->params,
142  get_class(Yii::app()->findModule($this->moduleId)));
143  return $latestView->render();
144  }
145  }
146 
147  protected function resolveLatestActivitiesConfigFormFromRequest(&$latestActivitiesConfigurationForm)
148  {
149  $excludeFromRestore = array();
150  if (isset($_GET[get_class($latestActivitiesConfigurationForm)]))
151  {
152  $latestActivitiesConfigurationForm->setAttributes($_GET[get_class($latestActivitiesConfigurationForm)]);
153  $excludeFromRestore = $this->saveUserSettingsFromConfigForm($latestActivitiesConfigurationForm);
154  }
155  $this->restoreUserSettingsToConfigFrom($latestActivitiesConfigurationForm, $excludeFromRestore);
156  }
157 
158  protected function saveUserSettingsFromConfigForm(&$latestActivitiesConfigurationForm)
159  {
160  $savedConfigs = array();
161  foreach (static::$persistantUserPortletConfigs as $persistantUserConfigItem)
162  {
163  if ($latestActivitiesConfigurationForm->$persistantUserConfigItem !==
165  $persistantUserConfigItem))
166  {
168  $persistantUserConfigItem,
169  $latestActivitiesConfigurationForm->$persistantUserConfigItem
170  );
171  $savedConfigs[] = $persistantUserConfigItem;
172  }
173  }
174  return $savedConfigs;
175  }
176 
177  protected function restoreUserSettingsToConfigFrom(&$latestActivitiesConfigurationForm, $excludeFromRestore)
178  {
179  foreach (static::$persistantUserPortletConfigs as $persistantUserConfigItem)
180  {
181  if (in_array($persistantUserConfigItem, $excludeFromRestore))
182  {
183  continue;
184  }
186  $this->params['portletId'],
187  $persistantUserConfigItem);
188  if (isset($persistantUserConfigItemValue))
189  {
190  $latestActivitiesConfigurationForm->$persistantUserConfigItem = $persistantUserConfigItemValue;
191  }
192  }
193  return $latestActivitiesConfigurationForm;
194  }
195 
196  protected static function includeHavingRelatedItemsWhenRenderingMashableModels()
197  {
198  return false;
199  }
200 
201  protected function makeLatestActivitiesConfigurationForm()
202  {
204  }
205 
210  protected function getPortletDetailsUrl()
211  {
212  return Yii::app()->createUrl('/' . $this->moduleId . '/defaultPortlet/details',
213  array_merge($_GET, array( 'portletId' =>
214  $this->params['portletId'],
215  'uniqueLayoutId' => $this->uniqueLayoutId)));
216  }
217 
222  protected function getNonAjaxRedirectUrl()
223  {
224  return Yii::app()->createUrl('/' . $this->moduleId . '/default/details',
225  array( 'id' => $this->params['relationModel']->id));
226  }
227 
233  protected function getDataProvider($uniquePageId, $form)
234  {
235  assert('is_string($uniquePageId)');
236  assert('$form instanceOf LatestActivitiesConfigurationForm');
237  $pageSize = Yii::app()->pagination->resolveActiveForCurrentUserByType('subListPageSize');
238  $filteredMashableModelClassNames = LatestActivitiesUtil::resolveMashableModelClassNamesByFilteredBy(
239  array_keys($form->mashableModelClassNamesAndDisplayLabels),
240  $form->filteredByModelName);
241  $relationItemId = (int)$this->params['relationModel']->getClassId('Item');
242  if ($form->rollup)
243  {
244  $relationItemsIds = ModelRollUpUtil::getItemIdsByModelAndUser($this->params['relationModel'],
245  Yii::app()->user->userModel);
246  }
247  else
248  {
249  $relationItemsIds = array($relationItemId);
250  }
251  $modelClassNamesAndSearchAttributeData = // Not Coding Standard
253  getSearchAttributesDataByModelClassNamesAndRelatedItemIds($filteredMashableModelClassNames,
254  $relationItemsIds, $form->ownedByFilter);
255  $modelClassNamesAndSortAttributes = // Not Coding Standard
257  return new RedBeanModelsDataProvider($uniquePageId, $modelClassNamesAndSortAttributes,
258  true, $modelClassNamesAndSearchAttributeData,
259  array('pagination' => array('pageSize' => $pageSize)));
260  }
261 
262  public static function canUserConfigure()
263  {
264  return false;
265  }
266 
271  public static function getPortletRulesType()
272  {
273  return 'ModelDetails';
274  }
275 
279  public static function getModuleClassName()
280  {
281  return 'ActivitiesModule';
282  }
283 
284  protected function renderActionContent()
285  {
286  $actionElementContent = $this->renderActionElementMenu(Zurmo::t('Core', 'Create'));
287  $content = null;
288  if ($actionElementContent != null)
289  {
290  $content .= '<div class="view-toolbar-container toolbar-mbmenu clearfix"><div class="view-toolbar">';
291  $content .= $actionElementContent;
292  $content .= '</div></div>';
293  }
294  return $content;
295  }
296 
303  protected function shouldRenderToolBarElement($element, $elementInformation)
304  {
305  assert('$element instanceof ActionElement');
306  assert('is_array($elementInformation)');
307  if (!parent::shouldRenderToolBarElement($element, $elementInformation))
308  {
309  return false;
310  }
311  if (isset($elementInformation['modelClassName']))
312  {
313  $modelClassName = $elementInformation['modelClassName'];
314  //Todo: figure out how to not need to new up a new model.
315  return ActionSecurityUtil::canCurrentUserPerformAction( $element->getActionType(),
316  new $modelClassName(false));
317  }
318  return true;
319  }
320 
321  protected static function resolvePropertyName($attribute)
322  {
323  return 'has' . ucfirst($attribute) . 'Switch';
324  }
325 
326  public static function hasRollupSwitch()
327  {
328  return false;
329  }
330 
332  public static function hasOwnedByFilterSwitch()
333  {
334  return true;
335  }
336 
337  public static function hasFilteredByModelNameSwitch()
338  {
339  return true;
340  }
341 
342  public static function processBeforeDelete($portletId)
343  {
344  foreach (static::$persistantUserPortletConfigs as $persistantUserConfigItem)
345  {
346  $property = static::resolvePropertyName($persistantUserConfigItem);
347  if (method_exists(get_called_class(), $property) && static::$property())
348  {
350  $persistantUserConfigItem,
351  null);
352  }
353  }
354  }
355 
356  public function renderPortletHeadContent()
357  {
358  return $this->renderActionContent();
359  }
360 
361  public static function getAllowedOnPortletViewClassNames()
362  {
363  return array();
364  }
365 
366  public static function allowMultiplePlacement()
367  {
368  return false;
369  }
370  }
371 ?>
static getMashableModelDataForCurrentUser($includeHavingRelatedItems=true)
__construct($viewData, $params, $uniqueLayoutId)
static setForCurrentUserByPortletIdAndKey($portletId, $keyName, $value)
static resolveMashableModelClassNamesByFilteredBy($mashableModelClassNames, $filteredByModelName)
static getSearchAttributesDataByModelClassNamesAndRelatedItemIds($modelClassNames, $relationItemIds, $ownedByFilter)
static getItemIdsByModelAndUser(Item $model, User $user)
renderActionElementMenu($title=null, $toolbar= 'toolbar')
shouldRenderToolBarElement($element, $elementInformation)
static getForCurrentUserByPortletIdAndKey($portletId, $keyName, $returnBoolean=false)
static canCurrentUserPerformAction($actionType, $model)
static getSortAttributesByMashableModelClassNames($modelClassNames)
Generated on Thu Apr 2 2020 07:10:40