Ejemplo n.º 1
0
 /**
  *
  * @param type $page
  */
 public function index($page = 1)
 {
     $view = $this->getActionView();
     $layoutView = $this->getLayoutView();
     $config = Registry::get('configuration');
     $articlesPerPage = $config->news_per_page;
     if ($page == 1) {
         $canonical = 'http://' . $this->getServerHost() . '/aktuality';
     } else {
         $canonical = 'http://' . $this->getServerHost() . '/aktuality/p/' . $page;
     }
     $content = $this->getCache()->get('news-' . $page);
     if ($content !== null) {
         $news = $content;
     } else {
         $news = App_Model_News::all(array('active = ?' => true, 'expirationDate >= ?' => date('Y-m-d H:i:s')), array('id', 'urlKey', 'author', 'title', 'shortBody', 'created', 'rank'), array('rank' => 'asc', 'created' => 'DESC'), (int) $articlesPerPage, (int) $page);
         $this->getCache()->set('news-' . $page, $news);
     }
     $newsCount = App_Model_News::count(array('active = ?' => true, 'expirationDate >= ?' => date('Y-m-d H:i:s')));
     $newsPageCount = ceil($newsCount / $articlesPerPage);
     $view->set('newsbatch', $news)->set('newspagecount', $newsPageCount);
     if ($newsPageCount > 1) {
         $prevPage = $page - 1;
         $nextPage = $page + 1;
         if ($nextPage > $newsPageCount) {
             $nextPage = 0;
         }
         $layoutView->set('pagedprev', $prevPage)->set('pagedprevlink', '/aktuality/p/' . $prevPage)->set('pagednext', $nextPage)->set('pagednextlink', '/aktuality/p/' . $nextPage);
     }
     $layoutView->set('metatitle', 'ZKO - Aktuality')->set('canonical', $canonical);
 }
Ejemplo n.º 2
0
 /**
  * 
  * @param type $page
  */
 public function index()
 {
     $view = $this->getActionView();
     $layoutView = $this->getLayoutView();
     $config = Registry::get('configuration');
     $content = $this->getCache()->get('news-1');
     $npp = $config->news_per_page;
     if (NULL !== $content) {
         $news = $content;
     } else {
         $news = App_Model_News::all(array('active = ?' => true, 'expirationDate >= ?' => date('Y-m-d H:i:s')), array('id', 'urlKey', 'author', 'title', 'shortBody', 'created', 'rank'), array('rank' => 'desc', 'created' => 'DESC'), (int) $npp, 1);
         $this->getCache()->set('news-1', $news);
     }
     $newsCount = App_Model_News::count(array('active = ?' => true, 'expirationDate >= ?' => date('Y-m-d H:i:s')));
     $newsPageCount = ceil($newsCount / $npp);
     $view->set('newsbatch', $news)->set('newspagecount', $newsPageCount);
     $canonical = 'http://' . $this->getServerHost() . '/';
     $layoutView->set('canonical', $canonical);
 }
Ejemplo n.º 3
0
 /**
  * @before _secured, _admin
  */
 public function load()
 {
     $this->willRenderActionView = false;
     $this->willRenderLayoutView = false;
     $page = (int) RequestMethods::post('page', 0);
     $search = RequestMethods::issetpost('sSearch') ? RequestMethods::post('sSearch') : '';
     if ($search != '') {
         $whereCond = "nw.created='?' OR nw.expirationDate='?' " . "OR nw.author LIKE '%%?%%' OR nw.title LIKE '%%?%%'";
         $query = App_Model_News::getQuery(array('nw.id', 'nw.author', 'nw.title', 'nw.expirationDate', 'nw.active', 'nw.created'))->wheresql($whereCond, $search, $search, $search, $search);
         if (RequestMethods::issetpost('iSortCol_0')) {
             $dir = RequestMethods::issetpost('sSortDir_0') ? RequestMethods::post('sSortDir_0') : 'asc';
             $column = RequestMethods::post('iSortCol_0');
             if ($column == 0) {
                 $query->order('nw.id', $dir);
             } elseif ($column == 2) {
                 $query->order('nw.title', $dir);
             } elseif ($column == 3) {
                 $query->order('nw.author', $dir);
             } elseif ($column == 4) {
                 $query->order('nw.expirationDate', $dir);
             } elseif ($column == 5) {
                 $query->order('nw.created', $dir);
             }
         } else {
             $query->order('nw.id', 'desc');
         }
         $limit = (int) RequestMethods::post('iDisplayLength');
         $query->limit($limit, $page + 1);
         $news = App_Model_News::initialize($query);
         $countQuery = App_Model_News::getQuery(array('nw.id'))->wheresql($whereCond, $search, $search, $search, $search);
         $newsCount = App_Model_News::initialize($countQuery);
         unset($countQuery);
         $count = count($newsCount);
         unset($newsCount);
     } else {
         $query = App_Model_News::getQuery(array('nw.id', 'nw.author', 'nw.title', 'nw.expirationDate', 'nw.active', 'nw.created'));
         if (RequestMethods::issetpost('iSortCol_0')) {
             $dir = RequestMethods::issetpost('sSortDir_0') ? RequestMethods::post('sSortDir_0') : 'asc';
             $column = RequestMethods::post('iSortCol_0');
             if ($column == 0) {
                 $query->order('nw.id', $dir);
             } elseif ($column == 2) {
                 $query->order('nw.title', $dir);
             } elseif ($column == 3) {
                 $query->order('nw.author', $dir);
             } elseif ($column == 4) {
                 $query->order('nw.expirationDate', $dir);
             } elseif ($column == 5) {
                 $query->order('nw.created', $dir);
             }
         } else {
             $query->order('nw.id', 'desc');
         }
         $limit = (int) RequestMethods::post('iDisplayLength');
         $query->limit($limit, $page + 1);
         $news = App_Model_News::initialize($query);
         $count = App_Model_News::count();
     }
     $draw = $page + 1 + time();
     $str = '{ "draw": ' . $draw . ', "recordsTotal": ' . $count . ', "recordsFiltered": ' . $count . ', "data": [';
     $returnArr = array();
     if ($news !== null) {
         foreach ($news as $_news) {
             if ($_news->active) {
                 $label = "<span class='labelProduct labelProductGreen'>Aktivní</span>";
             } else {
                 $label = "<span class='labelProduct labelProductRed'>Neaktivní</span>";
             }
             $arr = array();
             $arr[] = "[ \"" . $_news->getId() . "\"";
             $arr[] = "\"" . $_news->getTitle() . "\"";
             $arr[] = "\"" . $_news->getAuthor() . "\"";
             $arr[] = "\"" . $_news->getExpirationDate() . "\"";
             $arr[] = "\"" . $_news->getCreated() . "\"";
             $arr[] = "\"" . $label . "\"";
             $tempStr = "\"<a href='/admin/news/edit/" . $_news->id . "' class='btn btn3 btn_pencil' title='Upravit'></a>";
             if ($this->isAdmin()) {
                 $tempStr .= "<a href='/admin/news/delete/" . $_news->id . "' class='btn btn3 btn_trash ajaxDelete' title='Smazat'></a>";
             }
             $arr[] = $tempStr . "\"]";
             $returnArr[] = join(',', $arr);
         }
         $str .= join(',', $returnArr) . "]}";
         echo $str;
     } else {
         $str .= "[ \"\",\"\",\"\",\"\",\"\",\"\",\"\"]]}";
         echo $str;
     }
 }