コード例 #1
0
ファイル: QuestsAction.php プロジェクト: JimmDiGriz/HGApi
 private function complete()
 {
     $required = array('social_service' => true);
     $params = $this->controller->getParams($required);
     /**
      * @var Quest[] $socialQuests
      */
     $socialQuests = Quest::model()->byUser($this->controller->identity->getId())->byType(QuestTypes::POST_TO_WALL)->byModel((new \ReflectionClass(ContestManager::getCurrentActive()))->getShortName(), ContestManager::getCurrentActive()->id)->findAll();
     if (!in_array($params['social_service'], array('vk', 'ok', 'fb'))) {
         throw new InvalidParamsApiException();
     }
     /**
      * @var CommentatorsContestParticipant $participant
      */
     $participant = CommentatorsContestParticipant::model()->byContest(ContestManager::getCurrentActive()->id)->byUser($this->controller->identity->getId())->find();
     foreach ($socialQuests as $quest) {
         if (\CJSON::decode($quest->settings)['social_service'] == $params['social_service']) {
             $quest->complete();
             $this->controller->data = $quest;
             $participant->score += 25;
             $participant->update(array('score'));
             break;
         }
     }
     if (!$this->controller->data) {
         throw new NotFoundApiException();
     }
 }
コード例 #2
0
ファイル: ContestAction.php プロジェクト: JimmDiGriz/HGApi
 private function postSettings()
 {
     $required = array('community_filter' => true);
     $params = $this->controller->getParams($required);
     $clubIds = explode(',', $params['community_filter']);
     foreach ($clubIds as $clubId) {
         if (!\CommunityClub::model()->findByPk($clubId)) {
             throw new InvalidParamsApiException("Club with id {$clubId} not found.");
         }
     }
     /**
      * @var CommentatorsContestParticipant $participant
      */
     $participant = CommentatorsContestParticipant::model()->byContest(ContestManager::getCurrentActive()->id)->byUser($this->controller->identity->getId())->find();
     $participant->settings = \CJSON::encode($params);
     $participant->update(array('settings'));
     $this->controller->data = $participant;
 }