Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
DefaultController.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  {
42  public function filters()
43  {
44  $modelClassName = $this->getModule()->getPrimaryModelName();
45  $viewClassName = $modelClassName . 'EditAndDetailsView';
46  return array_merge(parent::filters(),
47  array(
48  array(
49  ZurmoBaseController::REQUIRED_ATTRIBUTES_FILTER_PATH . ' + create, createFromRelation, edit',
50  'moduleClassName' => get_class($this->getModule()),
51  'viewClassName' => $viewClassName,
52  ),
53  array(
54  ZurmoModuleController::ZERO_MODELS_CHECK_FILTER_PATH . ' + list, index',
55  'controller' => $this,
56  ),
57  )
58  );
59  }
60 
65  public function actionDetails($id = null)
66  {
67  $urlParams = array($this->getId() . '/combinedDetails');
68  $this->redirect($urlParams);
69  }
70 
74  public function actionCreate()
75  {
76  $savedCalendar = new SavedCalendar();
77  $savedCalendar->moduleClassName = 'MeetingsModule';
78  $attributes = CalendarUtil::getModelAttributesForSelectedModule($savedCalendar->moduleClassName);
79  $attributeKeys = array_keys($attributes);
80  $savedCalendar->startAttributeName = $attributeKeys[0];
81  $this->attemptToValidateAjaxFromPost($savedCalendar, 'SavedCalendar');
82  if (isset($_POST['SavedCalendar']))
83  {
84  $this->attemptToSaveModelFromPost($savedCalendar, null, false, false);
85  echo CJSON::encode(array('redirecttodetails' => true));
86  Yii::app()->end(0, false);
87  }
88  else
89  {
90  $editAndDetailsView = $this->makeEditAndDetailsView(
91  $this->attemptToSaveModelFromPost($savedCalendar, null, false, false), 'Edit');
93  makeStandardViewForCurrentUser($this, $editAndDetailsView));
94  echo $view->render();
95  }
96  }
97 
102  public function actionEdit($id)
103  {
104  $savedCalendar = SavedCalendar::getById(intval($id));
106  $this->processEdit($savedCalendar);
107  }
108 
113  protected function processEdit(SavedCalendar $calendar)
114  {
115  $this->attemptToValidateAjaxFromPost($calendar, 'SavedCalendar');
116  if (isset($_POST['SavedCalendar']))
117  {
118  $this->attemptToSaveModelFromPost($calendar, null, false, false);
119  echo CJSON::encode(array('redirecttodetails' => true));
120  Yii::app()->end(0, false);
121  }
122  else
123  {
125  makeStandardViewForCurrentUser($this,
126  $this->makeEditAndDetailsView(
127  $calendar, 'Edit')));
128  echo $view->render();
129  }
130  }
131 
135  public function actionCombinedDetails()
136  {
137  $dataProvider = CalendarUtil::getCalendarItemsDataProvider(Yii::app()->user->userModel);
138  $interactiveCalendarView = new CombinedCalendarView($dataProvider, $this->getId(), $this->getModule()->getId());
140  makeStandardViewForCurrentUser($this, $interactiveCalendarView));
141  echo $view->render();
142  }
143 
151  public function actionRelationsAndAttributesTree($type, $treeType, $id = null, $nodeId = null)
152  {
153  $postData = PostUtil::getData();
154  $report = CalendarUtil::resolveReportBySavedCalendarPostData($type, $id, $postData);
155  if ($nodeId != null)
156  {
157  $reportToTreeAdapter = new CalendarReportRelationsAndAttributesToTreeAdapter($report, $treeType);
158  echo ZurmoTreeView::saveDataAsJson($reportToTreeAdapter->getData($nodeId));
159  Yii::app()->end(0, false);
160  }
161  $view = new ReportRelationsAndAttributesForSavedCalendarTreeView($type, $treeType, 'edit-form');
162  $content = $view->render();
163  Yii::app()->getClientScript()->setToAjaxMode();
164  Yii::app()->getClientScript()->render($content);
165  echo $content;
166  }
167 
178  public function actionAddAttributeFromTree($type, $treeType, $nodeId, $rowNumber,
179  $trackableStructurePosition = false, $id = null)
180  {
181  $postData = PostUtil::getData();
182  $report = CalendarUtil::resolveReportBySavedCalendarPostData($type, $id, $postData);
183  ReportUtil::processAttributeAdditionFromTree($nodeId, $treeType, $report, $rowNumber, $trackableStructurePosition);
184  }
185 
192  protected function attemptToValidateAjaxFromPost($model, $postVariableName)
193  {
194  if (isset($_POST['ajax']) && $_POST['ajax'] == 'edit-form')
195  {
196  $postData = PostUtil::getData();
197  $readyToUsePostData = ExplicitReadWriteModelPermissionsUtil::
198  removeIfExistsFromPostData($_POST[$postVariableName]);
199  $sanitizedPostdata = PostUtil::sanitizePostByDesignerTypeForSavingModel($model, $readyToUsePostData);
200  $sanitizedOwnerPostData = PostUtil::
201  sanitizePostDataToJustHavingElementForSavingModel($sanitizedPostdata, 'owner');
202  $sanitizedPostDataWithoutOwner = PostUtil::removeElementFromPostDataForSavingModel($sanitizedPostdata, 'owner');
203  $model->setAttributes(($sanitizedPostDataWithoutOwner));
204  if ($model->validate())
205  {
206  $modelToStringValue = strval($model);
207  if ($sanitizedOwnerPostData != null)
208  {
209  $model->setAttributes($sanitizedOwnerPostData);
210  }
211  if ($model instanceof OwnedSecurableItem)
212  {
213  $model->validate(array('owner'));
214  }
215  }
217  if (!isset($postData[$wizardFormClassName]))
218  {
219  throw new NotSupportedException();
220  }
222  DataToReportUtil::resolveFiltersStructure($postData[$wizardFormClassName], $report);
223  DataToReportUtil::resolveFilters($postData[$wizardFormClassName], $report);
224  //This would do the filter and filter structure validation
225  $reportToWizardFormAdapter = new ReportToWizardFormAdapter($report);
226  $reportForm = $reportToWizardFormAdapter->makeFormByType();
227  $postData['validationScenario'] = $wizardFormClassName::FILTERS_VALIDATION_SCENARIO;
228  $filtersErrorData = ReportUtil::validateReportWizardForm($postData, $reportForm);
230  $errorData = array_merge($errorData, $filtersErrorData);
231  echo CJSON::encode($errorData);
232  Yii::app()->end(0, false);
233  }
234  }
235 
244  public function actionGetEvents($selectedMyCalendarIds = null,
245  $selectedSharedCalendarIds = null,
246  $startDate = null,
247  $endDate = null,
248  $dateRangeType = null)
249  {
250  $dataProvider = CalendarUtil::processAndGetDataProviderForEventsData($selectedMyCalendarIds,
251  $selectedSharedCalendarIds,
252  $startDate,
253  $endDate,
254  $dateRangeType);
255  $items = CalendarUtil::getFullCalendarItems($dataProvider);
256  foreach ($items as $index => $item)
257  {
258  $itemClass = isset($item['className']) ? $item['className']:null;
259  //If not more events
260  if ($itemClass != 'more-events')
261  {
262  $item['description'] = Yii::app()->createUrl('calendars/default/getCalendarItemDetail',
263  array(
264  'modelClass' => $item['modelClass'],
265  'modelId' => $item['modelId']
266  ));
267  }
268  else
269  {
270  $moreEventStartDate = date('Y-m-d', strtotime($item['start']));
271  $dateTimeObject = new DateTime($moreEventStartDate);
272  $dateTimeObject->add(new DateInterval('P1D'));
273  $moreEventEndDate = $dateTimeObject->format('Y-m-d');
274  $params = array(
275  'selectedMyCalendarIds' => $selectedMyCalendarIds,
276  'selectedSharedCalendarIds' => $selectedSharedCalendarIds,
277  'startDate' => $moreEventStartDate,
278  'endDate' => $moreEventEndDate,
279  'dateRangeType' => SavedCalendar::DATERANGE_TYPE_DAY
280  );
281  $item['description'] = Yii::app()->createUrl('calendars/default/getDayEvents', $params);
282  }
283  $items[$index] = $item;
284  }
285  echo CJSON::encode(array('items' => $items, 'isMaxCountReached' => $dataProvider->getIsMaxCountReached()));
286  }
287 
292  public function actionDelete($id)
293  {
294  $savedCalendar = SavedCalendar::getById(intval($id));
296  $savedCalendar->delete();
297  $dataProvider = CalendarUtil::getCalendarItemsDataProvider(Yii::app()->user->userModel);
298  $savedCalendarSubscriptions = $dataProvider->getSavedCalendarSubscriptions();
299  $content = CalendarUtil::makeCalendarItemsList($savedCalendarSubscriptions->getMySavedCalendarsAndSelected(),
300  'mycalendar[]', 'mycalendar', 'saved');
301  echo $content;
302  }
303 
307  public function actionModalList()
308  {
309  $modalListLinkProvider = new SelectFromSharedCalendarsModalListLinkProvider(
311  'shared-calendars-list'
312  );
314  setAjaxModeAndRenderModalSearchList($this, $modalListLinkProvider, 'SharedCalendersStateMetadataAdapter');
315  }
316 
321  public function actionAddSubsriptionForCalendar($id)
322  {
323  $savedCalendar = SavedCalendar::getById(intval($id));
324  $user = Yii::app()->user->userModel;
325  $savedCalendarSubscription = new SavedCalendarSubscription();
326  $savedCalendarSubscription->user = $user;
327  $savedCalendarSubscription->savedcalendar = $savedCalendar;
328  $savedCalendarSubscription->save();
329  $dataProvider = CalendarUtil::getCalendarItemsDataProvider($user);
330  $savedCalendarSubscriptions = $dataProvider->getSavedCalendarSubscriptions();
331  $content = CalendarUtil::makeCalendarItemsList($savedCalendarSubscriptions->getSubscribedToSavedCalendarsAndSelected(),
332  'sharedcalendar[]', 'sharedcalendar', 'shared');
333  echo $content;
334  }
335 
340  public function actionUnsubscribe($id)
341  {
342  $savedCalendarSubscription = SavedCalendarSubscription::getById(intval($id));
343  $savedCalendarSubscription->delete();
344  $dataProvider = CalendarUtil::getCalendarItemsDataProvider(Yii::app()->user->userModel);
345  $savedCalendarSubscriptions = $dataProvider->getSavedCalendarSubscriptions();
346  $content = CalendarUtil::makeCalendarItemsList($savedCalendarSubscriptions->getSubscribedToSavedCalendarsAndSelected(),
347  'sharedcalendar[]', 'sharedcalendar', 'shared');
348  echo $content;
349  }
350 
356  public function actionGetDateTimeAttributes($moduleName, $attribute)
357  {
358  assert('is_string($attribute)');
359  assert('is_string($moduleName)');
361  $htmlOptions = array();
362  if ($attribute == 'endAttributeName')
363  {
364  $htmlOptions['empty'] = Zurmo::t('Core', '(None)');
365  }
366  echo ZurmoHtml::listOptions('', $data, $htmlOptions);
367  }
368 
373  protected static function getZurmoControllerUtil()
374  {
375  return new CalendarZurmoControllerUtil();
376  }
377 
386  public function actionGetDayEvents($selectedMyCalendarIds = null,
387  $selectedSharedCalendarIds = null,
388  $startDate = null,
389  $endDate = null,
390  $dateRangeType = null)
391  {
392  $dataProvider = CalendarUtil::processAndGetDataProviderForEventsData($selectedMyCalendarIds,
393  $selectedSharedCalendarIds,
394  $startDate,
395  $endDate,
396  $dateRangeType,
397  false);
399  $modifiedItems = array();
400  foreach ($items as $item)
401  {
402  $item['start'] = CalendarUtil::getFullCalendarFormattedDateTimeElement($item['start']);
403  $startDateTime = strtotime($item['start']);
404  if (date('Y-m-d', $startDateTime) == $startDate)
405  {
406  $item['end'] = CalendarUtil::getFullCalendarFormattedDateTimeElement($item['end']);
407  $modifiedItems[] = $item;
408  }
409  }
410  $modifiedItems = CalendarUtil::populateDetailsUrlForCalendarItems($modifiedItems);
411  $calItemListView = new CalendarItemsListView(
412  $this->getId(),
413  $this->getModule()->getId(),
414  $modifiedItems,
415  GetUtil::getData()
416  );
417  Yii::app()->getClientScript()->setToAjaxMode();
418  echo $calItemListView->render();
419  }
420 
427  public function actionGetCalendarItemDetail($modelClass, $modelId)
428  {
429  $model = $modelClass::getById(intval($modelId));
430  $itemDetailViewClassName = $modelClass . 'ForCalendarItemDetailsView';
431  $itemDetailViewInstance = new $itemDetailViewClassName($this->getId(), $this->getModule()->getId(), $model);
432  echo $itemDetailViewInstance->render();
433  }
434 
435  public function actionOrgGraph()
436  {
437  $renderOrgChartModalView = new AccountOrgChartModalView();
438  $view = new ModalView($this, $renderOrgChartModalView);
439  return $view->render();
440  }
441  }
442 ?>
static getModelAttributesForSelectedModule($moduleClassName)
static processDataProviderAndGetCalendarItems(CalendarItemsDataProvider $dataProvider)
actionGetEvents($selectedMyCalendarIds=null, $selectedSharedCalendarIds=null, $startDate=null, $endDate=null, $dateRangeType=null)
static makeCalendarItemsList($data, $field, $itemClass, $type)
static getModalContainerId()
static resolveAccessCanCurrentUserDeleteModel(RedBeanModel $model, $fromAjax=false)
static validateReportWizardForm($postData, ReportWizardForm $model)
Definition: ReportUtil.php:90
static resolveFiltersStructure($data, Report $report)
static processAndGetDataProviderForEventsData($selectedMyCalendarIds=null, $selectedSharedCalendarIds=null, $startDate=null, $endDate=null, $dateRangeType=null, $isSticky=true)
processEdit(SavedCalendar $calendar)
actionGetDayEvents($selectedMyCalendarIds=null, $selectedSharedCalendarIds=null, $startDate=null, $endDate=null, $dateRangeType=null)
actionAddAttributeFromTree($type, $treeType, $nodeId, $rowNumber, $trackableStructurePosition=false, $id=null)
static makeErrorsDataAndResolveForOwnedModelAttributes($model)
static processAttributeAdditionFromTree($nodeId, $treeType, Report $report, $rowNumber, $trackableStructurePosition)
Definition: ReportUtil.php:118
static makeReportBySavedCalendar(SavedCalendar $savedCalendar)
actionRelationsAndAttributesTree($type, $treeType, $id=null, $nodeId=null)
static resolveReportBySavedCalendarPostData($type, $id=null, $postData)
static populateDetailsUrlForCalendarItems($items)
static getFullCalendarFormattedDateTimeElement($dateTime)
attemptToValidateAjaxFromPost($model, $postVariableName)
attemptToSaveModelFromPost($model, $redirectUrlParams=null, $redirect=true, $returnOnValidate=false)
const TYPE_ROWS_AND_COLUMNS
Definition: Report.php:51
actionGetDateTimeAttributes($moduleName, $attribute)
static getById($id, $modelClassName=null)
static setAjaxModeAndRenderModalSearchList(CController $controller, $modalListLinkProvider, $stateMetadataAdapterClassName=null)
static removeElementFromPostDataForSavingModel($sanitizedPostData, $elementName)
Definition: PostUtil.php:116
static resolveFilters($data, Report $report, $shouldRemoveOnlyRuntimeFilters=false)
static getFullCalendarItems(CalendarItemsDataProvider $dataProvider)
static getCalendarItemsDataProvider(User $user)
actionGetCalendarItemDetail($modelClass, $modelId)
static sanitizePostDataToJustHavingElementForSavingModel($sanitizedPostData, $elementName)
Definition: PostUtil.php:106
static sanitizePostByDesignerTypeForSavingModel($model, $postData)
Definition: PostUtil.php:94
static resolveAccessCanCurrentUserWriteModel(RedBeanModel $model, $fromAjax=false)
Generated on Sun Jan 17 2021 07:10:19
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.