Esempio n. 1
0
 public function loadData()
 {
     $mdlPage = new Model_Page();
     $row = $mdlPage->find($this->_page->getId())->current();
     if ($row) {
         $this->_page->setData($row);
     }
 }
Esempio n. 2
0
 public function action_list()
 {
     $data['pages'] = Model_Page::find('all');
     $this->template->title = 'List of all pages';
     $this->template->content = View::forge('page/list', $data);
 }
Esempio n. 3
0
 /**
  * Get additional content data selected
  * 
  * @param $result = Query result
  */
 public static function post_find($result)
 {
     if ($result !== null) {
         if (is_array($result)) {
             foreach ($result as $item) {
                 // It will first check if we already have result in temporary result,
                 // and only execute query if we dont. That way we dont have duplicate queries
                 // Get content images
                 $item->get_images = static::lazy_load(function () use($item) {
                     return Model_Image::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'images');
                 // Get first content image
                 $item->get_image = static::lazy_load(function () use($item) {
                     if (!empty($item->images)) {
                         return $item->images[0];
                     }
                 }, $item->id, 'image', 'object');
                 // Get content files
                 $item->get_files = static::lazy_load(function () use($item) {
                     return Model_File::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'files');
                 // Get content videos
                 $item->get_videos = static::lazy_load(function () use($item) {
                     return Model_Video::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'videos');
                 // Get content parent
                 $item->get_parent = static::lazy_load(function () use($item) {
                     return Model_Page::find_one_by_id($item->parent_id);
                 }, $item->id, 'parent', 'object');
                 // Get content children
                 $item->get_children = static::lazy_load(function () use($item) {
                     return Model_Page::find(array('where' => array('parent_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'children');
                 // Get content accordions
                 $item->get_accordions = static::lazy_load(function () use($item) {
                     return Model_Accordion::find(array('where' => array('parent_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'accordions');
                 // Get content children
                 $item->get_seo = static::lazy_load(function () use($item) {
                     return Model_Seo::find_one_by_content_id($item->id);
                 }, $item->id, 'seo', 'object');
             }
         }
     }
     // return the result
     return $result;
 }
Esempio n. 4
0
 public function get_search_items($parent_id = 0)
 {
     // Reset $parent_id if its invalid value
     is_numeric($parent_id) or $parent_id = 0;
     /************ Start generating query ***********/
     $items = Model_Page::find(function ($query) use($parent_id) {
         // Select only root pages
         // $query->where('parent_id', $parent_id);
         // Get search filters
         foreach (\Input::get() as $key => $value) {
             if (!empty($value) || $value == '0') {
                 switch ($key) {
                     case 'title':
                         $query->where($key, 'like', "%{$value}%");
                         break;
                     case 'status':
                         if (is_numeric($value)) {
                             $query->where($key, $value);
                         }
                         break;
                     case 'active_from':
                         $date = strtotime($value);
                         if ($date) {
                             $query->where($key, '>=', $date);
                         }
                         break;
                     case 'active_to':
                         $date = strtotime($value);
                         if ($date) {
                             $query->where($key, '<=', $date);
                         }
                         break;
                 }
             }
         }
         // Order query
         $query->order_by('sort', 'asc');
         $query->order_by('id', 'asc');
     });
     /************ End generating query ***********/
     // Reset to empty array if there are no result found by query
     if (is_null($items)) {
         $items = array();
     }
     // start - sort by subpage
     $items_sorted = array();
     $list_subpages = function ($item) use(&$list_subpages) {
         $items_sorted_sub = array();
         foreach ($item->children as $child) {
             array_push($items_sorted_sub, $child);
             if (!empty($child->children)) {
                 foreach ($list_subpages($child) as $value) {
                     array_push($items_sorted_sub, $value);
                 }
             }
         }
         return $items_sorted_sub;
     };
     $pages = Model_Page::find(function ($query) {
         // Order query
         $query->order_by('sort', 'asc');
         $query->order_by('id', 'asc');
     });
     foreach ($pages as $page) {
         if ($page->parent_id == 0) {
             array_push($items_sorted, $page);
             foreach ($list_subpages($page) as $value) {
                 array_push($items_sorted, $value);
             }
         }
     }
     $final_items = array();
     foreach ($items_sorted as $item_sorted) {
         foreach ($items as $item) {
             if ($item_sorted->id == $item->id) {
                 array_push($final_items, $item);
             }
         }
     }
     $items = $final_items;
     // end - sort by subpage
     // Initiate pagination
     $pagination = \Hybrid\Pagination::make(array('total_items' => count($items), 'per_page' => \Input::get('per_page', 10), 'uri_segment' => null));
     // Remove unwanted items, and show only required ones
     $items = array_slice($items, $pagination->offset, $pagination->per_page);
     $status = array('false' => 'Select', '1' => 'Active', '0' => 'Inactive', '2' => 'Active in period');
     return array('items' => $items, 'pagination' => $pagination, 'status' => $status);
 }