/** * IS: Terdeklarasinya filter dan param di session, dan page_row * FS: Mengirimkan ke viewer: cleanUrl, message, filter_alert, page_row, * year_list, dan paginator * Desc: Mengatur aksi yang dilakukan untuk halaman index news */ public function indexAction() { /** Send this page url to the view */ $this->view->cleanurl = $this->_cleanUrl; /** Get messages from CRUD process */ $message = $this->_flash->getMessages(); if (!empty($message)) { $this->view->message = $message; } /** Create table instance */ $table_news = new Model_DbTable_News(); /** Set the variable initial value */ $filter = null; $new_search = FALSE; /** Get the filter params */ if ($this->getRequest()->isPost()) { $param_month = null; $filter = $_POST['filterPage']; /** If new search is commited then we set the $new_search to TRUE */ $new_search = TRUE; $this->_paginator_sess->filter = $filter; switch ($filter) { case 0: $param = null; break; case 1: $param = $_POST['filterTitle']; break; case 2: $param = $_POST['filterPoi']; break; case 3: $param = $_POST['filterYear']; $param_month = $this->_getParam('filterMonth'); break; case 4: $param = $_POST['filterStatus']; break; } $this->_paginator_sess->param = $param; if ($param_month != null) { $this->_paginator_sess->param_month = $param_month; } } /** Get the params from session and create paginator */ $filter = $this->_paginator_sess->filter; $param = $this->_paginator_sess->param; $param_month = $this->_paginator_sess->param_month; /** Return alert to view on filter selected */ switch ($filter) { case 0: $filter_alert = "Show all news"; break; case 1: $filter_alert = "News which title with keyword '" . $param . "'"; break; case 2: $filter_alert = "News that related to '" . $param . "'"; break; case 3: $filter_alert = "News that published on " . strftime("%B", strtotime($param_month . "/29/1985")) . " " . $param . ""; break; case 4: $param == '1' ? $state = 'Published' : ($state = 'Draft'); $filter_alert = "News with '" . $state . "' status"; break; } $this->view->alert = $filter_alert; $select = $table_news->getQueryAllByLanguage($filter, $param, $param_month); /** Get page row setting and send to the paginator control */ $page_row = $this->_getParam('filterPageRow'); $this->view->row = $page_row; if ($page_row != null) { $paginator = parent::setPaginator($select, $page_row); } else { $paginator = parent::setPaginator($select); } /** * If this is a new search * then return the page number back to the 1st page */ if ($new_search) { $paginator->setCurrentPageNumber(1); } /** Send data to the view */ $this->view->year_list = $table_news->getPublishYear(); $this->view->paginator = $paginator; }