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  {
44  public function filters()
45  {
46  $filters = array();
47  $filters[] = array(
48  ZurmoBaseController::RIGHTS_FILTER_PATH . ' - redeemList, redeemReward',
49  'moduleClassName' => 'GameRewardsModule',
50  'rightName' => GameRewardsModule::getAccessRight(),
51  );
52  $filters[] = array(
53  ZurmoBaseController::RIGHTS_FILTER_PATH . ' + massEdit, massEditProgressSave',
54  'moduleClassName' => 'ZurmoModule',
55  'rightName' => ZurmoModule::RIGHT_BULK_WRITE,
56  );
57  $filters[] = array(
58  ZurmoModuleController::ZERO_MODELS_CHECK_FILTER_PATH . ' + list, index',
59  'controller' => $this,
60  );
61  return $filters;
62  }
63 
64  public function actionList()
65  {
66  $pageSize = Yii::app()->pagination->resolveActiveForCurrentUserByType(
67  'listPageSize', get_class($this->getModule()));
68  $gameReward = new GameReward(false);
69  $searchForm = new GameRewardsSearchForm($gameReward);
70  $listAttributesSelector = new ListAttributesSelector('GameRewardsListView', get_class($this->getModule()));
71  $searchForm->setListAttributesSelector($listAttributesSelector);
72  $dataProvider = $this->resolveSearchDataProvider(
73  $searchForm,
74  $pageSize,
75  null,
76  'GameRewardsSearchView'
77  );
78  $title = Zurmo::t('GameRewardsModule',
79  'GameRewardsModulePluralLabel',
81  $breadCrumbLinks = array(
82  $title,
83  );
84  if (isset($_GET['ajax']) && $_GET['ajax'] == 'list-view')
85  {
86  $mixedView = $this->makeListView(
87  $searchForm,
88  $dataProvider
89  );
90  $view = new GameRewardsPageView($mixedView);
91  }
92  else
93  {
94  $mixedView = $this->makeActionBarSearchAndListView($searchForm, $dataProvider);
96  makeViewWithBreadcrumbsForCurrentUser($this, $mixedView,
97  $breadCrumbLinks, 'GameRewardBreadCrumbView'));
98  }
99  echo $view->render();
100  }
101 
102  public function actionDetails($id)
103  {
104  $gameReward = static::getModelAndCatchNotFoundAndDisplayError('GameReward', intval($id));
106  AuditEvent::logAuditEvent('ZurmoModule', ZurmoModule::AUDIT_EVENT_ITEM_VIEWED, array(strval($gameReward), 'GameRewardsModule'), $gameReward);
107  $breadCrumbView = GameRewardsStickySearchUtil::resolveBreadCrumbViewForDetailsControllerAction($this, 'GameRewardsSearchView', $gameReward);
108  $detailsAndRelationsView = $this->makeDetailsAndRelationsView($gameReward, 'GameRewardsModule',
109  'GameRewardDetailsAndRelationsView',
110  Yii::app()->request->getRequestUri(),
111  $breadCrumbView);
113  makeStandardViewForCurrentUser($this, $detailsAndRelationsView));
114  echo $view->render();
115  }
116 
117  public function actionCreate()
118  {
119  $title = Zurmo::t('GameRewardsModule', 'Create Game Reward');
120  $breadCrumbLinks = array($title);
121  $editAndDetailsView = $this->makeEditAndDetailsView(
122  $this->attemptToSaveModelFromPost(new GameReward()), 'Edit');
124  makeViewWithBreadcrumbsForCurrentUser($this, $editAndDetailsView,
125  $breadCrumbLinks, 'GameRewardBreadCrumbView'));
126  echo $view->render();
127  }
128 
129  public function actionEdit($id, $redirectUrl = null)
130  {
131  $gameReward = GameReward::getById(intval($id));
133  $this->processEdit($gameReward, $redirectUrl);
134  }
135 
136  public function actionCopy($id)
137  {
138  $copyToGameReward = new GameReward();
139  $postVariableName = get_class($copyToGameReward);
140  if (!isset($_POST[$postVariableName]))
141  {
142  $gameReward = GameReward::getById((int)$id);
144  ZurmoCopyModelUtil::copy($gameReward, $copyToGameReward);
145  }
146  $this->processEdit($copyToGameReward);
147  }
148 
149  protected function processEdit(GameReward $gameReward, $redirectUrl = null, $isBeingCopied = false)
150  {
151  if ($isBeingCopied)
152  {
153  $title = Zurmo::t('Core', 'Edit Game Reward');
154  }
155  else
156  {
157  $title = Zurmo::t('Core', 'Copy Game Reward');
158  }
159  $breadCrumbLinks = array(strval($gameReward) => array('default/details', 'id' => $gameReward->id), $title);
161  makeViewWithBreadcrumbsForCurrentUser($this,
162  $this->makeEditAndDetailsView(
163  $this->attemptToSaveModelFromPost($gameReward, $redirectUrl), 'Edit'),
164  $breadCrumbLinks, 'GameRewardBreadCrumbView'));
165  echo $view->render();
166  }
167 
182  public function actionMassEdit()
183  {
184  $pageSize = Yii::app()->pagination->resolveActiveForCurrentUserByType(
185  'massEditProgressPageSize');
186  $gameReward = new GameReward(false);
187  $activeAttributes = $this->resolveActiveAttributesFromMassEditPost();
188  $dataProvider = $this->getDataProviderByResolvingSelectAllFromGet(
189  new GameRewardsSearchForm($gameReward),
190  $pageSize,
191  Yii::app()->user->userModel->id,
192  null,
193  'GameRewardsSearchView');
194  $selectedRecordCount = static::getSelectedRecordCountByResolvingSelectAllFromGet($dataProvider);
195  $gameReward = $this->processMassEdit(
196  $pageSize,
197  $activeAttributes,
198  $selectedRecordCount,
199  'GameRewardsPageView',
200  $gameReward,
201  GameRewardsModule::getModuleLabelByTypeAndLanguage('Plural'),
202  $dataProvider
203  );
204  $massEditView = $this->makeMassEditView(
205  $gameReward,
206  $activeAttributes,
207  $selectedRecordCount,
208  GameRewardsModule::getModuleLabelByTypeAndLanguage('Plural')
209  );
211  makeStandardViewForCurrentUser($this, $massEditView));
212  echo $view->render();
213  }
214 
222  public function actionMassEditProgressSave()
223  {
224  $pageSize = Yii::app()->pagination->resolveActiveForCurrentUserByType(
225  'massEditProgressPageSize');
226  $gameReward = new GameReward(false);
227  $dataProvider = $this->getDataProviderByResolvingSelectAllFromGet(
228  new GameRewardsSearchForm($gameReward),
229  $pageSize,
230  Yii::app()->user->userModel->id,
231  null,
232  'GameRewardsSearchView'
233  );
235  'GameReward',
236  $pageSize,
237  GameRewardsModule::getModuleLabelByTypeAndLanguage('Plural'),
238  $dataProvider
239  );
240  }
241 
256  public function actionMassDelete()
257  {
258  $pageSize = Yii::app()->pagination->resolveActiveForCurrentUserByType(
259  'massDeleteProgressPageSize');
260  $gameReward = new GameReward(false);
261 
262  $activeAttributes = $this->resolveActiveAttributesFromMassDeletePost();
263  $dataProvider = $this->getDataProviderByResolvingSelectAllFromGet(
264  new GameRewardsSearchForm($gameReward),
265  $pageSize,
266  Yii::app()->user->userModel->id,
267  null,
268  'GameRewardsSearchView');
269  $selectedRecordCount = static::getSelectedRecordCountByResolvingSelectAllFromGet($dataProvider);
270  $gameReward = $this->processMassDelete(
271  $pageSize,
272  $activeAttributes,
273  $selectedRecordCount,
274  'GameRewardsPageView',
275  $gameReward,
276  GameRewardsModule::getModuleLabelByTypeAndLanguage('Plural'),
277  $dataProvider
278  );
279  $massDeleteView = $this->makeMassDeleteView(
280  $gameReward,
281  $activeAttributes,
282  $selectedRecordCount,
283  GameRewardsModule::getModuleLabelByTypeAndLanguage('Plural')
284  );
286  makeStandardViewForCurrentUser($this, $massDeleteView));
287  echo $view->render();
288  }
289 
297  public function actionMassDeleteProgress()
298  {
299  $pageSize = Yii::app()->pagination->resolveActiveForCurrentUserByType(
300  'massDeleteProgressPageSize');
301  $gameReward = new GameReward(false);
302  $dataProvider = $this->getDataProviderByResolvingSelectAllFromGet(
303  new GameRewardsSearchForm($gameReward),
304  $pageSize,
305  Yii::app()->user->userModel->id,
306  null,
307  'GameRewardsSearchView'
308  );
309  $this->processMassDeleteProgress(
310  'GameReward',
311  $pageSize,
312  GameRewardsModule::getModuleLabelByTypeAndLanguage('Plural'),
313  $dataProvider
314  );
315  }
316 
317  public function actionModalList()
318  {
319  $modalListLinkProvider = new SelectFromRelatedEditModalListLinkProvider(
320  $_GET['modalTransferInformation']['sourceIdFieldId'],
321  $_GET['modalTransferInformation']['sourceNameFieldId'],
322  $_GET['modalTransferInformation']['modalId']
323  );
325  setAjaxModeAndRenderModalSearchList($this, $modalListLinkProvider);
326  }
327 
328  public function actionDelete($id)
329  {
330  $gameReward = GameReward::GetById(intval($id));
332  $gameReward->delete();
333  $this->redirect(array($this->getId() . '/index'));
334  }
335 
336  protected static function getSearchFormClassName()
337  {
338  return 'GameRewardsSearchForm';
339  }
340 
341  public function actionExport()
342  {
343  $this->export('GameRewardsSearchView');
344  }
345 
349  public function actionRedeemList()
350  {
351  $pageSize = Yii::app()->pagination->resolveActiveForCurrentUserByType(
352  'listPageSize', get_class($this->getModule()));
353  $gameReward = new GameReward(false);
354  $searchForm = new GameRewardsSearchForm($gameReward);
355  $dataProvider = $this->resolveSearchDataProvider(
356  $searchForm,
357  $pageSize,
358  'GameRewardsForRedemptionStateMetadataAdapter',
359  'GameRewardsRedeemSearchView'
360  );
361  $breadCrumbLinks = array(
362  Zurmo::t('GameRewardsModule', 'Redeem Rewards'),
363  );
364  if (isset($_GET['ajax']) && $_GET['ajax'] == 'list-view')
365  {
366  $mixedView = $this->makeListView(
367  $searchForm,
368  $dataProvider,
369  'GameRewardsRedeemListView'
370  );
371  $view = new GameRewardsPageView($mixedView);
372  }
373  else
374  {
375  $introView = new GameRewardsRedemptionIntroView(get_class($this->getModule()));
376  $mixedView = $this->makeActionBarSearchAndListView($searchForm, $dataProvider,
377  'SecuredActionBarForGameRewardsSearchAndListView',
378  'GameRewardsRedeem', null, $introView);
380  makeViewWithBreadcrumbsForCurrentUser($this, $mixedView,
381  $breadCrumbLinks, 'GameRewardRedeemBreadCrumbView'));
382  }
383  echo $view->render();
384  }
385 
386  public function actionRedeemReward($id)
387  {
388  $gameReward = static::getModelAndCatchNotFoundAndDisplayError('GameReward', intval($id));
390 
391  $gameCoin = GameCoin::resolveByPerson(Yii::app()->user->userModel);
392  if ($gameCoin->value < $gameReward->cost)
393  {
394  $message = Zurmo::t('GameRewardsModule', 'You do not have enough coins to redeem this reward');
395  echo CJSON::encode(array('message' => $message));
396  Yii::app()->end(0, false);
397  }
398  if ($gameReward->quantity <= 0)
399  {
400  $message = Zurmo::t('GameRewardsModule', 'This reward is no longer available');
401  echo CJSON::encode(array('message' => $message));
402  Yii::app()->end(0, false);
403  }
404  $gameRewardTransaction = new GameRewardTransaction();
405  $gameRewardTransaction->quantity = 1;
406  $gameRewardTransaction->person = Yii::app()->user->userModel;
407  $gameReward->transactions->add($gameRewardTransaction);
408  $gameCoin->removeValue((int)$gameReward->cost);
409  if (!$gameCoin->save())
410  {
411  throw new FailedToSaveModelException();
412  }
413  $gameReward->quantity = $gameReward->quantity - 1;
414  if (!$gameReward->save())
415  {
416  throw new FailedToSaveModelException();
417  }
418  //Notify the owner of the game reward
419  $message = new NotificationMessage();
420  $commonMessage = Zurmo::t('JobsManagerModule', '{name} was redeemed by {personFullName}.',
421  array('{name}' => strval($gameReward),
422  '{personFullName}' => strval(Yii::app()->user->userModel)));
423  $message->htmlContent = $commonMessage;
424  $url = Yii::app()->createAbsoluteUrl('gameRewards/default/details/',
425  array('id' => $gameReward->id));
426  $message->htmlContent .= "<br/>" . ZurmoHtml::link(Zurmo::t('Core', 'Click Here'), $url,
427  array('target' => '_blank'));
428  $message->textContent = $commonMessage . "\n";
429  $message->textContent .= Zurmo::t('GameRewardsModule', 'Use this link to get more details: {url}',
430  array('{url}' => ShortUrlUtil::createShortUrl($url)));
432  $rules->addUser($gameReward->owner);
433  NotificationsUtil::submit($message, $rules);
434 
435  $message = Zurmo::t('GameRewardsModule', '{name} has been redeemed.', array('{name}' => strval($gameReward)));
436  echo CJSON::encode(array('message' => $message));
437  Yii::app()->end(0, false);
438  }
439 
440  protected function resolveFilteredByMetadataBeforeMakingDataProvider($searchForm, & $metadata)
441  {
442  if ($searchForm->filteredBy == GameRewardsSearchForm::FILTERED_BY_CAN_REDEEM)
443  {
444  $gameCoin = GameCoin::resolveByPerson(Yii::app()->user->userModel);
445  $totalCoinsForUser = (int)$gameCoin->value;
446  $clauseNumber = count($metadata['clauses']) + 1;
447  $metadata['clauses'][$clauseNumber] = array('attributeName' => 'cost',
448  'operatorType' => 'lessThanOrEqualTo',
449  'value' => $totalCoinsForUser);
450  if ($metadata['structure'] == '')
451  {
452  $metadata['structure'] = $clauseNumber;
453  }
454  else
455  {
456  $metadata['structure'] .= ' AND ' . $clauseNumber;
457  }
458  }
459  }
460  }
461 ?>
static copy(RedBeanModel $model, RedBeanModel $copyToModel)
static getTranslationParamsForAllModules()
Definition: LabelUtil.php:75
processMassEditProgressSave($modelClassName, $pageSize, $title, $dataProvider=null)
static resolveAccessCanCurrentUserDeleteModel(RedBeanModel $model, $fromAjax=false)
static resolveByPerson(Item $person)
Definition: GameCoin.php:60
makeMassDeleteView($model, $activeAttributes, $selectedRecordCount, $title, $massDeleteViewClassName= 'MassDeleteView', $useModuleClassNameForItemLabel=true)
Definition: Controller.php:296
resolveActiveAttributesFromMassDeletePost()
Definition: Controller.php:270
attemptToSaveModelFromPost($model, $redirectUrlParams=null, $redirect=true, $returnOnValidate=false)
static resolveAccessCanCurrentUserReadModel(RedBeanModel $model, $fromAjax=false)
processMassEdit($pageSize, $activeAttributes, $selectedRecordCount, $pageViewClassName, $listModel, $title, $dataProvider=null)
static getById($id, $modelClassName=null)
static setAjaxModeAndRenderModalSearchList(CController $controller, $modalListLinkProvider, $stateMetadataAdapterClassName=null)
static resolveBreadCrumbViewForDetailsControllerAction(CController $controller, $stickySearchKey, RedBeanModel $model)
static submit(NotificationMessage $message, NotificationRules $rules)
processMassDelete($pageSize, $activeAttributes, $selectedRecordCount, $pageViewClassName, $listModel, $title, $dataProvider=null, $redirectUrl=null)
static resolveAccessCanCurrentUserWriteModel(RedBeanModel $model, $fromAjax=false)
Generated on Sat Jul 11 2020 07:10:26
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.