Example #1
0
 /**
  *  Load feed
  */
 protected function loadFeed()
 {
     $posts = PostModel::getNewsFeed();
     /*
      * Add a "url" helper attribute for linking to each post and category
      */
     $posts->each(function ($post) {
         $post->setUrl($this->postPage, $this->controller);
         $post->categories->each(function ($category) {
             $category->setUrl($this->categoryPage, $this->controller);
         });
     });
     CW::info(['NewsFeed' => $posts]);
     return $posts;
 }
Example #2
0
 protected function loadPost()
 {
     $slug = $this->property('slug');
     $post = PostModel::isPublished()->where('slug', $slug)->with(['cover'])->first();
     /*
      * Add a "url" helper attribute for linking to each category
      */
     if ($post && $post->categories->count()) {
         $post->categories->each(function ($category) {
             $category->setUrl($this->categoryPage, $this->controller);
         });
     }
     CW::info(['News' => $post]);
     return $post;
 }
Example #3
0
 protected function listPosts()
 {
     $categories = $this->category ? $this->category->id : null;
     /*
      * List all the posts, eager load their categories
      */
     $posts = PostModel::with(['categories', 'cover'])->listFrontEnd(['page' => $this->property('pageNumber'), 'perPage' => $this->property('postsPerPage'), 'categories' => $categories, 'sort' => 'published_at desc']);
     /*
      * Add a "url" helper attribute for linking to each post and category
      */
     $posts->each(function ($post) {
         $post->setUrl($this->postPage, $this->controller);
         $post->categories->each(function ($category) {
             $category->setUrl($this->categoryPage, $this->controller);
         });
     });
     CW::info(['NewsArchive' => $posts]);
     return $posts;
 }
Example #4
0
 public function boot()
 {
     $alias = AliasLoader::getInstance();
     $alias->alias('Carbon', '\\Carbon\\Carbon');
     $alias->alias('CW', '\\Clockwork\\Support\\Laravel\\Facade');
     /*
      * Register menu items for the RainLab.Pages plugin
      */
     Event::listen('pages.menuitem.listTypes', function () {
         return ['newsarchive' => 'Архив новостей'];
     });
     Event::listen('pages.menuitem.getTypeInfo', function ($type) {
         if ($type == 'newsarchive') {
             return PostModel::getMenuTypeInfo($type);
         }
     });
     Event::listen('pages.menuitem.resolveItem', function ($type, $item, $url, $theme) {
         if ($type == 'newsarchive') {
             return PostModel::resolveMenuItem($item, $url, $theme);
         }
     });
 }