public function results()
 {
     $id = $this->getParam(0, 0);
     $type_label = $this->getParam(1, 0);
     $page = !empty($this->getParam(2, 0)) ? (int) $this->getParam(2, 0) : 1;
     //$search_query = $this->request->get('q', '');
     $labels = Info::$type_labels;
     $type_label = ucfirst(str_replace('-', ' ', $type_label));
     $type = array_search($type_label, $labels);
     //$infos = Info::getElements($id, $type);
     /*
     $vars = array (
     	'id' => $id,
     	'type_label' => $type_label,
     	'infos' => $infos,
     	'labels' => $labels
     );
     */
     $sql = 'SELECT id, quarter_id, name, type, description, url, rating, theme FROM info WHERE quarter_id = :quarter_id AND type = :type ORDER BY id ASC';
     $bindings = array('quarter_id' => $id, 'type' => $type);
     $pagination = new Pagination($sql, $bindings, 16, $page - 1);
     $results = $pagination->getResults();
     foreach ($results as $result) {
         $infos[] = new Info($result);
     }
     //foreach ($infos as $key => $info) {
     //	$info->description=substr($info->description,0, 50);
     //}
     $vars = array('id' => $id, 'type_label' => $type_label, 'infos' => $infos, 'labels' => $labels, 'page' => $page, 'count_pages' => $pagination->getPagesCount(), 'count_total' => $pagination->getTotalCount());
     $this->render('elements', $vars);
 }
 public function results()
 {
     $params = $this->getParams();
     $search_query = $this->request->get('q', '');
     $page = !empty($params[0]) ? (int) $params[0] : 1;
     $vars = array('title' => 'Search', 'description' => 'Description', 'page' => $page, 'count_pages' => 0, 'posts' => array(), 'count_total' => 0, 'search_query' => $search_query);
     if (!empty($search_query)) {
         $pagination = new Pagination('SELECT * FROM post WHERE title LIKE :search OR content LIKE :search ORDER BY date DESC', array(':search' => '%' . $search_query . '%'), 5, $page - 1);
         $vars = array_merge($vars, array('page' => $page, 'count_pages' => $pagination->getPagesCount(), 'posts' => $pagination->getResults(), 'count_total' => $pagination->getTotalCount()));
     }
     $this->render('search', $vars);
 }
 public function results()
 {
     $page = !empty($this->getParam(0, 0)) ? (int) $this->getParam(0, 0) : 1;
     //$pictures = Picture::getList('SELECT id, quarter_id, src, info_id, user_id FROM photo WHERE user_id IS NOT NULL ORDER BY id DESC');
     $sql = 'SELECT id, quarter_id, src, info_id, user_id FROM photo WHERE user_id IS NOT NULL ORDER BY id DESC';
     $bindings = array();
     $pagination = new Pagination($sql, $bindings, 20, $page - 1);
     $results = $pagination->getResults();
     foreach ($results as $result) {
         $pictures[] = new Picture($result);
     }
     $vars = array('pictures' => $pictures, 'page' => $page, 'count_pages' => $pagination->getPagesCount(), 'count_total' => $pagination->getTotalCount());
     $this->render('wall', $vars);
 }
 public function archives()
 {
     $params = $this->getParams();
     $date = !empty($params[0]) ? $params[0] : date('Y-m');
     $page = !empty($params[1]) ? (int) $params[1] : 1;
     $time = strtotime($date);
     $date_label = ucfirst(Lang::_(strtolower(date('F', $time)))) . ' ' . date('Y', $time);
     $pagination = new Pagination('SELECT * FROM post WHERE DATE_FORMAT(date, "%Y-%m") = :date ORDER BY date DESC', array(':date' => $date), 4, $page - 1);
     /*
     // Same with date split without mysql function DATE_FORMAT()
     $date_parts = explode('-', $date);
     $year = $date_parts[0];
     $month = $date_parts[1];
     
     $pagination = new Pagination('SELECT * FROM post WHERE YEAR(date) = :year AND MONTH(date) = :month ORDER BY date DESC', array(':year' => $year, ':month' => $month), 4, $page - 1);
     */
     $vars = array('title' => 'Title', 'description' => 'Description', 'date' => $date, 'date_label' => $date_label, 'page' => $page, 'count_pages' => $pagination->getPagesCount(), 'count_total' => $pagination->getTotalCount(), 'posts' => $pagination->getResults());
     $this->render('archives', $vars);
 }
 public function results()
 {
     $params = $this->getParams();
     $quick_search = $this->request->get('qs');
     $advanced_search = $this->request->get('as');
     $search_query = $this->request->get('q', '');
     $quarter = $this->request->get('quarter', '');
     $type = $this->request->get('type', '');
     $theme = $this->request->get('theme', '');
     $page = !empty($params[0]) ? (int) $params[0] : 1;
     $infos = array();
     $quarters = Quarter::getList('SELECT id, name FROM quarter ORDER BY name ASC');
     $types = Info::$type_labels;
     $themes_query = Db::select('SELECT DISTINCT(theme) FROM info WHERE theme IS NOT NULL AND theme != "" ORDER BY theme');
     $themes = array();
     foreach ($themes_query as $row) {
         $_theme = $row['theme'];
         if (strpos($_theme, '|') !== false) {
             $theme_parts = explode('|', $_theme);
             foreach ($theme_parts as $_theme) {
                 if (!in_array($_theme, $themes)) {
                     $themes[] = $_theme;
                 }
             }
             continue;
         }
         $themes[] = $_theme;
     }
     $vars = array('title' => 'Search', 'description' => 'Description', 'quarters' => $quarters, 'types' => $types, 'themes' => $themes, 'page' => $page, 'count_pages' => 0, 'infos' => $infos, 'count_total' => 0, 'search_query' => $search_query, 'quarter' => $quarter, 'type' => $type, 'theme' => $theme, 'qs' => $quick_search, 'as' => $advanced_search);
     $sql = 'SELECT i.* FROM quarter q LEFT JOIN info i ON i.quarter_id = q.id WHERE 1 ';
     if (!empty($search_query)) {
         $sql .= 'AND (q.name LIKE :search OR q.description LIKE :search OR i.name LIKE :search OR i.description LIKE :search) ';
         $bindings = array('search' => '%' . $search_query . '%');
     }
     if (!empty($advanced_search)) {
         if (!empty($quarter)) {
             $sql .= 'AND q.id = :quarter ';
             $bindings['quarter'] = $quarter;
         }
         if (!empty($type)) {
             $sql .= 'AND i.type = :type ';
             $bindings['type'] = $type;
         }
         if (!empty($theme)) {
             $sql .= 'AND i.theme LIKE :theme ';
             $bindings['theme'] = '%' . $theme . '%';
         }
     }
     if (!empty($bindings)) {
         $pagination = new Pagination($sql, $bindings, 10, $page - 1);
         $results = $pagination->getResults();
         foreach ($results as $result) {
             $infos[] = new Info($result);
         }
         foreach ($infos as $key => $info) {
             $info->description = substr($info->description, 0, 200);
         }
         $vars = array_merge($vars, array('page' => $page, 'count_pages' => $pagination->getPagesCount(), 'infos' => $infos, 'count_total' => $pagination->getTotalCount()));
     }
     $this->render('search', $vars);
 }