page = $params['page']; $this->controller = $params['controller']; $this->commentsAnchor = $params['comments_anchor']; } /** * Load the news * * @param int $maxItems * * @return mixed */ public function loadData($maxItems = self::MAX_NO_ITEMS) { $posts = null; if (!empty($this->data)) { return $this->data; } $model = new Posts(); $locale = request('locale'); $posts = $model->listFrontEnd([ 'sort' => 'published_at desc', 'perPage' => $maxItems, 'locale' => in_array($locale,['ru','en','tk'])? $locale : 'en' ]); foreach ($posts as $post) { $post->setUrl($this->page, $this->controller); // $post->comments_url = "{$post->url}/#{$this->commentsAnchor}"; $post->feed_content = true === $this->displayFullContent ? $post->content : $post->introductory; } return $this->data = $posts; } /** * Retrieve posts from cache or load them and then return them * * @param int $maxItems * * @return mixed */ public function getData($maxItems = self::MAX_NO_ITEMS) { if (null !== $this->data && !empty($this->data)) { return $this->data; } $this->data = $this->loadData($maxItems); return $this->data; } /** * Set if we display the full post content or a summary * * @param bool $fullContent */ public function setDisplayFullContent($fullContent = true) { $this->displayFullContent = $fullContent; } }