Exemplo n.º 1
0
 protected function loadArchive()
 {
     $this->page['min_date'] = BlogPost::min('published_at');
     if ($this->property('parent') == '') {
         return BlogPost::where('published', 1)->orderBy('published_at', 'desc')->get();
     } else {
         $parent = $this->property('parent');
         return BlogPost::where('parent', $parent)->where('published', 1)->orderBy('published_at', 'desc')->get();
     }
 }
 protected function updateEvent($data)
 {
     $post = BasePost::where('id', $data['event_id'])->first();
     if ($post->available == 0) {
         return false;
     } else {
         $post->decrement('available');
         $post->save();
         return true;
     }
 }
 public function getPost()
 {
     if ($this->post !== null) {
         return $this->post;
     }
     $this->post = PostModel::where('promoted', '1')->where('categories_id', 2)->first();
     if (is_null($this->post)) {
         return \Response::make($this->controller->run('404'), 404);
     } else {
         return $this->post;
     }
 }
 protected function loadPosts()
 {
     //\Log::info($this->parentPage);
     if ($this->parentPage != '') {
         $parent = $this->parentPage;
         $BlogPosts = BlogPost::where('parent', $parent);
     } else {
         $BlogPosts = new BlogPost();
     }
     $BlogPosts = $BlogPosts->isPublished();
     /*
      * Preset Fitlers
      * First we cycle through all possible preset filtering
      * @type - category,tag,author,date-time
      */
     if ($this->property('filter_type') == 'category') {
         $category_name = $this->property('filter_value');
         $category = CategoryModel::whereRaw("LOWER(name) = '{$category_name}'")->first();
         if ($category) {
             $catID = $category->id;
         } else {
             $catID = '#';
         }
         $BlogPosts->filterByCategory($catID);
     }
     if ($this->property('filter_type') == 'tag') {
         $tag = TagModel::where('name', '=', $this->property('filter_value'))->first();
         return $tag->posts()->paginate($this->property('postsPerPage'));
     }
     if ($this->property('filter_type') == 'author') {
         $author = BackendUserModel::findUserByLogin($this->property('filter_value'));
         if ($author) {
             $author_id = $author->id;
         } else {
             $author_id = '#';
         }
         $BlogPosts->filterByAuthor($author_id);
     }
     /*
      * Filter Request
      * Next we cycle through all possible request filters
      * @type - category,tag,author,canonical
      * (canonical requires additional different page vars /:year?/:month?/)
      */
     if ($this->param('filter')) {
         if ($this->param('filter') !== 'category' && !$this->param('slug')) {
             $slug = $this->param('filter');
             $type = 'category';
         } else {
             $type = $this->param('filter');
             $slug = $this->param('slug');
         }
         $slug = $slug;
         $slug = strtolower($slug);
         $slug = str_replace('-', ' ', $slug);
         $slug = str_replace('%20', ' ', $slug);
         if ($type == 'category') {
             $this->page['blogCurrentCategorySlug'] = $slug;
             $category = CategoryModel::whereRaw("LOWER(name) = '{$slug}'")->first();
             if ($category) {
                 $catID = $category->id;
             } else {
                 $catID = '#';
             }
             $BlogPosts->filterByCategory($catID);
         } elseif ($type == 'tag') {
             $this->page['blogCurrentTagSlug'] = $slug;
             $tag = TagModel::where('name', '=', $slug)->first();
             if ($tag) {
                 return $tag->posts()->paginate($this->property('postsPerPage'));
             }
             return false;
         } elseif ($type == 'author') {
             $author = BackendUserModel::findUserByLogin($slug);
             if ($author) {
                 $author_id = $author->id;
             } else {
                 $author_id = '#';
             }
             $BlogPosts->filterByAuthor($author_id);
         } elseif ($type == 'search') {
             $this->page['search_slug'] = $slug;
             $BlogPosts->filterBySearch($slug);
         } elseif ($type == 'cannonical') {
             $y = $this->param('year');
             $m = $this->param('month');
             $BlogPosts->filterByDate($y, $m);
         } else {
             $component = $this->addComponent('Radiantweb\\Problog\\Components\\Post', 'proBlogPost', array('slug' => $slug));
             $component->onRun();
             $this->render_post = $this->page['render_post'] = $slug;
             return $this->render_post;
         }
     }
     /*
      * no filters, we go get all
      */
     $posts = $BlogPosts->orderBy('published_at', 'desc')->paginate($this->property('postsPerPage'), $this->currentPage);
     //$queries = DB::getQueryLog();
     //$last_query = end($queries);
     //\Log::info($last_query);
     return $posts;
 }
Exemplo n.º 5
0
 public function getPost()
 {
     if ($this->post !== null) {
         return $this->post;
     }
     $this->post = PostModel::where('slug', '=', $this->param('slug'))->first();
     if (is_null($this->post)) {
         return \Response::make($this->controller->run('404'), 404);
     } else {
         return $this->post;
     }
 }