Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
GamificationRules.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 
41  {
46  const SCORE_CATEGORY_CREATE_MODEL = 'CreateModel';
47 
52  const SCORE_CATEGORY_UPDATE_MODEL = 'UpdateModel';
53 
58  const SCORE_CATEGORY_LOGIN_USER = 'LoginUser';
59 
64  const SCORE_CATEGORY_MASS_EDIT = 'MassEdit';
65 
70  const SCORE_CATEGORY_MASS_DELETE = 'MassDelete';
71 
76  const SCORE_CATEGORY_SEARCH = 'Search';
77 
82  const SCORE_CATEGORY_IMPORT = 'Import';
83 
89  const SCORE_CATEGORY_TIME_SENSITIVE_ACTION = 'TimeSensitiveAction';
90 
95  protected $scoreOnUpdate = true;
96 
101  public function attachScoringEventsByModelClassName($modelClassName)
102  {
103  assert('is_string($modelClassName)');
104  $modelClassName::model()->attachEventHandler('onAfterSave', array($this, 'scoreOnSaveModel'));
105  }
106 
111  public function scoreOnSaveModel(CEvent $event)
112  {
113  $model = $event->sender;
114  assert('$model instanceof Item');
115  if (Yii::app()->gameHelper->isScoringModelsOnSaveMuted())
116  {
117  return;
118  }
119  if ($model->getIsNewModel())
120  {
121  $scoreType = static::resolveCreateScoreTypeByModel($model);
122  $category = static::SCORE_CATEGORY_CREATE_MODEL;
123  $gameScore = GameScore::resolveToGetByTypeAndPerson($scoreType, Yii::app()->user->userModel);
124  }
125  elseif (!$this->scoreOnUpdate)
126  {
127  return;
128  }
129  else
130  {
131  $scoreType = static::resolveUpdateScoreTypeByModel($model);
132  $category = static::SCORE_CATEGORY_UPDATE_MODEL;
133  $gameScore = GameScore::resolveToGetByTypeAndPerson($scoreType, Yii::app()->user->userModel);
134  }
135  $gameScore->addValue();
136  $saved = $gameScore->save();
137  if (!$saved)
138  {
139  throw new FailedToSaveModelException();
140  }
141  GamePointUtil::addPointsByPointData(Yii::app()->user->userModel,
142  static::getPointTypeAndValueDataByCategory($category));
143  }
144 
145  protected static function resolveCreateScoreTypeByModel($model)
146  {
147  return 'Create' . get_class($model);
148  }
149 
150  protected static function resolveUpdateScoreTypeByModel($model)
151  {
152  return 'Update' . get_class($model);
153  }
154 
161  public static function getPointTypeAndValueDataByCategory($category)
162  {
163  assert('is_string($category)');
164  $methodName = 'getPointTypesAndValuesFor' . $category;
165  if (method_exists(get_called_class(), $methodName))
166  {
167  return static::$methodName();
168  }
169  else
170  {
171  throw new NotImplementedException();
172  }
173  }
174 
178  public static function getPointTypesAndValuesForCreateModel()
179  {
180  return array(GamePoint::TYPE_USER_ADOPTION => 10);
181  }
182 
186  public static function getPointTypesAndValuesForUpdateModel()
187  {
188  return array(GamePoint::TYPE_USER_ADOPTION => 10);
189  }
190 
194  public static function getPointTypesAndValuesForLoginUser()
195  {
196  return array(GamePoint::TYPE_USER_ADOPTION => 10);
197  }
198 
202  public static function getPointTypesAndValuesForSearch()
203  {
204  return array(GamePoint::TYPE_USER_ADOPTION => 5);
205  }
206 
210  public static function getPointTypesAndValuesForMassEdit()
211  {
212  return array(GamePoint::TYPE_USER_ADOPTION => 15);
213  }
214 
218  public static function getPointTypesAndValuesForImport()
219  {
220  return array(GamePoint::TYPE_USER_ADOPTION => 25);
221  }
222 
227  {
228  return array(GamePoint::TYPE_USER_ADOPTION => 10);
229  }
230 
234  public static function scoreOnSearchModels($modelClassName)
235  {
236  assert('is_string($modelClassName)');
237  $scoreType = 'Search' . $modelClassName;
238  $category = static::SCORE_CATEGORY_SEARCH;
239  $gameScore = GameScore::resolveToGetByTypeAndPerson($scoreType, Yii::app()->user->userModel);
240  $gameScore->addValue();
241  $saved = $gameScore->save();
242  if (!$saved)
243  {
244  throw new FailedToSaveModelException();
245  }
246  GamePointUtil::addPointsByPointData(Yii::app()->user->userModel,
247  static::getPointTypeAndValueDataByCategory($category));
248  }
249 
253  public static function scoreOnMassEditModels($modelClassName)
254  {
255  assert('is_string($modelClassName)');
256  $scoreType = 'MassEdit' . $modelClassName;
257  $category = static::SCORE_CATEGORY_MASS_EDIT;
258  $gameScore = GameScore::resolveToGetByTypeAndPerson($scoreType, Yii::app()->user->userModel);
259  $gameScore->addValue();
260  $saved = $gameScore->save();
261  if (!$saved)
262  {
263  throw new FailedToSaveModelException();
264  }
265  GamePointUtil::addPointsByPointData(Yii::app()->user->userModel,
266  static::getPointTypeAndValueDataByCategory($category));
267  }
268 
272  public static function scoreOnMassDeleteModels($modelClassName)
273  {
274  assert('is_string($modelClassName)');
275  $scoreType = 'MassDelete' . $modelClassName;
276  $category = static::SCORE_CATEGORY_MASS_DELETE;
277  $gameScore = GameScore::resolveToGetByTypeAndPerson($scoreType, Yii::app()->user->userModel);
278  $gameScore->addValue();
279  $saved = $gameScore->save();
280  if (!$saved)
281  {
282  throw new FailedToSaveModelException();
283  }
284  GamePointUtil::addPointsByPointData(Yii::app()->user->userModel,
285  static::getPointTypeAndValueDataByCategory($category));
286  }
287 
291  public static function scoreOnImportModels($modelClassName)
292  {
293  assert('is_string($modelClassName)');
294  $scoreType = 'Import' . $modelClassName;
295  $category = static::SCORE_CATEGORY_IMPORT;
296  $gameScore = GameScore::resolveToGetByTypeAndPerson($scoreType, Yii::app()->user->userModel);
297  $gameScore->addValue();
298  $saved = $gameScore->save();
299  if (!$saved)
300  {
301  throw new FailedToSaveModelException();
302  }
303  GamePointUtil::addPointsByPointData(Yii::app()->user->userModel,
304  static::getPointTypeAndValueDataByCategory($category));
305  }
306  }
307 ?>
static getPointTypesAndValuesForMassEdit()
static scoreOnImportModels($modelClassName)
static resolveToGetByTypeAndPerson($type, Item $person)
Definition: GameScore.php:59
attachScoringEventsByModelClassName($modelClassName)
static getPointTypeAndValueDataByCategory($category)
scoreOnSaveModel(CEvent $event)
static addPointsByPointData(User $user, $pointTypeAndValueData)
static getPointTypesAndValuesForTimeSensitiveAction()
static scoreOnSearchModels($modelClassName)
static getPointTypesAndValuesForImport()
static getPointTypesAndValuesForSearch()
static getPointTypesAndValuesForCreateModel()
static scoreOnMassEditModels($modelClassName)
static getPointTypesAndValuesForUpdateModel()
static scoreOnMassDeleteModels($modelClassName)
static getPointTypesAndValuesForLoginUser()
Generated on Wed Jul 8 2020 07:10:34
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.