protected static function resolveUpdateScoreTypeByModel($model) { if ($model->category->value == Meeting::getCategoryCallValue()) { return static::SCORE_TYPE_UPDATE_CALL; } return parent::resolveUpdateScoreTypeByModel($model); }
public static function resolveSaveGameScoreAndAddPointsByCategory($gameScore, $category) { assert('is_string($category)'); $saved = $gameScore->save(); if (!$saved) { throw new FailedToSaveModelException(); } GamePointUtil::addPointsByPointData(Yii::app()->user->userModel, GamificationRules::getPointTypeAndValueDataByCategory($category)); }
/** * (non-PHPdoc) * @see GamificationRules::scoreOnSaveModel() */ public function scoreOnSaveModel(CEvent $event) { parent::scoreOnSaveModel($event); $scoreType = static::SCORE_TYPE_WIN_AGREEMENT; $category = static::SCORE_CATEGORY_WIN_AGREEMENT; $gameScore = GameScore::resolveToGetByTypeAndPerson($scoreType, Yii::app()->user->userModel); $gameScore->addValue(); $saved = $gameScore->save(); if (!$saved) { throw new FailedToSaveModelException(); } GamePointUtil::addPointsByPointData(Yii::app()->user->userModel, static::getPointTypeAndValueDataByCategory($category)); }
public function scoreOnSaveModel(CEvent $event) { if (Yii::app()->gameHelper->isScoringModelsOnSaveMuted()) { return; } if (!LeadsUtil::isStateALead($event->sender->state) && array_key_exists('state', $event->sender->originalAttributeValues) && $event->sender->originalAttributeValues['state'][1] > 0 && LeadsUtil::isStateALeadByStateName($event->sender->originalAttributeValues['state'][2])) { $this->scoreOnSaveWhereLeadIsConverted($event); } elseif (LeadsUtil::isStateALead($event->sender->state)) { $this->scoreOnSaveWhereStateIsLead($event); } else { parent::scoreOnSaveModel($event); } }
/** * (non-PHPdoc) * @see GamificationRules::scoreOnSaveModel() */ public function scoreOnSaveModel(CEvent $event) { parent::scoreOnSaveModel($event); if (array_key_exists('value', $event->sender->stage->originalAttributeValues) && $event->sender->stage->value == Opportunity::getStageClosedWonValue()) { $scoreType = static::SCORE_TYPE_WIN_OPPORTUNITY; $category = static::SCORE_CATEGORY_WIN_OPPORTUNITY; $gameScore = GameScore::resolveToGetByTypeAndPerson($scoreType, Yii::app()->user->userModel); $gameScore->addValue(); $saved = $gameScore->save(); if (!$saved) { throw new FailedToSaveModelException(); } GamePointUtil::addPointsByPointData(Yii::app()->user->userModel, static::getPointTypeAndValueDataByCategory($category)); } }
/** * (non-PHPdoc) * @see GamificationRules::scoreOnSaveModel() */ public function scoreOnSaveModel(CEvent $event) { parent::scoreOnSaveModel($event); //Is the Mission being taken by a user, when previously available. if (array_key_exists('status', $event->sender->originalAttributeValues) && $event->sender->originalAttributeValues['status'] == Mission::STATUS_AVAILABLE && $event->sender->status == Mission::STATUS_TAKEN) { $scoreType = static::SCORE_TYPE_TAKE_MISSION; $category = static::SCORE_CATEGORY_TAKE_MISSION; $gameScore = GameScore::resolveToGetByTypeAndPerson($scoreType, $event->sender->takenByUser); $gameScore->addValue(); $saved = $gameScore->save(); if (!$saved) { throw new FailedToSaveModelException(); } GamePointUtil::addPointsByPointData(Yii::app()->user->userModel, static::getPointTypeAndValueDataByCategory($category)); } elseif (array_key_exists('status', $event->sender->originalAttributeValues) && $event->sender->originalAttributeValues['status'] == Mission::STATUS_TAKEN && $event->sender->status == Mission::STATUS_COMPLETED) { $scoreType = static::SCORE_TYPE_COMPLETE_MISSION; $category = static::SCORE_CATEGORY_COMPLETE_MISSION; $gameScore = GameScore::resolveToGetByTypeAndPerson($scoreType, $event->sender->takenByUser); $gameScore->addValue(); $saved = $gameScore->save(); if (!$saved) { throw new FailedToSaveModelException(); } GamePointUtil::addPointsByPointData(Yii::app()->user->userModel, static::getPointTypeAndValueDataByCategory($category)); } elseif (array_key_exists('status', $event->sender->originalAttributeValues) && $event->sender->originalAttributeValues['status'] == Mission::STATUS_COMPLETED && $event->sender->status == Mission::STATUS_ACCEPTED) { $scoreType = static::SCORE_TYPE_ACCEPTED_MISSION; $category = static::SCORE_CATEGORY_ACCEPTED_MISSION; $gameScore = GameScore::resolveToGetByTypeAndPerson($scoreType, $event->sender->takenByUser); $gameScore->addValue(); $saved = $gameScore->save(); if (!$saved) { throw new FailedToSaveModelException(); } GamePointUtil::addPointsByPointData(Yii::app()->user->userModel, static::getPointTypeAndValueDataByCategory($category)); } }
/** * @param string $modelClassName */ public function attachScoringEventsByModelClassName($modelClassName) { assert('is_string($modelClassName)'); parent::attachScoringEventsByModelClassName($modelClassName); $modelClassName::model()->attachEventHandler('onAfterSave', array($this, 'scoreCompletedOnTime')); }
/** * @depends testScoreOnImportModels */ public function testGetPointTypeAndValueDataByCategory() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $pointTypeAndValueData = GamificationRules::getPointTypeAndValueDataByCategory('Search'); $this->assertEquals(array('UserAdoption' => 5), $pointTypeAndValueData); }