Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
MarketingListMembersPortletView.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  implements PortletViewInterface
39  {
40  // TODO: @Shoaibi: Low: refactor this and LatestActivitiesForPortletView, create a parent PortletView Class
45  protected $cssClasses = array('portlet-with-toolbar');
46 
47  protected $params;
48 
49  protected $controllerId;
50 
51  protected $moduleId;
52 
53  protected $model;
54 
55  protected $uniqueLayoutId;
56 
57  protected $viewData;
58 
59  protected $listView;
60 
61  protected $dataProvider;
62 
63  protected $uniquePageId;
64 
65  protected $configurationForm;
66 
67  protected static $persistentUserPortletConfigs = array(
68  'filteredBySubscriptionType',
69  );
70 
77  public function __construct($viewData, $params, $uniqueLayoutId)
78  {
79  assert('is_array($viewData) || $viewData == null');
80  assert('isset($params["relationModuleId"])');
81  assert('isset($params["relationModel"])');
82  assert('isset($params["portletId"])');
83  assert('is_string($uniqueLayoutId)');
84  $this->moduleId = $params['relationModuleId'];
85  $this->model = $params['relationModel'];
86  $this->modelId = $this->model->id;
87  $this->controllerId = $params['controllerId'];
88  $this->viewData = $viewData;
89  $this->params = $params;
90  $this->uniqueLayoutId = $uniqueLayoutId;
91  $this->uniquePageId = get_called_class();
92  }
93 
94  public function getPortletParams()
95  {
96  return array();
97  }
98 
99  public function renderPortletHeadContent()
100  {
101  return null;
102  }
103 
104  public static function getDefaultMetadata()
105  {
106  $metadata = array(
107  'global' => array(
108  'toolbar' => array(
109  'elements' => array(
110  array('type' => 'MarketingListAddSubscriberMenu',
111  'iconClass' => 'icon-add',
112  'pageVarName' => 'eval:$this->getPageVarName()',
113  'listViewGridId' => 'eval:$this->getListGridId()'),
114  array('type' => 'MarketingListMembersUnsubscribeMenu',
115  'iconClass' => 'icon-edit',
116  'controllerId' => 'eval:$this->getMassActionsControllerId()',
117  'pageVarName' => 'eval:$this->getPageVarName()',
118  'listViewGridId' => 'eval:$this->getListGridId()'),
119  array('type' => 'MassDeleteMenu',
120  'iconClass' => 'icon-delete',
121  'controllerId' => 'eval:$this->getMassActionsControllerId()',
122  'pageVarName' => 'eval:$this->getPageVarName()',
123  'listViewGridId' => 'eval:$this->getListGridId()'),
124  ),
125  ),
126  ),
127  );
128  return $metadata;
129  }
130 
134  public static function getPortletDescription()
135  {
136  }
137 
138  public function getTitle()
139  {
140  return Zurmo::t('LeadsModule', 'ContactsModulePluralLabel/LeadsModulePluralLabel',
142  }
143 
144  public function renderContent()
145  {
146  if ($this->shouldRenderViewToolBar())
147  {
148  $actionElementBar = $this->renderViewToolBar();
149  }
150  elseif ($this->shouldRenderActionElementBar())
151  {
152  $actionElementBar = ZurmoHtml::tag('nav', array('class' => 'pillbox clearfix'),
153  $this->renderActionElementBar(false));
154  }
155  else
156  {
157  $actionElementBar = null;
158  }
159  $content = null;
160  if ($actionElementBar != null)
161  {
162  $content .= $actionElementBar;
163  }
164  $content .= $this->renderSearchFormAndListContent();
165  return ZurmoHtml::tag('div', array('class' => $this->getWrapperDivClass()), $content);
166  }
167 
168  protected function shouldRenderViewToolBar()
169  {
170  return false;
171  }
172 
173  protected function shouldRenderActionElementBar()
174  {
175  if (ArrayUtil::getArrayValue($this->params, 'isAjaxRequest'))
176  {
177  return false;
178  }
179  return true;
180  }
181 
182  public static function canUserConfigure()
183  {
184  return false;
185  }
186 
191  public static function getPortletRulesType()
192  {
193  return 'ModelDetails';
194  }
195 
199  public static function getModuleClassName()
200  {
201  return 'MarketingListsModule';
202  }
203 
208  protected function getPortletDetailsUrl()
209  {
210  return Yii::app()->createUrl('/' . $this->moduleId . '/defaultPortlet/details',
211  array_merge($_GET, array( 'portletId' => $this->getPortletId(),
212  'uniqueLayoutId' => $this->uniqueLayoutId)));
213  }
214 
215  protected function getPortletId()
216  {
217  return ArrayUtil::getArrayValueWithExceptionIfNotFound($this->params, 'portletId');
218  }
219 
224  protected function getNonAjaxRedirectUrl()
225  {
226  $redirectUrl = ArrayUtil::getArrayValue($this->params, 'redirectUrl');
227  if ($redirectUrl && strpos($redirectUrl, 'defaultPortlet') === false)
228  {
229  return $redirectUrl;
230  }
231  else
232  {
233  return Yii::app()->createUrl('/' . $this->moduleId . '/' . $this->controllerId . '/details',
234  array( 'id' => $this->modelId));
235  }
236  }
237 
238  protected function renderSearchFormAndListContent()
239  {
240  $listContent = $this->getListView()->render();
241  return ZurmoHtml::tag('div', array('class' => $this->getListContentWrapperDivClass()), $listContent);
242  }
243 
244  public function makeListView()
245  {
246  $listViewClassName = $this->getListViewClassName();
247  $this->getDataProvider(); // no need to save return value as we don't need it.
248  return new $listViewClassName(
249  $this->dataProvider,
250  $this->configurationForm,
251  $this->controllerId,
252  $this->moduleId,
253  $this->getPortletDetailsUrl(),
254  $this->getNonAjaxRedirectUrl(),
255  $this->uniquePageId,
256  $this->params,
257  get_class(Yii::app()->findModule($this->moduleId))
258  );
259  }
260 
261  protected function getListView()
262  {
263  if ($this->listView === null)
264  {
265  $this->listView = $this->makeListView();
266  }
267  return $this->listView;
268  }
269 
270  protected function resolveConfigFormFromRequest()
271  {
272  $excludeFromRestore = array();
273  if (isset($_GET[get_class($this->configurationForm)]))
274  {
275  $this->configurationForm->setAttributes($_GET[get_class($this->configurationForm)]);
276  $excludeFromRestore = $this->saveUserSettingsFromConfigForm();
277  }
278  $this->restoreUserSettingsToConfigFrom($excludeFromRestore);
279  }
280 
281  protected function saveUserSettingsFromConfigForm()
282  {
283  $savedConfigs = array();
284  $configUtil = $this->getConfigUtilClassName();
285  foreach (static::$persistentUserPortletConfigs as $persistentUserConfigItem)
286  {
287  if ($this->configurationForm->$persistentUserConfigItem !==
288  $configUtil::getForCurrentUserByPortletIdAndKey( $this->getPortletId(), $persistentUserConfigItem))
289  {
290  $configUtil::setForCurrentUserByPortletIdAndKey( $this->getPortletId(), $persistentUserConfigItem,
291  $this->configurationForm->$persistentUserConfigItem);
292  $savedConfigs[] = $persistentUserConfigItem;
293  }
294  }
295  return $savedConfigs;
296  }
297 
298  protected function restoreUserSettingsToConfigFrom($excludeFromRestore)
299  {
300  foreach (static::$persistentUserPortletConfigs as $persistentUserConfigItem)
301  {
302  if (in_array($persistentUserConfigItem, $excludeFromRestore))
303  {
304  continue;
305  }
306  else
307  {
308  $configUtil = $this->getConfigUtilClassName();
309  $persistentUserConfigItemValue = $configUtil::getForCurrentUserByPortletIdAndKey(
310  $this->getPortletId(),
311  $persistentUserConfigItem
312  );
313  if (isset($persistentUserConfigItemValue))
314  {
315  $this->configurationForm->$persistentUserConfigItem = $persistentUserConfigItemValue;
316  }
317  }
318  }
319  }
320 
321  protected function makeConfigurationForm()
322  {
323  $this->configurationForm = null;
324  $configFormClass = $this->getConfigurationFormClassName();
325  if ($configFormClass)
326  {
327  $this->configurationForm = new $configFormClass();
328  $this->resolveConfigFormFromRequest();
329  }
330  }
331 
332  protected function getConfigurationFormClassName()
333  {
334  return 'MarketingListMembersConfigurationForm';
335  }
336 
337  protected function getConfigurationForm()
338  {
339  if ($this->configurationForm === null)
340  {
341  $this->makeConfigurationForm();
342  }
343  return $this->configurationForm;
344  }
345 
346  protected function getDataProvider()
347  {
348  if ($this->dataProvider === null)
349  {
350  $this->dataProvider = $this->makeDataProvider();
351  }
352  return $this->dataProvider;
353  }
354 
355  protected function getPageVarName()
356  {
357  return $this->getDataProvider()->getPagination()->pageVar;
358  }
359 
360  protected function getListViewClassName()
361  {
362  return 'MarketingListMembersListView';
363  }
364 
365  protected function getListGridId()
366  {
367  return $this->getListView()->getGridViewId();
368  }
369 
370  protected function getWrapperDivClass()
371  {
372  return MarketingListDetailsAndRelationsView::MEMBERS_PORTLET_CLASS;
373  }
374 
375  protected function getListContentWrapperDivClass()
376  {
377  return 'marketing-list-members-list';
378  }
379 
380  protected function getConfigUtilClassName()
381  {
382  return 'MarketingListMembersPortletPersistentConfigUtil';
383  }
384 
385  protected function getMassActionsControllerId()
386  {
387  return 'member';
388  }
389 
390  protected function makeDataProvider()
391  {
392  $pageSize = Yii::app()->pagination->resolveActiveForCurrentUserByType('subListPageSize');
393  $searchAttributes = $this->getSearchAttributes();
394  $sortAttributes = $this->getSortAttributes();
395  $sortDescending = $this->getIsSortDescending();
396  return new RedBeanModelsDataProvider($this->uniquePageId,
397  $sortAttributes,
398  $sortDescending,
399  $searchAttributes,
400  array('pagination' => array('pageSize' => $pageSize))
401  );
402  }
403 
404  protected function getSearchAttributes()
405  {
406  $form = $this->getConfigurationForm();
408  $form->filteredBySubscriptionType,
409  $form->filteredBySearchTerm);
410  }
411 
412  protected function getSortAttributes()
413  {
414  return MarketingListMembersUtil::makeSortAttributeData();
415  }
416 
417  protected function getIsSortDescending()
418  {
419  return MarketingListMembersUtil::getIsSortDescending();
420  }
421  }
422 ?>
static getTranslationParamsForAllModules()
Definition: LabelUtil.php:75
__construct($viewData, $params, $uniqueLayoutId)
static getArrayValue($array, $element, $defaultValue=null)
Definition: ArrayUtil.php:45
renderViewToolBar($renderInForm=true)
static makeSearchAttributeData($marketingListId, $filterBySubscriptionType, $filterBySearchTerm)
static getArrayValueWithExceptionIfNotFound($array, $element)
Definition: ArrayUtil.php:72
renderActionElementBar($renderedInForm)
Generated on Fri Jul 10 2020 07:10:33
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.