Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ZurmoPortletController.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 RIGHTS_FILTER_PATH = 'application.modules.zurmo.controllers.filters.RightsControllerFilter';
40 
41  public function filters()
42  {
43  $moduleClassName = get_class($this->getModule());
44  $filters = array();
45  if (is_subclass_of($moduleClassName, 'SecurableModule'))
46  {
47  $filters[] = array(
48  ZurmoBaseController::RIGHTS_FILTER_PATH,
49  'moduleClassName' => $moduleClassName,
50  'rightName' => $moduleClassName::getAccessRight(),
51  );
52  }
53  return $filters;
54  }
55 
56  public function actionDetails($id)
57  {
58  $portletView = $this->getPortletViewForDetails($id);
59  if (!RightsUtil::canUserAccessModule($portletView::getModuleClassName(), Yii::app()->user->userModel))
60  {
61  $messageView = new AccessFailureView();
62  $view = new AccessFailurePageView($messageView);
63  echo $view->render();
64  Yii::app()->end(0, false);
65  }
66  $view = new AjaxPageView($portletView);
67  echo $view->render();
68  }
69 
74  public function actionListDetails($id)
75  {
76  $portletView = $this->getPortletViewForDetails($id);
77  if (!RightsUtil::canUserAccessModule($portletView::getModuleClassName(), Yii::app()->user->userModel))
78  {
79  $messageView = new AccessFailureView();
80  $view = new AccessFailurePageView($messageView);
81  echo $view->render();
82  Yii::app()->end(0, false);
83  }
84  $view = new AjaxPageView($portletView->makeListView());
85  echo $view->render();
86  }
87 
92  public function actionMyListDetails()
93  {
94  $portlet = Portlet::getById(intval($_GET['portletId']));
95  $portletView = $portlet->getView();
96  if (!RightsUtil::canUserAccessModule($portletView::getModuleClassName(), Yii::app()->user->userModel))
97  {
98  $messageView = new AccessFailureView();
99  $view = new AccessFailurePageView($messageView);
100  echo $view->render();
101  Yii::app()->end(0, false);
102  }
103  $view = new AjaxPageView($portletView);
104  echo $view->render();
105  }
106 
112  public function actionViewAction($id, $action)
113  {
114  $id = intval($id);
115  $modelName = $this->getModule()->getPrimaryModelName();
116  $model = $modelName::getById($id);
118  $portlet = Portlet::getById(intval($_GET['portletId']));
119 
120  $portlet->params = array(
121  'controllerId' => 'default',
122  'relationModuleId' => $this->getModule()->getId(),
123  'relationModel' => $model,
124  'redirectUrl' => Yii::app()->request->getRequestUri(),
125  );
126  $portletView = $portlet->getView();
127  if (!RightsUtil::canUserAccessModule($portletView::getModuleClassName(), Yii::app()->user->userModel))
128  {
129  Yii::app()->end(0, false);
130  }
131  $portletView->$action();
132  }
133 
139  public function actionMyListViewAction($action)
140  {
141  $portlet = Portlet::getById(intval($_GET['portletId']));
142  $portletView = $portlet->getView();
143  if (!RightsUtil::canUserAccessModule($portletView::getModuleClassName(), Yii::app()->user->userModel))
144  {
145  Yii::app()->end(0, false);
146  }
147  $portletView->$action();
148  }
149 
163  public function actionSelectFromRelatedListSave($modelId, $portletId, $uniqueLayoutId,
164  $relationAttributeName, $relationModelId, $relationModuleId, $relationModelClassName = null)
165  {
166  if ($relationModelClassName == null)
167  {
168  $relationModelClassName = Yii::app()->getModule($relationModuleId)->getPrimaryModelName();
169  }
170  $relationModel = $relationModelClassName::getById((int)$relationModelId);
171  $modelClassName = $this->getModule()->getPrimaryModelName();
172  $model = $modelClassName::getById((int)$modelId);
173  $redirectUrl = $this->createUrl('/' . $relationModuleId . '/default/details',
174  array('id' => $relationModelId));
175  if (!$model->$relationAttributeName->contains($relationModel))
176  {
177  $model->$relationAttributeName->add($relationModel);
178  if (!$model->save())
179  {
180  $this->processSelectFromRelatedListSaveFails($model);
181  }
182  }
183  else
184  {
185  $this->processSelectFromRelatedListSaveAlreadyConnected($model);
186  }
187  $isViewLocked = ZurmoDefaultViewUtil::getLockKeyForDetailsAndRelationsView('lockPortletsForDetailsAndRelationsView');
188  $this->redirect(array('/' . $relationModuleId . '/defaultPortlet/modalRefresh',
189  'id' => $relationModelId,
190  'portletId' => $portletId,
191  'uniqueLayoutId' => $uniqueLayoutId,
192  'redirectUrl' => $redirectUrl,
193  'portletParams' => array( 'relationModuleId' => $relationModuleId,
194  'relationModelId' => $relationModelId),
195  'portletsAreRemovable' => !$isViewLocked));
196  }
197 
198  protected function processSelectFromRelatedListSaveFails(RedBeanModel $model)
199  {
200  $header = Zurmo::t('ZurmoModule', 'Please resolve the following issues for {modelString}:',
201  array('{modelString}' => strval($model)));
202  echo CJSON::encode(array('message' => ZurmoHtml::errorSummary(array($model), $header),
203  'messageType' => 'error'));
204  Yii::app()->end(0, false);
205  }
206 
207  protected function processSelectFromRelatedListSaveAlreadyConnected(RedBeanModel $model)
208  {
209  echo CJSON::encode(array('message' => Zurmo::t('ZurmoModule', '{modelString} is already connected to this record.',
210  array('{modelString}' => strval($model))),
211  'messageType' => 'message'));
212  Yii::app()->end(0, false);
213  }
214 
215  public function resolveAndGetModuleId()
216  {
217  return $this->getModule()->getId();
218  }
219 
220  public function actionAddList()
221  {
222  Yii::app()->getClientScript()->setToAjaxMode();
223  $view = new ModalView($this,
225  $this->getId(),
226  $this->getModule()->getId(),
227  $_GET['modelId'], //dashboard id is model id
228  $_GET['uniqueLayoutId']
229  ));
230  echo $view->render();
231  }
232 
240  public function actionAdd()
241  {
242  assert('!empty($_GET["uniqueLayoutId"])');
243  assert('!empty($_GET["portletType"])');
244  $isPortletAlreadyAdded = Portlet::doesPortletExistByViewTypeLayoutIdAndUser($_GET['portletType'], $_GET['uniqueLayoutId'], Yii::app()->user->userModel->id);
245  $maximumColumns = $this->resolveMaximumColumnsByLayoutId();
246 
247  if ($isPortletAlreadyAdded === false)
248  {
249  $this->resetPortletsInColumnToAccomodateNewPortlet($maximumColumns);
250  Portlet::makePortletUsingViewType($_GET['portletType'], $_GET['uniqueLayoutId'], Yii::app()->user->userModel, intval($maximumColumns));
251  }
252 
253  if (!empty($_GET['modelId']))
254  {
255  $dashboardId = $_GET['modelId'];
256  }
257  else
258  {
259  $dashboardId = '';
260  }
261 
262  //Please see @link:AccountDetailsAndRelationsPortletViewTest
263  if (isset($_GET['redirect']))
264  {
265  return;
266  }
267  $this->redirect(array('/' . $this->resolveAndGetModuleId() . '/default/details', 'id' => $dashboardId));
268  }
269 
274  protected function resolveMaximumColumnsByLayoutId()
275  {
277  $layoutType = $layoutTypes[ConfigurableDetailsAndRelationsView::getDefaultLayoutType()];
278  $maximumColumns = substr($layoutType, 0, 1);
279  return $maximumColumns;
280  }
281 
286  protected function resetPortletsInColumnToAccomodateNewPortlet($maximumColumns)
287  {
288  $portletCollection = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition($_GET['uniqueLayoutId'], Yii::app()->user->userModel->id, array());
289  $maximumIndexFromCollection = max(array_keys($portletCollection));
290  $maximumIterativeIndex = min($maximumIndexFromCollection, $maximumColumns);
291  if (!empty($portletCollection))
292  {
293  if ($maximumIterativeIndex > 1)
294  {
295  foreach ($portletCollection[$maximumIterativeIndex] as $position => $portlet)
296  {
297  $portlet->position = $portlet->position + 1;
298  $portlet->save();
299  }
300  }
301  }
302  }
303 
304  protected function getPortletViewForDetails($id)
305  {
306  $id = intval($id);
307  $modelName = $this->getModule()->getPrimaryModelName();
308  $model = $modelName::getById($id);
310  $portlet = Portlet::getById(intval($_GET['portletId']));
311 
312  if (null != $redirectUrl = ArrayUtil::getArrayValue($_GET, 'redirectUrl'))
313  {
314  $redirectUrl = $redirectUrl;
315  }
316  else
317  {
318  $redirectUrl = Yii::app()->request->getRequestUri();
319  }
320  $portlet->params = array(
321  'controllerId' => 'default',
322  'relationModuleId' => $this->getModule()->getId(),
323  'relationModel' => $model,
324  'redirectUrl' => $redirectUrl,
325  );
326  $portletView = $portlet->getView();
327  return $portletView;
328  }
329  }
330 ?>
static makePortletUsingViewType($viewType, $uniqueLayoutId, $user, $numberOfColumns)
Definition: Portlet.php:160
static doesPortletExistByViewTypeLayoutIdAndUser($viewType, $uniqueLayoutId, $userId)
Definition: Portlet.php:276
actionSelectFromRelatedListSave($modelId, $portletId, $uniqueLayoutId, $relationAttributeName, $relationModelId, $relationModuleId, $relationModelClassName=null)
static getArrayValue($array, $element, $defaultValue=null)
Definition: ArrayUtil.php:45
resetPortletsInColumnToAccomodateNewPortlet($maximumColumns)
static resolveAccessCanCurrentUserReadModel(RedBeanModel $model, $fromAjax=false)
static canUserAccessModule($moduleClassName, $user)
Definition: RightsUtil.php:103
static errorSummary($model, $header=null, $footer=null, $htmlOptions=array())
Definition: ZurmoHtml.php:57
static getLockKeyForDetailsAndRelationsView($key)
static getById($id, $modelClassName=null)
Generated on Fri Jul 3 2020 07:10:37
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.