Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ZurmoModuleController.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 
43  {
44  const ZERO_MODELS_CHECK_FILTER_PATH = 'application.modules.zurmo.controllers.filters.ZeroModelsCheckControllerFilter';
45 
46  public function filters()
47  {
48  return array_merge(parent::filters(),
49  array(
50  array(
51  ZurmoBaseController::RIGHTS_FILTER_PATH . ' + pushDashboard',
52  'moduleClassName' => 'ZurmoModule',
53  'rightName' => ZurmoModule::RIGHT_PUSH_DASHBOARD_OR_LAYOUT,
54  ),
55  )
56  );
57  }
58 
59  public function actionIndex()
60  {
61  $this->actionList();
62  }
63 
72  public function actionUpdateAttributeValue($id, $attribute, $value)
73  {
74  $modelClassName = $this->getModule()->getPrimaryModelName();
75  $model = $modelClassName::getById(intval($id));
77  if (!$model->isAttribute($attribute) || !$model->{$attribute} instanceof CustomField)
78  {
79  throw new NotSupportedException();
80  }
81  $model->{$attribute}->value = $value;
82  $saved = $model->save();
83  if (!$saved)
84  {
85  throw new FailedToSaveModelException();
86  }
87  }
88 
89  public function actionLoadSavedSearch($id, $redirectAction = 'list')
90  {
91  $savedSearch = SavedSearch::getById((int)$id);
93  $getParams = unserialize($savedSearch->serializedData);
94  $getParams = array_merge($getParams, array('savedSearchId' => $id));
95  $url = Yii::app()->createUrl($this->getModule()->getId() . '/' . $this->getId() . '/' .
96  $redirectAction, $getParams);
97  $this->redirect($url);
98  }
99 
110  public function actionSelectFromRelatedList($portletId,
111  $uniqueLayoutId,
112  $relationAttributeName,
113  $relationModelId,
114  $relationModuleId,
115  $stateMetadataAdapterClassName = null)
116  {
117  $portlet = Portlet::getById((int)$portletId);
118  $modalListLinkProvider = new SelectFromRelatedListModalListLinkProvider(
119  $relationAttributeName,
120  (int)$relationModelId,
121  $relationModuleId,
122  $portlet->getUniquePortletPageId(),
123  $uniqueLayoutId,
124  (int)$portlet->id,
125  $this->getModule()->getId()
126  );
128  setAjaxModeAndRenderModalSearchList($this, $modalListLinkProvider, $stateMetadataAdapterClassName);
129  }
130 
131  public function actionAutoComplete($term, $autoCompleteOptions = null)
132  {
133  $modelClassName = $this->getModule()->getPrimaryModelName();
134  echo $this->renderAutoCompleteResults($modelClassName, $term, $autoCompleteOptions);
135  }
136 
137  protected function renderAutoCompleteResults($modelClassName, $term, $autoCompleteOptions = null)
138  {
139  $pageSize = Yii::app()->pagination->resolveActiveForCurrentUserByType('autoCompleteListPageSize',
140  get_class($this->getModule()));
141  $autoCompleteResults = ModelAutoCompleteUtil::getByPartialName($modelClassName, $term, $pageSize, $autoCompleteOptions);
142  if (empty($autoCompleteResults))
143  {
144  $autoCompleteResults = array(array('id' => null,
145  'value' => null,
146  'label' => Zurmo::t('Core', 'No results found')));
147  }
148  return CJSON::encode($autoCompleteResults);
149  }
150 
154  public function actionCreateFromRelation($relationAttributeName, $relationModelId, $relationModuleId, $redirectUrl)
155  {
156  throw new NotImplementedException();
157  }
158 
168  protected function resolveNewModelByRelationInformation($model, $relationAttributeName,
169  $relationModelId, $relationModuleId)
170  {
171  assert('$model instanceof RedBeanModel');
172  assert('is_string($relationAttributeName)');
173  assert('is_int($relationModelId)');
174  assert('is_string($relationModuleId)');
175  $relationType = $model->getRelationType($relationAttributeName);
177  {
178  $relationModel = $model->$relationAttributeName;
179  $relatedModel = $relationModel::getById((int)$relationModelId);
180  $model->$relationAttributeName = $relatedModel;
181  }
182  else
183  {
184  $relationModelClassName = Yii::app()->getModule($relationModuleId)->getPrimaryModelName();
185  $relatedModel = $relationModelClassName::getById($relationModelId);
186  $model->$relationAttributeName->add($relatedModel);
187  }
188  $this->addRelatedModelAccountToModel($model, $relatedModel);
189  return $model;
190  }
191 
197  protected function addRelatedModelAccountToModel(RedBeanModel $model, RedBeanModel $relatedModel)
198  {
199  if (isset($relatedModel->account) && $relatedModel->account->id > 0 &&
200  in_array('account', $model->attributeNames()))
201  {
202  $model->account = $relatedModel->account;
203  }
204  }
205 
211  public function actionCopy($id)
212  {
213  throw new NotImplementedException();
214  }
215 
216  public function actionAuditEventsModalList($id)
217  {
218  $model = $this->resolveModelForAuditEventsModalList($id);
221  $dataProvider = AuditEventsListControllerUtil::makeDataProviderBySearchAttributeData($searchAttributeData);
222  Yii::app()->getClientScript()->setToAjaxMode();
223  echo AuditEventsListControllerUtil::renderList($this, $dataProvider);
224  }
225 
226  protected function resolveModelForAuditEventsModalList($id)
227  {
228  $modelClassName = $this->getModule()->getPrimaryModelName();
229  return $modelClassName::getById((int)$id);
230  }
231 
232  protected function getModelName()
233  {
234  return $this->getModule()->getPrimaryModelName();
235  }
236 
237  protected static function getSearchFormClassName()
238  {
239  return null;
240  }
241 
242  protected function export($stickySearchKey = null, $modelClassName = null, $exportFileName = null)
243  {
244  assert('$stickySearchKey == null || is_string($stickySearchKey)');
245  assert('$modelClassName == null || is_string($modelClassName)');
246  assert('$exportFileName == null || is_string($exportFileName)');
247  if ($modelClassName == null)
248  {
249  $modelClassName = $this->getModelName();
250  }
251  $searchFormClassName = static::getSearchFormClassName();
252  $pageSize = null;
253  $model = new $modelClassName(false);
254 
255  if ($searchFormClassName != null)
256  {
257  $searchForm = new $searchFormClassName($model);
258  }
259  else
260  {
261  throw new NotSupportedException();
262  }
263 
264  $stateMetadataAdapterClassName = $this->resolveStateMetadataAdapterClassNameForExport();
265  $dataProvider = $this->getDataProviderByResolvingSelectAllFromGet(
266  $searchForm,
267  $pageSize,
268  Yii::app()->user->userModel->id,
269  $stateMetadataAdapterClassName,
270  $stickySearchKey
271  );
272 
273  if (!$dataProvider)
274  {
275  $idsToExport = array_filter(explode(",", trim($_GET['selectedIds'], " ,"))); // Not Coding Standard
276  }
277  $totalItems = static::getSelectedRecordCountByResolvingSelectAllFromGet($dataProvider, false);
278 
279  $data = array();
280  if ($totalItems > 0)
281  {
282  if ($totalItems <= ExportModule::$asynchronousThreshold)
283  {
284  // Output csv file directly to user browser
285  if ($dataProvider)
286  {
287  $modelsToExport = ExportUtil::getDataForExport($dataProvider);
288  if (count($modelsToExport) > 0)
289  {
290  $modelToExportAdapter = new ModelToExportAdapter($modelsToExport[0]);
291  $headerData = $modelToExportAdapter->getHeaderData();
292  }
293  foreach ($modelsToExport as $model)
294  {
296  {
297  $modelToExportAdapter = new ModelToExportAdapter($model);
298  $data[] = $modelToExportAdapter->getData();
299  }
300  }
301  }
302  else
303  {
304  $headerData = array();
305  foreach ($idsToExport as $idToExport)
306  {
307  $model = $modelClassName::getById(intval($idToExport));
309  {
310  $modelToExportAdapter = new ModelToExportAdapter($model);
311  $data[] = $modelToExportAdapter->getData();
312  if (count($headerData) == 0)
313  {
314  $headerData = $modelToExportAdapter->getHeaderData();
315  }
316  }
317  }
318  }
319  // Output data
320  if (count($data))
321  {
322  if ($exportFileName == null)
323  {
324  $moduleName = $this->getModule()->getName();
325  if ($moduleName == 'projects')
326  {
327  $fileName = Zurmo::t('ProjectsModule', 'ProjectsModulePluralLabel', LabelUtil::getTranslationParamsForAllModules());
328  }
329  elseif ($moduleName == 'accounts')
330  {
331  $fileName = Zurmo::t('AccountsModule', 'AccountsModulePluralLabel', LabelUtil::getTranslationParamsForAllModules());
332  }
333  elseif ($moduleName == 'contacts')
334  {
335  $fileName = Zurmo::t('ContactsModule', 'ContactsModulePluralLabel', LabelUtil::getTranslationParamsForAllModules());
336  }
337  elseif ($moduleName == 'leads')
338  {
339  $fileName = Zurmo::t('LeadsModule', 'LeadsModulePluralLabel', LabelUtil::getTranslationParamsForAllModules());
340  }
341  elseif ($moduleName == 'meetings')
342  {
343  $fileName = Zurmo::t('MeetingsModule', 'MeetingsModulePluralLabel', LabelUtil::getTranslationParamsForAllModules());
344  }
345  elseif ($moduleName == 'notes')
346  {
347  $fileName = Zurmo::t('NotesModule', 'NotesModulePluralLabel', LabelUtil::getTranslationParamsForAllModules());
348  }
349  elseif ($moduleName == 'opportunities')
350  {
351  $fileName = Zurmo::t('OpportunitiesModule', 'OpportunitiesModulePluralLabel', LabelUtil::getTranslationParamsForAllModules());
352  }
353  elseif ($moduleName == 'products')
354  {
355  $fileName = Zurmo::t('ProductsModule', 'ProductsModulePluralLabel', LabelUtil::getTranslationParamsForAllModules());
356  }
357  elseif ($moduleName == 'productTemplates')
358  {
359  $fileName = Zurmo::t('ProductTemplatesModule', 'ProductTemplatesModulePluralLabel', LabelUtil::getTranslationParamsForAllModules());
360  }
361  elseif ($moduleName == 'tasks')
362  {
363  $fileName = Zurmo::t('TasksModule', 'TasksModulePluralLabel', LabelUtil::getTranslationParamsForAllModules());
364  }
365  else
366  {
367  $fileName = $this->getModule()->getName();
368  }
369  $fileName = $fileName . ".csv";
370  }
371  else
372  {
373  $fileName = $exportFileName . ".csv";
374  }
375  $output = ExportItemToCsvFileUtil::export($data, $headerData, $fileName, true);
376  }
377  else
378  {
379  Yii::app()->user->setFlash('notification',
380  Zurmo::t('ZurmoModule', 'There is no data to export.')
381  );
382  }
383  }
384  else
385  {
386  if ($dataProvider)
387  {
388  $serializedData = ExportUtil::getSerializedDataForExport($dataProvider);
389  }
390  else
391  {
392  $serializedData = serialize($idsToExport);
393  }
394 
395  // Create background job
396  $exportItem = new ExportItem();
397  $exportItem->isCompleted = false;
398  $exportItem->exportFileType = 'csv';
399  $exportItem->exportFileName = $this->getModule()->getName();
400  $exportItem->modelClassName = $modelClassName;
401  $exportItem->serializedData = $serializedData;
402  $exportItem->isJobRunning = false;
403  $exportItem->cancelExport = false;
404  $exportItem->save();
405  $exportItem->forget();
406  Yii::app()->user->setFlash('notification',
407  Zurmo::t('ZurmoModule', 'A large amount of data has been requested for export. You will receive ' .
408  'a notification with the download link when the export is complete.')
409  );
410  }
411  }
412  else
413  {
414  Yii::app()->user->setFlash('notification',
415  Zurmo::t('ZurmoModule', 'There is no data to export.')
416  );
417  }
418  $this->redirect(array($this->getId() . '/index'));
419  }
420 
421  protected function resolveStateMetadataAdapterClassNameForExport()
422  {
423  return $this->getModule()->getStateMetadataAdapterClassName();
424  }
425 
426  protected static function getModelAndCatchNotFoundAndDisplayError($modelClassName, $id)
427  {
428  assert('is_string($modelClassName)');
429  assert('is_int($id)');
430  try
431  {
432  return $modelClassName::getById($id);
433  }
434  catch (NotFoundException $e)
435  {
436  $messageContent = Zurmo::t('ZurmoModule', 'The record you are trying to access does not exist.');
437  $messageView = new ModelNotFoundView($messageContent);
438  $view = new ModelNotFoundPageView($messageView);
439  echo $view->render();
440  Yii::app()->end(0, false);
441  }
442  }
443 
444  public function actionRenderStickyListBreadCrumbContent($stickyOffset, $stickyKey, $stickyModelId)
445  {
446  if ($stickyOffset == null)
447  {
448  Yii::app()->end(0, false);
449  }
450  $pageSize = Yii::app()->pagination->resolveActiveForCurrentUserByType(
451  'listPageSize', get_class($this->getModule()));
452  $modelClassName = $this->getModule()->getPrimaryModelName();
453  $searchFormClassName = static::getSearchFormClassName();
454  $model = new $modelClassName(false);
455  $searchForm = new $searchFormClassName($model);
456  $dataProvider = $this->resolveSearchDataProvider(
457  $searchForm,
458  $pageSize,
459  null,
460  $stickyKey,
461  false
462  );
463  $totalCount = $dataProvider->calculateTotalItemCount();
464  $finalOffset = StickySearchUtil::resolveFinalOffsetForStickyList((int)$stickyOffset, (int)$pageSize, (int)$totalCount);
465  $dataProvider->setOffset($finalOffset);
466  $dataList = $dataProvider->getData();
467  if (count($dataList) > 0)
468  {
469  $menuItems = array('label' => 'รท'); //char code is &#247;
470  foreach ($dataList as $row => $data)
471  {
472  $url = Yii::app()->createUrl($this->getModule()->getId() . '/' . $this->getId() . '/details',
473  array('id' => $data->id, 'stickyOffset' => $row + $finalOffset));
474  if ($data->id == $stickyModelId)
475  {
476  $menuItems['items'][] = array( 'label' => strval($data),
477  'url' => $url,
478  'itemOptions' => array('class' => 'strong'));
479  }
480  else
481  {
482  $menuItems['items'][] = array('label' => strval($data), 'url' => $url);
483  }
484  }
485  $cClipWidget = new CClipWidget();
486  $cClipWidget->beginClip("StickyList");
487  $cClipWidget->widget('application.core.widgets.MbMenu', array(
488  'htmlOptions' => array('id' => 'StickyListMenu'),
489  'items' => array($menuItems),
490  ));
491  $cClipWidget->endClip();
492  echo $cClipWidget->getController()->clips['StickyList'];
493  }
494  }
495 
496  public function actionUnlink($id)
497  {
498  $relationModelClassName = ArrayUtil::getArrayValue(GetUtil::getData(), 'relationModelClassName');
499  $relationModelId = ArrayUtil::getArrayValue(GetUtil::getData(), 'relationModelId');
500  $relationModelRelationName = ArrayUtil::getArrayValue(GetUtil::getData(), 'relationModelRelationName');
501  if ($relationModelClassName == null || $relationModelId == null || $relationModelRelationName == null)
502  {
503  throw new NotSupportedException();
504  }
505  $relationModel = $relationModelClassName::GetById(intval($relationModelId));
506  if ($relationModel->getRelationType($relationModelRelationName) != RedBeanModel::HAS_MANY &&
507  $relationModel->getRelationType($relationModelRelationName) != RedBeanModel::MANY_MANY)
508  {
509  throw new NotSupportedException();
510  }
511  $modelClassName = $relationModel->getRelationModelClassName($relationModelRelationName);
512  $model = $modelClassName::getById((int)$id);
515  $relationModel->$relationModelRelationName->remove($model);
516  $saved = $relationModel->save();
517  if (!$saved)
518  {
519  throw new FailedToSaveModelException();
520  }
521  }
522 
530  public function actionSearchForDuplicateModels($attribute, $value)
531  {
532  throw new NotImplementedException();
533  }
534 
538  public function processListViewMerge($modelClassName,
539  $mergedModelFormClassName,
540  $viewPrefix,
541  $pageView,
542  $redirectUrl)
543  {
544  $getData = GetUtil::getData();
545  try
546  {
547  $modelsList = ListViewMergeUtil::getSelectedModelsListForMerge($modelClassName, $getData);
548  }
549  catch (NotFoundException $exception)
550  {
551  $message = Zurmo::t('ZurmoModule', 'At least one record you are trying to merge does not exist.');
552  Yii::app()->user->setFlash('notification', $message);
553  $this->redirect('index');
554  }
555  $model = new $mergedModelFormClassName('listViewMerge');
556  $model->selectedModels = $modelsList;
558  $redirectUrl = Yii::app()->createUrl($redirectUrl);
559  if ($model->validate())
560  {
561  $titleBarAndEditView = $this->makeListMergeView(
562  $this->attemptToSaveModelFromPost($model->primaryModel, null, $redirectUrl),
563  $viewPrefix, array_values($modelsList));
564  $view = new $pageView(ZurmoDefaultViewUtil::
565  makeStandardViewForCurrentUser($this, $titleBarAndEditView));
566  echo $view->render();
567  }
568  else
569  {
570  $this->redirect($redirectUrl);
571  }
572  }
573 
578  protected function beforeRedirect($model)
579  {
580  assert('$model instanceof RedBeanModel');
581  $getData = GetUtil::getData();
582  if ($this->getAction()->id == 'listViewMerge')
583  {
584  Yii::app()->gameHelper->muteScoringModelsOnSave();
586  Yii::app()->gameHelper->unmuteScoringModelsOnSave();
587  }
588  }
589 
590  public function actionPushLayout($id)
591  {
592  $modelClassName = $this->getModelName();
593  $model = $modelClassName::getById(intval($id));
594  if (isset($_POST[$modelClassName]))
595  {
596  $groupsAndUsers = PushDashboardUtil::resolveGroupsAndUsersFromPost($_POST[$modelClassName]);
597  PushDashboardUtil::pushLayoutToUsers($model, $groupsAndUsers);
598  Yii::app()->user->setFlash('notification', Zurmo::t('ZurmoModule', 'Layout pushed successfully'));
599  $this->redirect(array($this->getId() . '/details', 'id' => $id));
600  }
601  $editView = new PushDashboardEditView($this->getId(), $this->getModule()->getId(), $model,
602  Zurmo::t('ZurmoModule', 'Push Layout'));
604  echo $view->render();
605  }
606  }
607 ?>
static resolveGroupsAndUsersFromPost($postData)
resolveNewModelByRelationInformation($model, $relationAttributeName, $relationModelId, $relationModuleId)
static processCopyRelationsAndDeleteNonPrimaryModelsInMerge($primaryModel, $getData)
static getDataForExport(CDataProvider $dataProvider)
Definition: ExportUtil.php:43
static getSelectedModelsListForMerge($modelClassName, $getData)
static renderList(CController $controller, $dataProvider)
static getTranslationParamsForAllModules()
Definition: LabelUtil.php:75
static getSerializedDataForExport(CDataProvider $dataProvider)
Definition: ExportUtil.php:54
static doesCurrentUserHavePermissionOnSecurableItem($securableItem, $permissionToCheck)
static pushLayoutToUsers($model, $groupsAndUsers)
processListViewMerge($modelClassName, $mergedModelFormClassName, $viewPrefix, $pageView, $redirectUrl)
const HAS_ONE
Definition: BeanModel.php:64
const HAS_ONE_BELONGS_TO
Definition: BeanModel.php:48
static getArrayValue($array, $element, $defaultValue=null)
Definition: ArrayUtil.php:45
actionSearchForDuplicateModels($attribute, $value)
static resolveFinalOffsetForStickyList($stickyOffset, $pageSize, $totalCount)
static setPrimaryModelForListViewMerge($model, $getData)
static makeDataProviderBySearchAttributeData($searchAttributeData)
static resolveAccessCanCurrentUserReadModel(RedBeanModel $model, $fromAjax=false)
static getByPartialName($modelClassName, $partialName, $pageSize, $autoCompleteOptions=null)
static export($data, $headerData=array(), $exportFileName= 'exports.csv', $download=false, $allowHeaderOnlyConversion=false, $shouldTrim=false)
const MANY_MANY
Definition: BeanModel.php:78
static getById($id, $modelClassName=null)
static setAjaxModeAndRenderModalSearchList(CController $controller, $modalListLinkProvider, $stateMetadataAdapterClassName=null)
const HAS_MANY
Definition: BeanModel.php:71
addRelatedModelAccountToModel(RedBeanModel $model, RedBeanModel $relatedModel)
actionUpdateAttributeValue($id, $attribute, $value)
static makeStandardViewForCurrentUser(CController $controller, View $containedView)
actionCreateFromRelation($relationAttributeName, $relationModelId, $relationModuleId, $redirectUrl)
actionSelectFromRelatedList($portletId, $uniqueLayoutId, $relationAttributeName, $relationModelId, $relationModuleId, $stateMetadataAdapterClassName=null)
static resolveAccessCanCurrentUserWriteModel(RedBeanModel $model, $fromAjax=false)
Generated on Thu Mar 4 2021 07:10:28
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.