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)); }
/** * (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)); } }
public function testGetUserLeaderboardData() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $pointTypeAndValueData = array('some type' => 400); GamePointUtil::addPointsByPointData(Yii::app()->user->userModel, $pointTypeAndValueData); Yii::app()->gameHelper->processDeferredPoints(); $data = GamePointUtil::getUserLeaderboardData(GamePointUtil::LEADERBOARD_TYPE_WEEKLY); $this->assertTrue(Yii::app()->gameHelper->enabled); //test to see if enabled when running all tests $this->assertTrue(count($data) > 0); $data = GamePointUtil::getUserLeaderboardData(GamePointUtil::LEADERBOARD_TYPE_MONTHLY); $this->assertTrue(count($data) > 0); $data = GamePointUtil::getUserLeaderboardData(GamePointUtil::LEADERBOARD_TYPE_OVERALL); $this->assertTrue(count($data) > 0); }
/** * @param CEvent $event */ public function scoreCompletedOnTime(CEvent $event) { $model = $event->sender; assert('$model instanceof Item'); if (!$model->getIsNewModel() && array_key_exists('completed', $model->originalAttributeValues) && $model->completed == true && $model->dueDateTime != null) { $completedTimestamp = DateTimeUtil::convertDbFormatDateTimeToTimestamp($model->completedDateTime); $dueTimestamp = DateTimeUtil::convertDbFormatDateTimeToTimestamp($model->dueDateTime); if ($completedTimestamp <= $dueTimestamp) { $scoreType = static::SCORE_TYPE_COMPLETED_TASK_ON_TIME; $category = static::SCORE_CATEGORY_TIME_SENSITIVE_ACTION; $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 testGetUserLeaderboardData() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $pointTypeAndValueData = array('some type' => 400); GamePointUtil::addPointsByPointData(Yii::app()->user->userModel, $pointTypeAndValueData); Yii::app()->gameHelper->processDeferredPoints(); $data = GamePointUtil::getUserLeaderboardData(GamePointUtil::LEADERBOARD_TYPE_WEEKLY); $this->assertTrue(Yii::app()->gameHelper->enabled); //test to see if enabled when running all tests $this->assertTrue(count($data) > 0); $data = GamePointUtil::getUserLeaderboardData(GamePointUtil::LEADERBOARD_TYPE_MONTHLY); $this->assertTrue(count($data) > 0); //Now test with new user, calling to that specific user $sally = UserTestHelper::createBasicUser('sally'); $data = GamePointUtil::getUserLeaderboardData(GamePointUtil::LEADERBOARD_TYPE_OVERALL, 1, null, null, $sally); $this->assertTrue(count($data) == 0); $data = GamePointUtil::getUserLeaderboardData(GamePointUtil::LEADERBOARD_TYPE_WEEKLY, 1, null, null, $sally); $this->assertTrue(count($data) == 0); $data = GamePointUtil::getUserLeaderboardData(GamePointUtil::LEADERBOARD_TYPE_MONTHLY, 1, null, null, $sally); $this->assertTrue(count($data) == 0); $data = GamePointUtil::getUserLeaderboardData(GamePointUtil::LEADERBOARD_TYPE_OVERALL, 1, null, null, $sally); $this->assertTrue(count($data) == 0); }
/** * (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 static function scoreOnImportModels($modelClassName) { assert('is_string($modelClassName)'); $scoreType = 'Import' . $modelClassName; $category = static::SCORE_CATEGORY_IMPORT; $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)); }
/** * test for checking hideFromLeaderboard attribute */ public function testHideFromLeaderboardOnUserSave() { $user = new User(); $user->username = '******'; $user->title->value = 'Mr.'; $user->firstName = 'My'; $user->lastName = 'leaderboard'; $user->hideFromLeaderboard = true; $user->setPassword('myuser'); $this->assertTrue($user->save()); unset($user); $user = User::getByUsername('leaderboard'); Yii::app()->user->userModel = $user; $pointTypeAndValueData = array('some type' => 400); GamePointUtil::addPointsByPointData(Yii::app()->user->userModel, $pointTypeAndValueData); Yii::app()->gameHelper->processDeferredPoints(); $user = User::getByUsername('leaderboard'); $this->assertEquals(1, $user->hideFromLeaderboard); unset($user); $userSet = GamePointUtil::getUserLeaderboardData(GamePointUtil::LEADERBOARD_TYPE_OVERALL); $this->assertEquals(0, count($userSet)); $user = User::getByUsername('leaderboard'); $user->hideFromLeaderboard = false; $this->assertTrue($user->save()); unset($user); $user = User::getByUsername('leaderboard'); $this->assertEquals(0, $user->hideFromLeaderboard); unset($user); $userSet = GamePointUtil::getUserLeaderboardData(GamePointUtil::LEADERBOARD_TYPE_OVERALL); $this->assertTrue(count($userSet) > 0); }
protected function scoreOnSaveWhereStateIsLead(CEvent $event) { $model = $event->sender; assert('$model instanceof Item'); if ($model->getIsNewModel()) { $scoreType = static::SCORE_TYPE_CREATE_LEAD; $category = static::SCORE_CATEGORY_CREATE_LEAD; $gameScore = GameScore::resolveToGetByTypeAndPerson($scoreType, Yii::app()->user->userModel); } else { $scoreType = static::SCORE_TYPE_UPDATE_LEAD; $category = static::SCORE_CATEGORY_UPDATE_LEAD; $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)); }
/** * Override to handle 'draft' email template creation * @param CEvent $event * @throws FailedToSaveModelException */ public function scoreOnSaveModel(CEvent $event) { $model = $event->sender; assert('$model instanceof Item'); if (Yii::app()->gameHelper->isScoringModelsOnSaveMuted()) { return; } if ($model->getIsNewModel()) { if (!$model->isDraft) { $scoreType = static::resolveCreateScoreTypeByModel($model); $category = static::SCORE_CATEGORY_CREATE_MODEL; $gameScore = GameScore::resolveToGetByTypeAndPerson($scoreType, Yii::app()->user->userModel); } else { return; } } elseif (!$this->scoreOnUpdate) { return; } else { if (array_key_exists('isDraft', $event->sender->originalAttributeValues) && $event->sender->isDraft) { //Considered a new 'email template' $scoreType = static::resolveCreateScoreTypeByModel($model); $category = static::SCORE_CATEGORY_CREATE_MODEL; $gameScore = GameScore::resolveToGetByTypeAndPerson($scoreType, Yii::app()->user->userModel); } else { $scoreType = static::resolveUpdateScoreTypeByModel($model); $category = static::SCORE_CATEGORY_UPDATE_MODEL; $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)); }