public function get_search_items($parent_id = 0, $group_type) { $group_type = strtolower($group_type); $group_type = $group_type && in_array($group_type, array('property', 'pricing')) ? $group_type : 'property'; \View::set_global('group_type', $group_type); // Override category_id if its a search $parent_id = \Input::get('parent_id', $parent_id); // If we are viewing category products // We need to find all products from that and child categories if ($parent_id) { $group = \Product\Model_Group::find_one_by_id($parent_id); $group and \View::set_global('group', $group); } // Reset $parent_id if its invalid value is_numeric($parent_id) or $parent_id = 0; /************ Start generating query ***********/ $items = Model_Group::find(function ($query) use($group_type, $parent_id) { $query->where('type', '=', $group_type); $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; } } } // 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(); } // 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); return array('items' => $items, 'pagination' => $pagination); }
/** * Index page * * @access public * @param $slug */ public function action_index($slug = false, $gallery_id = null) { // Get home page $home_page = \Config::get('details.locked_items.home_page'); $gallery_page = \Config::get('details.locked_items.gallery'); $item = false; if ($slug == 'referrals' && strtolower(\Sentry::user()->groups()[0]['name']) != 'club members') { \Messages::error('Only club members can access this page.'); \Response::redirect('/'); } //var_dump($slug);die(); // Find content by slug if ($slug !== false) { $item = \Page\Model_Page::get_by_slug($slug); } elseif ($slug === false) { $item = \Page\Model_Page::find_one_by_id($home_page); } if ($item) { // Home page is always without slug so we redirect if someone tries to access home page with slug if ($item->id == $home_page && $slug !== false) { \Response::redirect(\Uri::base(false)); } } else { // Send to 404 page throw new \HttpNotFoundException(); } $result = \Page\Model_Page::get_content_file($item->id); if ($result) { foreach ($result as $rs) { $item->content_file_pdf = $rs->file; //pdf file $item->content_file_title = $rs->title; //pdf title } } // Default view file $view_file = 'default'; // Fill in home page slug if none is supplied if ($slug === false && $item->id == $home_page) { $slug = $item->seo->slug; // Home page has its standard template $view_file = 'home'; } else { // Search for page specific template $files = \File::read_dir($this->theme_view_path); if (!empty($files)) { foreach ($files as $file) { $path_parts = pathinfo($file); if (strpos($path_parts['filename'], '_') === 0) { $file_id = substr($path_parts['filename'], strripos($path_parts['filename'], '_') + 1); if (is_numeric($file_id) && $item->id == $file_id) { $view_file = $path_parts['filename']; } } } } } $stock_options = \Config::load('stock-option.db'); // TODO delete this srand($item->id); $this->page_theme = \Theme::instance()->set_partial('content', $this->view_dir . $view_file); $this->page_theme->set('item', $item, false); $this->page_theme->set('manage_stock', $stock_options['manage_stock'], false); $this->page_theme->set('hide_out_of_stock', $stock_options['hide_out_of_stock'], false); $this->page_theme->set('allow_buy_out_of_stock', $stock_options['allow_buy_out_of_stock'], false); if ($item->id == $gallery_page) { if ($gallery_id && \Input::is_ajax()) { // This will return gallery images only if it is ajax call $this->returnGalleryImages($gallery_id); } } // Data for home page if ($view_file == 'home') { $featured_products = \Product\Model_Group::find_one_by_id(4); if ($featured_products) { $featured_products = $featured_products->products; } $this->page_theme->set('featured_products', $featured_products, false); $categories = \Product\Model_Category::find(array('where' => array('parent_id' => 0, 'status' => 1), 'order_by' => array('sort' => 'asc'), 'limit' => 8)); $this->page_theme->set('categories', $categories, false); $applications = \Application\Model_Application::find(array('where' => array('parent_id' => 0, 'status' => 1), 'order_by' => array('sort' => 'asc'), 'limit' => 8)); $this->page_theme->set('applications', $applications, false); // $this->page_theme->set('blog', $this->wp_blog(), false); } \View::set_global('title', $item->seo->meta_title ?: $item->title); \View::set_global('meta_description', $item->seo->meta_description ?: ''); \View::set_global('meta_keywords', $item->seo->meta_keywords ?: ''); $robots = array('meta_robots_index' => $item->seo->meta_robots_index == 1 ? 'index' : 'noindex', 'meta_robots_follow' => $item->seo->meta_robots_follow == 1 ? 'follow' : 'nofollow'); \View::set_global('robots', $robots); \View::set_global('canonical', $item->seo->canonical_links); \View::set_global('h1_tag', $item->seo->h1_tag); if ($item->seo->redirect_301) { \Response::redirect($item->seo->redirect_301); } }