/** * Build content data to model properties * @param $records * @throws ForbiddenException * @throws NotFoundException */ private function buildContent($records) { $nullItems = 0; foreach ($records as $row) { /** @var Content $row */ // check title length on current language locale $localeTitle = $row->getLocaled('title'); if (Str::likeEmpty($localeTitle)) { ++$nullItems; continue; } // get snippet from full text for current locale $text = Text::snippet($row->getLocaled('text')); $itemPath = $this->categories[$row->category_id]->path; if (!Str::likeEmpty($itemPath)) { $itemPath .= '/'; } $itemPath .= $row->path; // prepare tags data $tags = $row->getLocaled('meta_keywords'); if (!Str::likeEmpty($tags)) { $tags = explode(',', $tags); } else { $tags = null; } $owner = App::$User->identity($row->author_id); // make a fake if user is not exist over id if ($owner === null) { $owner = new User(); } // check if current user can rate item $ignoredRate = App::$Session->get('content.rate.ignore'); $canRate = true; if (Obj::isArray($ignoredRate) && Arr::in((string) $row->id, $ignoredRate)) { $canRate = false; } if (!App::$User->isAuth()) { $canRate = false; } elseif ($owner->getId() === App::$User->identity()->getId()) { // own item $canRate = false; } // build result array $this->items[] = ['id' => $row->id, 'title' => $localeTitle, 'text' => $text, 'date' => Date::humanize($row->created_at), 'updated' => $row->updated_at, 'author' => $owner, 'poster' => $row->getPosterUri(), 'thumb' => $row->getPosterThumbUri(), 'thumbSize' => File::size($row->getPosterThumbUri()), 'views' => (int) $row->views, 'rating' => (int) $row->rating, 'canRate' => $canRate, 'category' => $this->categories[$row->category_id], 'uri' => '/content/read/' . $itemPath, 'tags' => $tags]; } if ($nullItems === $this->_contentCount) { throw new NotFoundException(__('Content is not founded')); } }