Example #1
0
 protected function loadItems()
 {
     if (!($category = Category::find($this->property('category')))) {
         return Item::paginate($this->property('itemsPerPage'), $this->property('pageNumber'));
     }
     return $category->items()->paginate($this->property('itemsPerPage'), $this->property('pageNumber'));
 }
Example #2
0
 /**
  * When running this component, load all items based on the selections.
  */
 public function onRun()
 {
     // Page links
     $this->itemPage = $this->page['itemPage'] = $this->property('itemPage');
     $this->tagListPage = $this->page['tagListPage'] = $this->property('tagListPage');
     $this->catListPage = $this->page['catListPage'] = $this->property('catListPage');
     // find the correct property to select the items with
     $object = null;
     if ($this->property('selectedTag') != null) {
         $object = $this->loadItemsByTag($this->property('selectedTag'));
     } elseif ($this->property('selectedCat') != null) {
         $object = $this->loadItemsByCategory($this->property('selectedCat'), true);
     } elseif ($this->property('category') != null) {
         $object = $this->loadItemsByCategory($this->property('category'));
     }
     // check if a valid object has been created
     if (!$object) {
         // display all items
         $this->portfolio = Item::paginate($this->property('itemsPerPage'), $this->property('pageNumber'));
     } else {
         // show the items in the portfolio
         $this->portfolio = $object->items()->orderBy('created_at', $this->property('order'))->paginate($this->property('itemsPerPage'), $this->property('pageNumber'));
     }
     // Add url helper to the items
     if ($this->portfolio != null) {
         $this->portfolio = $this->updatePageUrls($this->portfolio);
     }
 }