Exemple #1
0
 /**
  * Articles List
  * Called through XHR from articles panel
  * 
  */
 public function get_articles_list($page = 1)
 {
     // Nb and Minimum
     $nb = $this->input->post('nb') ? $this->input->post('nb') : self::$_NB_ARTICLES_PAGINATION;
     // Pagination
     $nb_lang = count(Settings::get_languages());
     //	if ($nb < self::$_NB_ARTICLES_PAGINATION) $nb = self::$_NB_ARTICLES_PAGINATION;
     $page = $page - 1;
     $offset = $page * $nb;
     $where = array('limit' => $nb * $nb_lang, 'offset' => $offset * $nb_lang);
     // Filter
     $filter_title = $this->input->post('title');
     if ($filter_title) {
         $where['like'] = array('article_lang.title' => $filter_title);
     }
     $filter_content = $this->input->post('content');
     if ($filter_content) {
         $where['like'] = array('article_lang.content' => $filter_content);
     }
     // ID Page
     $filter_id_page = $this->input->post('id_parent');
     if ($filter_id_page) {
         $children_ids = $this->page_model->get_children_ids($filter_id_page, TRUE);
         $where['where_in'] = array('page_article.id_page' => $children_ids);
     }
     // Menu
     $filter_id_menu = $this->input->post('id_menu');
     if ($filter_id_menu) {
         $where['page.id_menu'] = $filter_id_menu;
     }
     $articles = $this->article_model->get_all_lang_list($where);
     // Get Pages and Breadcrumb to pages for each linked page
     $_pages_breadcrumbs = array();
     foreach ($articles as &$article) {
         $article['data']['pages'] = array();
         // Main Parent page ID
         if (empty($article['data']['page_ids'])) {
             $article['data']['page_ids'] = '0';
         } else {
             $page_ids = explode('/', $article['data']['path_ids']);
             if (isset($page_ids[count($page_ids) - 2])) {
                 $article['data']['id_page'] = $page_ids[count($page_ids) - 2];
             } else {
                 $article['data']['id_page'] = '0';
             }
         }
         // Pages Breadcrumbs
         $page_ids = explode(';', $article['data']['page_ids']);
         if (!empty($page_ids)) {
             foreach ($page_ids as $id_page) {
                 $breadcrumb = in_array($id_page, array_keys($_pages_breadcrumbs)) ? $_pages_breadcrumbs[$id_page] : $this->page_model->get_breadcrumb_string($id_page);
                 $_pages_breadcrumbs[$id_page] = $breadcrumb;
                 //$breadcrumb = '';
                 if (!empty($id_page)) {
                     $article['data']['pages'][] = array('id_page' => $id_page, 'breadcrumb' => $breadcrumb);
                 }
             }
         }
     }
     // Pagination
     $this->template['current_page'] = $page + 1;
     $this->template['nb'] = $nb;
     unset($where['limit']);
     unset($where['offset']);
     $this->template['articles_count'] = $this->article_model->count_all_lang_list($where) / $nb_lang;
     $this->template['articles_pages'] = ceil($this->template['articles_count'] / $nb);
     $this->template['articles'] = $articles;
     $this->output('articles/list');
 }