Example #1
0
 public function followingAction()
 {
     $request = $this->getRequest();
     $list_type = $request->getParam('list_type');
     if ($request->getParam('list_type') == 'followers') {
         $this->view->following = $following = true;
     } else {
         $this->view->following = $following = false;
     }
     if (!$following) {
         $username = $request->getParam('following');
     } else {
         $username = $request->getParam('followers');
     }
     $user = $this->view->users = Model_Users::getByUsername($username);
     if (!$user) {
         return $this->forward('error', 'error404');
     }
     $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 = 'asc';
     }
     $sort = $request->getRequest('sort');
     if (is_null($sort)) {
         $sort = 'username';
     }
     if ($following) {
         $name = $this->translate('Following');
     } else {
         $name = $this->translate('Followers');
     }
     $this->getLayout()->meta_title = $user['firstname'] . ' ' . $user['lastname'] . ' - ' . $user['username'] . ' - ' . $name;
     $this->getLayout()->meta_description = $user['firstname'] . ' ' . $user['lastname'] . ' - ' . $user['username'] . ' - ' . $name;
     $this->view->crumbs = array(array('name' => $this->translate('Home'), 'href' => $request->getBaseUrl()), array('name' => $this->translate('Authors'), 'href' => WM_Router::create($request->getBaseUrl() . '?controller=users&action=authors')), array('name' => $user['username']));
     $this->view->author_header = Helper_Author::authorHeader($user);
     $link = $request->getBaseUrl() . '?controller=users&action=' . (!$following ? 'following' : 'followers') . '&username='******'username'];
     $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));
     $total_records = Model_Users::countFollowers($user['user_id'], $following);
     $start = $page * $limit - $limit;
     if ($start > $total_records) {
         $page = max(ceil($total_records / $limit), 1);
         $start = $page * $limit - $limit;
     } elseif ($start < 0) {
         $start = 0;
     }
     $items = Model_Users::getFollowers($user['user_id'], $start, $limit, $following, 'users.' . $sort . ' ' . $order);
     $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);
     }
     /* ITEMS */
     if ($items) {
         $this->view->items = array();
         foreach ($items as $n => $item) {
             $this->view->items[] = Helper_Author::returnFollowing($item, $user, $following ? false : true);
         }
     }
     $this->view->children = array();
     $this->view->children['header_part'] = 'layout/header_part';
     $this->view->children['footer_part'] = 'layout/footer_part';
 }