コード例 #1
0
 public function testGetUserRankingData()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $data = GamePointUtil::getUserRankingData($super);
     $this->assertEquals(3, count($data));
 }
コード例 #2
0
 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));
 }
コード例 #3
0
 /**
  * (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));
 }
コード例 #4
0
 /**
  * (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));
     }
 }
コード例 #5
0
 public function actionLeaderboard($type = null)
 {
     if ($type == null) {
         $type = GamePointUtil::LEADERBOARD_TYPE_WEEKLY;
     }
     if ($type == GamePointUtil::LEADERBOARD_TYPE_WEEKLY) {
         $activeActionElementType = 'LeaderboardWeeklyLink';
     } elseif ($type == GamePointUtil::LEADERBOARD_TYPE_MONTHLY) {
         $activeActionElementType = 'LeaderboardMonthlyLink';
     } elseif ($type == GamePointUtil::LEADERBOARD_TYPE_OVERALL) {
         $activeActionElementType = 'LeaderboardOverallLink';
     } else {
         throw new NotSupportedException();
     }
     $view = new TitleBarAndLeaderboardView($this->getId(), $this->getModule()->getId(), GamePointUtil::getUserLeaderboardData($type), $activeActionElementType);
     $view = new LeaderboardPageView(ZurmoDefaultViewUtil::makeStandardViewForCurrentUser($this, $view));
     echo $view->render();
 }
コード例 #6
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));
         }
     }
 }
コード例 #7
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));
     }
 }
コード例 #8
0
 /**
  * @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));
 }
コード例 #9
0
 public function actionGameDashboard($id)
 {
     $user = User::getById(intval($id));
     UserAccessUtil::resolveAccessingASystemUser($user);
     $title = Zurmo::t('ZurmoModule', 'Dashboard');
     $badgeData = GameBadge::getAllByPersonIndexedByType($user);
     $generalLevelData = GameLevelUtil::getStatisticsDataForAGivenLevelType($user, GameLevel::TYPE_GENERAL);
     $rankingData = GamePointUtil::getUserRankingData($user);
     $statisticsData = GameLevelUtil::getUserStatisticsData($user);
     $collectionData = GameCollection::resolvePersonAndAvailableTypes($user, GameCollection::getAvailableTypes());
     $dashboardView = new UserGameDashboardView($this, $user, $generalLevelData, $badgeData, $rankingData, $statisticsData, $collectionData);
     $view = new AjaxPageView($dashboardView);
     echo $view->render();
 }
コード例 #10
0
 /**
  * @param string $type
  * @param null|int $offset
  * @param null|int $count
  * @return array
  */
 public static function getUserLeaderboardData($type, $offset = null, $count = null)
 {
     assert('is_string($type)');
     assert('$offset  === null || is_integer($offset)  && $offset  >= 0');
     assert('$count   === null || is_integer($count)   && $count   >= 1');
     $leaderboardData = GamePointUtil::getUserLeaderboardData($type, $offset + 1, $offset, $count);
     $resolvedLeaderboardData = array();
     foreach ($leaderboardData as $userId => $data) {
         $data['userId'] = $userId;
         $resolvedLeaderboardData[] = $data;
     }
     return $resolvedLeaderboardData;
 }
コード例 #11
0
ファイル: UserTest.php プロジェクト: youprofit/Zurmo
 /**
  * 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);
 }
コード例 #12
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));
 }
コード例 #13
0
ファイル: DefaultController.php プロジェクト: youprofit/Zurmo
 public function actionDetails($id)
 {
     $user = User::getById(intval($id));
     UserAccessUtil::resolveAccessingASystemUser($user);
     $title = Zurmo::t('UsersModule', 'Profile');
     $breadcrumbLinks = array(strval($user) => array('default/details', 'id' => $id), $title);
     AuditEvent::logAuditEvent('ZurmoModule', ZurmoModule::AUDIT_EVENT_ITEM_VIEWED, array(strval($user), 'UsersModule'), $user);
     $params = array('controllerId' => $this->getId(), 'relationModuleId' => $this->getModule()->getId(), 'relationModel' => $user, 'rankingData' => GamePointUtil::getUserRankingData($user), 'statisticsData' => GameLevelUtil::getUserStatisticsData($user), 'badgeData' => GameBadge::getAllByPersonIndexedByType($user));
     $detailsAndRelationsView = new UserDetailsAndRelationsView($this->getId(), $this->getModule()->getId(), $params);
     $view = new UsersPageView($this->resolveZurmoDefaultOrAdminView($detailsAndRelationsView, $breadcrumbLinks, 'UserBreadCrumbView'));
     echo $view->render();
 }
コード例 #14
0
 /**
  * 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));
 }