public function postProcessing(&$data) { include_once \Yii::getPathOfAlias('site.frontend.vendor.simplehtmldom_1_5') . DIRECTORY_SEPARATOR . 'simple_html_dom.php'; for ($i = 0; $i < count($data); $i++) { $data[$i]['purifiedHtml'] = Comment::model()->findByPk($data[$i]['id'])->purified->text; $data[$i]['text'] = HtmlParser::handleHtml($data[$i]['text'], $data[$i])->outertext; $data[$i]['purifiedHtml'] = HtmlParser::handleHtml($data[$i]['purifiedHtml'], $data[$i])->outertext; if (in_array('answers', $this->controller->getWithParameters(Comment::model(), true))) { $answers = Comment::model()->findAll(array('condition' => 'root_id = ' . $data[$i]['id'] . ' and id != ' . $data[$i]['id'])); if ($answers) { $data[$i]['answers'] = array(); foreach ($answers as $answer) { Formatter::format($answer); $temp = $answer->getAttributes(); $temp['text'] = HtmlParser::handleHtml($temp['text'], $temp)->outertext; Formatter::formatUser($answer->author); Formatter::formatCommon($answer->author); $temp['author'] = $answer->author->getAttributes(Filter::getFilter($answer->author->getAttributes(), get_class($answer->author))); //Formatter::format($temp); $data[$i]['answers'][] = $temp; } } } } }
public function getRating() { $required = array('user_id' => false, 'start_date' => false, 'end_date' => false, 'category_id' => true); $this->params = $this->controller->getParams($required); if (isset($this->params['start_date']) && isset($this->params['end_date'])) { $model = QaRatingHistory::model()->between($this->params['start_date'], $this->params['end_date']); $this->history = true; } else { $model = QaRating::model(); } $model->byCategory($this->params['category_id']); if (isset($this->params['user_id'])) { $model->byUser($this->params['user_id']); } //temp if ($this->history) { $model->getDbCriteria()->select = $model->getTableAlias() . '.user_id, count(*) as points'; $model->getDbCriteria()->group = $model->getTableAlias() . '.user_id'; $model->getDbCriteria()->order = 'points DESC'; $result = array(); $records = $model->findAll($this->controller->getPaginationParams()); if (count($records) == 0) { throw new NotFoundApiException(); } foreach ($records as $record) { $user = \User::model()->findByPk($record->user_id); Formatter::format($user); $result[] = array('user_id' => (int) $record->user_id, 'total_count' => (int) $record->points, 'answers_count' => (int) QaRatingHistory::model()->byCategory($this->params['category_id'])->byUser($record->user_id)->between($this->params['start_date'], $this->params['end_date'])->byModel((new \ReflectionClass(QaAnswer::model()))->getShortName())->count(), 'votes_count' => (int) QaRatingHistory::model()->byCategory($this->params['category_id'])->byUser($record->user_id)->between($this->params['start_date'], $this->params['end_date'])->byModel((new \ReflectionClass(QaAnswerVote::model()))->getShortName())->count(), 'user' => $this->getController()->getFilteredAttributes($user)); } echo \CJSON::encode($result); die; } else { $this->controller->get($model, $this); } }
public function postProcessing(&$data) { $data[0]['token'] = $data[1]; $data = $data[0]; Formatter::addStatusToUser($data); Formatter::addSocialServicesToUser($data); }
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; } }
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]); } }
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; } } }
private function handleContacts(&$contacts) { for ($i = 0; $i < count($contacts); $i++) { /** * @var \User $user */ $user = \User::model()->findByPk($contacts[$i]['id']); if (!$user) { throw new NotFoundApiException('InvalidContact:UserNotFound'); } Formatter::formatUser($user); $contacts[$i]['avatar'] = $user->getAttributes()['avatarInfo']; $message = \MessagingMessage::model()->between($this->controller->identity->getId(), $user->id)->find(array('order' => \MessagingMessage::model()->getTableAlias() . ".created desc")); Formatter::formatCommon($message); $contacts[$i]['message'] = $message->getAttributes(); } }
public function postProcessing(&$data) { if ($this->controller->requestType != 'Param' || isset($data[0]['message'])) { return; } $params = $this->controller->getParams(array('read' => false, 'count' => false)); $fields = array('readEntities', 'unreadEntities'); if (isset($params['count'])) { $counter = 0; for ($i = 0; $i < count($data); $i++) { $counter += count($data[$i]['unreadEntities']); } $this->controller->setMessage($counter); return; } for ($i = 0; $i < count($data); $i++) { /** * @var \EMongoDocument $item */ foreach ($fields as $field) { if ($data[$i][$field] == null) { continue; } foreach ($data[$i][$field] as $key => $item) { $data[$i][$field][$key] = $item->getAttributes(); $user = \User::model()->findByPk($item->userId); Formatter::format($user); $data[$i][$field][$key]['user'] = $this->controller->getFilteredAttributes($user); } } } }
public static function addSocialServicesToUser(&$user) { $services = \UserSocialService::model()->findAllByAttributes(array('user_id' => $user['id'])); $user['social_services'] = array(); if ($services) { foreach ($services as $service) { Formatter::formatCommon($service); $user['social_services'][] = $service->getAttributes(); } } }
/** * Fill data field with array of user and token keys * In user key instance of user * In token key just created api token * * @param \User $user */ public function toAuthArray($user) { if ($user instanceof \User) { /** * @var UserApiToken $token */ $token = UserApiToken::model()->byAppId($this->getApplication()->_id->{'$id'})->findByPk($user->id . $this->getApplication()->_id); if (!$token) { //support old tokens where app_id is ObjectId $token = UserApiToken::model()->byAppId($this->getApplication()->_id)->findByPk($user->id . $this->getApplication()->_id); if (!$token) { $token = UserApiToken::model()->create($user, $this->getApplication()->_id->{'$id'}); } } Formatter::format($token); $user->refresh(); $this->data = array('user' => $user, 'token' => $token); } else { $this->setError('WrongAuthArrayParam', 500); } }
/** * HTML Format, Views Counter Increment * * @param $data */ public function postProcessing(&$data) { //\Yii::import('ext.SimpleHTMLDOM.SimpleHTMLDOM'); include_once \Yii::getPathOfAlias('site.frontend.vendor.simplehtmldom_1_5') . DIRECTORY_SEPARATOR . 'simple_html_dom.php'; $lastText = ''; $indexes = array(); //В форматер и отрефакторить. for ($i = 0; $i < count($data); $i++) { if ($data[$i]['originService'] == 'oldCommunity') { $data[$i]['subscribers'] = \UserClubSubscription::model()->getSubscribersCount(Content::model()->findByPk($data[$i]['id'])->club->id); } else { if ($data[$i]['originService'] == 'oldBlog') { $data[$i]['subscribers'] = (int) \UserBlogSubscription::model()->subscribersCount($data[$i]['authorId']); } else { $data[$i]['subscribers'] = 0; } } $temp = $data[$i]['html']; if ($i != 0) { //ApiLog::i($lastText . ' -------- ' . $temp); if ($lastText == $temp) { //ApiLog::i('DELETED'); //$data[$i] = null; $indexes[] = $i; continue; } } if (!$this->isOriginHtml) { $data[$i]['html'] = HtmlParser::handleHtml($data[$i]['html'], $data[$i])->outertext; if ($data[$i]['preview'] != '') { $data[$i]['preview'] = HtmlParser::handleHtml($data[$i]['preview'])->outertext; } $url = preg_replace("/http:\\/\\/www.*\\.ru/", "", $data[$i]['url']); $pageView = PageView::getModel($url); $data[$i]['views'] = $pageView->visits; if (isset($data[$i]['photoCollection'])) { $array = \CJSON::decode($data[$i]['photoCollection']); $collection = PhotoCollection::model()->findByPk($array['id']); if ($collection) { $data[$i]['photoCollection'] = $collection->getAttributes(); $attaches = PhotoAttach::model()->findAll(array('condition' => 'collection_id=' . $data[$i]['photoCollection']['id'], 'with' => array('photo'))); foreach ($attaches as $attach) { $temp = $attach->getAttributes(); $temp['photo'] = $attach->photo->getAttributes(); $temp['photo']['originalUrl'] = \Yii::app()->fs->getUrl($attach->photo->getFile()->getKey()); $data[$i]['photoCollection']['attaches'][] = $temp; } } } } //crutch for adding status info for. if ($data[$i]['originService'] == 'status') { $status = Status::model()->with('moodModel')->findByPk($data[$i]['originEntityId']); Formatter::formatCommon($status); $data[$i]['status'] = $status->getAttributes(); if ($status->moodModel) { Formatter::formatCommon($status->moodModel); $data[$i]['status']['moodModel'] = $status->moodModel->getAttributes(); } } $lastText = $temp; } for ($i = 0; $i < count($indexes); $i++) { unset($data[$indexes[$i]]); } $data = array_values($data); }