Exemplo n.º 1
0
 /**
  * Show articles (table view)
  * Can show articles by context, by category, by author, by key, by page
  * Default view is reverse chronological order
  *
  * @param   integer $id_area Area ID
  * @param   string 	$lang Language code
  * @param   string	$case view switcher
  * @param   mixed   $id_what view parameter
  * @param   integer $pp index for pagination
  * @param   string	$str Search string
  * @return  void
  */
 public function index($id_area = 2, $lang = '', $case = 'latest_articles', $id_what = 0, $pp = 0, $str = '')
 {
     // load dictionary
     $this->dict->get_wordarray(array('articles'));
     $area = new Area_model();
     list($id_area, $areas) = $area->get_my_areas($id_area);
     $_SESSION['referer'] = 'index/' . $id_area . '/' . $lang . '/' . $case . '/' . $id_what . '/' . $pp . '/' . $str;
     // get page
     $page = $this->get_page('articles');
     $navbar = array($this->site->get_bredcrumb($page));
     // content
     $mod = new Article_model();
     $view = new X4View_core('container');
     $view->content = new X4View_core('articles/article_list');
     $view->content->navbar = $navbar;
     switch ($case) {
         case 'context_order':
             $cmod = new Context_model();
             $con = $cmod->get_contexts($id_area, $lang);
             if ($id_what == 0 && $con) {
                 $id_what = $con[0]->code;
             }
             $view->content->items = X4Pagination_helper::paginate($mod->get_by_context($id_area, $lang, $id_what, $str), $pp);
             $view->content->contexts = $con;
             break;
         case 'category_order':
             $cmod = new Category_model();
             $ctg = $cmod->get_categories($id_area, $lang);
             if ($id_what === 0 && $ctg) {
                 $id_what = $ctg[0]->name;
             }
             $view->content->items = X4Pagination_helper::paginate($mod->get_by_category($id_area, $lang, $id_what, $str), $pp);
             $view->content->categories = $ctg;
             break;
         case 'author_order':
             $aut = $mod->get_authors($id_area, $lang);
             if ($id_what == 0 && $aut) {
                 $id_what = $aut[0]->id_editor;
             }
             $view->content->items = X4Pagination_helper::paginate($mod->get_by_author($id_area, $lang, $id_what, $str), $pp);
             $view->content->authors = $aut;
             break;
         case 'key_order':
             $keys = $mod->get_keys($id_area, $lang);
             if ($id_what == 0 && $keys) {
                 $id_what = $keys[0]->xkeys;
             }
             $view->content->items = X4Pagination_helper::paginate($mod->get_by_key($id_area, $lang, $id_what, $str), $pp);
             $view->content->keys = $keys;
             break;
         case 'by_page':
             $pmod = new Page_model();
             $spage = $pmod->get_by_id($id_what);
             $view->content->items = X4Pagination_helper::paginate($mod->get_by_page($id_area, $lang, $id_what, $str), $pp);
             $view->content->page = $spage;
             break;
         default:
             $view->content->items = X4Pagination_helper::paginate($mod->get_articles($id_area, $lang, 'id', $str), $pp);
             break;
     }
     // for the construction of the tabs
     $view->content->xcase = $case;
     $view->content->cases = $this->cases;
     $view->content->id_what = $id_what;
     $view->content->pp = $pp;
     $view->content->str = $str;
     // area switcher
     $view->content->id_area = $id_area;
     $view->content->areas = $areas;
     // language switcher
     $view->content->lang = $lang;
     $lang = new Language_model();
     $view->content->langs = $lang->get_languages();
     $view->render(TRUE);
 }