Exemplo n.º 1
0
 /**
  * Shows the admin dashboard: an overview of all ThumbsUp items.
  *
  * @return  void
  */
 public function action_dashboard()
 {
     // Setup content template
     $content = new ThumbsUp_Template(THUMBSUP_DOCROOT . 'admin/html/dashboard.php');
     // Filter by name
     $filter = isset($_GET['filter']) ? trim($_GET['filter']) : '';
     $filter_sql = $filter === '' ? '' : "WHERE LOWER(i.name) LIKE '%" . sqlite_escape_string((string) $_GET['filter']) . "%'";
     // Pagination
     $per_page = !empty($this->config['admin_items_per_page']) ? max(1, (int) $this->config['admin_items_per_page']) : 100;
     $total_items = $filter === '' ? ThumbsUp_Database::get_total_items() : (int) ThumbsUp_Database::db()->singleQuery("SELECT COUNT(1) FROM items i {$filter_sql}");
     $total_pages = (int) ceil($total_items / $per_page);
     $page = isset($_GET['page']) && ctype_digit($_GET['page']) ? min($total_pages, max(1, (int) $_GET['page'])) : 1;
     $limit_sql = 'LIMIT ' . $per_page . ' OFFSET ' . ($page - 1) * $per_page;
     // List of all items
     $content->items = (array) ThumbsUp_Database::db()->arrayQuery("\n\t\t\tSELECT\n\t\t\t\ti.id AS id,\n\t\t\t\ti.name AS name,\n\t\t\t\ti.closed AS closed,\n\t\t\t\ti.date AS date,\n\t\t\t\tCOUNT(v.id) AS total_votes,\n\t\t\t\tSUM(v.rating) AS positive_votes\n\t\t\tFROM items i\n\t\t\tLEFT JOIN votes v ON i.id = v.item_id\n\t\t\t{$filter_sql}\n\t\t\tGROUP BY i.id\n\t\t\tORDER BY LOWER(i.name) ASC\n\t\t\t{$limit_sql}", SQLITE_ASSOC);
     // Item counts
     $content->total_items_shown = count($content->items);
     // Render the template
     $content->filter = $filter;
     $content->total_items = $total_items;
     $content->total_pages = $total_pages;
     $content->page = $page;
     $this->template->content = $content;
     $this->template->render();
 }