Beispiel #1
0
 public function postProcessing(&$data)
 {
     for ($i = 0; $i < count($data); $i++) {
         Formatter::addAddressToUser($data[$i]['author']);
         $favourite = Favourite::model()->byUser($this->controller->identity->getId())->byModel(get_class(QaQuestion::model()), $data[$i]['id'])->find();
         $data[$i]['is_my_favourite'] = $favourite == null ? false : true;
     }
 }
Beispiel #2
0
 public function postProcessing(&$data)
 {
     for ($i = 0; $i < count($data); $i++) {
         if (in_array('blogPostsCount', $this->controller->getWithParameters(\User::model(), true))) {
             $count = count(Content::model()->findAllByAttributes(array('authorId' => $data[$i]['id'], 'originService' => 'oldBlog')));
             $data[$i]['blogPostsCount'] = $count;
         }
         $favourite = Favourite::model()->byUser($this->controller->identity->getId())->byModel(get_class(\User::model()), $data[$i]['id'])->find();
         $data[$i]['is_my_favourite'] = $favourite == null ? false : true;
         Formatter::addStatusToUser($data[$i]);
     }
 }
Beispiel #3
0
 public function postProcessing(&$data)
 {
     $getQuestionAuthor = in_array('question', $this->controller->getWithParameters(QaAnswer::model(), true));
     for ($i = 0; $i < count($data); $i++) {
         /**
          * @var QaAnswer $temp
          */
         $temp = QaAnswer::model()->findByPk($data[$i]['id']);
         if (!$temp->question) {
             $data[$i] = null;
             continue;
         }
         if ($getQuestionAuthor) {
             $questionAuthor = \User::model()->findByPk($data[$i]['question']['authorId']);
             Formatter::format($questionAuthor);
             $data[$i]['question']['author'] = $this->getController()->getFilteredAttributes($questionAuthor);
         }
         if ($temp->votesCount > 0) {
             $vote = QaAnswerVote::model()->byAnswer($temp->id)->user($this->controller->identity->getId())->find();
             $data[$i]['has_my_vote'] = $vote != null;
         } else {
             $data[$i]['has_my_vote'] = false;
         }
         $favourite = Favourite::model()->byUser($this->controller->identity->getId())->byModel(get_class(QaAnswer::model()), $data[$i]['id'])->find();
         $data[$i]['is_my_favourite'] = $favourite == null ? false : true;
     }
     $data = array_map(function ($item) {
         if ($item != null) {
             return $item;
         }
     }, $data);
     if ($question_id = \Yii::app()->request->getParam('question_id', null)) {
         $best = QaAnswer::model()->findByAttributes(array('questionId' => $question_id, 'isBest' => 1));
         if ($best) {
             $newData = array();
             $newData['answers'] = $data;
             Formatter::format($best);
             $newData['best'] = $this->getController()->getFilteredAttributes($best);
             if (in_array('author', $this->controller->getWithParameters(QaAnswer::model(), true))) {
                 $author = \User::model()->findByPk($best->authorId);
                 Formatter::format($author);
                 $newData['best']['author'] = $this->getController()->getFilteredAttributes($author);
             }
             $data = $newData;
         }
     }
 }
Beispiel #4
0
 public function deleteFavourite()
 {
     $required = ['model_name' => true, 'model_id' => true];
     $params = $this->controller->getParams($required);
     if (!array_key_exists($params['model_name'], self::$modelAliases)) {
         throw new InvalidParamsApiException('ModelNameNotSupported');
     }
     $favourite = Favourite::model()->byUser($this->controller->identity->getId())->byModelName(self::$modelAliases[$params['model_name']])->byModelId($params['model_id'])->find();
     if (!$favourite) {
         throw new NotFoundApiException();
     }
     $favourite->detachBehavior('notificationBehavior');
     $favourite->detachBehavior('withRelated');
     if (!$favourite->delete()) {
         throw new ApiException($favourite->getErrors(), 500);
     }
     $this->controller->setMessage('Success');
 }