Example #1
0
 public function topAction()
 {
     $request = $this->getRequest();
     JO_Session::set('redirect', $request->getBaseUrl() . $request->getUri());
     $list_type = $request->getParam('list_type');
     if (!$list_type) {
         $this->getLayout()->meta_title = $this->translate('Top authors');
         $this->getLayout()->meta_description = $this->translate('Top authors');
         $this->view->top_authors_name = $this->translate('Top Authors');
         $list_type = 'top';
     } else {
         $this->getLayout()->meta_title = $this->translate('All authors');
         $this->getLayout()->meta_description = $this->translate('All authors');
         $this->view->top_authors_name = $this->translate('All Authors');
     }
     $page = (int) $request->getRequest('page', 1);
     if ($page < 1) {
         $page = 1;
     }
     $limit = JO_Registry::get('front_limit');
     $order = $request->getRequest('order');
     if (is_null($order)) {
         $order = 'desc';
     }
     $sort = $request->getRequest('sort');
     if ($list_type == 'top') {
         if (is_null($sort) || $sort == 'sales') {
             $sort = 'position';
         }
     } else {
         if (is_null($sort)) {
             $sort = 'username';
         }
     }
     $order = $request->getRequest('order');
     if (is_null($order)) {
         $order = 'asc';
     }
     $prefix = 'users.';
     $link = $request->getBaseUrl() . '?controller=users&action=' . $list_type;
     $this->view->sort_by = array(array('name' => $this->view->translate('rating'), 'href' => WM_Router::create($link . '&sort=rating'), 'is_selected' => $sort == 'rating' ? true : false), array('name' => $this->view->translate('sales'), 'href' => WM_Router::create($link . '&sort=sales'), 'is_selected' => $list_type == 'top' ? $sort == 'position' ? true : false : ($sort == 'sales' ? true : false)), array('name' => $this->view->translate('author name'), 'href' => WM_Router::create($link . '&sort=username'), 'is_selected' => $sort == 'username' ? true : false));
     /* ORDER */
     $link .= '&sort=' . $sort;
     $this->view->orders = array(array('name' => '&raquo;', 'href' => WM_Router::create($link . '&order=desc'), 'is_selected' => $order == 'desc' ? true : false), array('name' => '&laquo;', 'href' => WM_Router::create($link . '&order=asc'), 'is_selected' => $order == 'asc' ? true : false));
     /* CRUMBS */
     $this->view->crumbs = array();
     $this->view->crumbs[] = array('name' => $this->view->translate('Home'), 'href' => $request->getBaseUrl());
     /* PAGENATION */
     $link .= '&order=' . $order;
     $total_records = Model_Users::CountTopUsers();
     if ($list_type == 'top') {
         $total_records > 999 && ($total_records = 999);
     }
     $start = $page * $limit - $limit;
     if ($start > $total_records) {
         $page = max(ceil($total_records / $limit), 1);
         $start = $page * $limit - $limit;
     } elseif ($start < 0) {
         $start = 0;
     }
     $pagination = new Model_Pagination();
     $pagination->setLimit($limit);
     $pagination->setPage($page);
     $pagination->setText(array('text_prev' => $this->view->translate('Prev'), 'text_next' => $this->view->translate('Next')));
     $pagination->setTotal($total_records);
     $pagination->setUrl(WM_Router::create($link . '&page={page}'));
     $this->view->pagination = $pagination->render();
     if (!empty($this->view->pagination)) {
         $this->view->pagination = str_replace('{of}', $this->view->translate('OF'), $this->view->pagination);
     }
     $users = Model_Users::topUsers($start, $limit, ($sort != 'position' ? $prefix : '') . $sort . ' ' . $order, $list_type);
     if ($users) {
         $this->view->users = array();
         foreach ($users as $user) {
             $this->view->users[] = Helper_Author::getTopAuthor($user, $list_type);
         }
     }
     $this->view->children = array();
     $this->view->children['header_part'] = 'layout/header_part';
     $this->view->children['footer_part'] = 'layout/footer_part';
 }