Exemplo n.º 1
0
 public function threads_for_userAction()
 {
     $request = $this->getRequest();
     $this->setViewChange('index');
     $username = $request->getRequest('threads_for_user');
     $username = trim(mb_strtolower(urldecode($username), 'UTF-8'));
     $this->view->crumbs = array(array('name' => $this->translate('Home'), 'href' => $request->getBaseUrl()), array('name' => $this->translate('Forum'), 'href' => WM_Router::create($request->getBaseUrl() . '?controller=forum')), array('name' => $username));
     $this->view->mainCategories = array();
     $this->view->mainCategories = Model_Forum::getAll();
     foreach ($this->view->mainCategories as $k => $v) {
         $this->view->mainCategories[$k]['href'] = WM_Router::create($request->getBaseUrl() . '?controller=forum&action=thread/' . $this->view->mainCategories[$k]['id'] . '/' . WM_Router::clearName($this->view->mainCategories[$k]['name']));
     }
     $this->view->mainCategories = array_merge(array(0 => array('name' => $this->translate('All Topics'), 'href' => WM_Router::create($request->getBaseUrl() . '?controller=forum'))), $this->view->mainCategories);
     $this->view->headline = $this->translate('All Topics');
     $this->view->sel_thread = -1;
     $this->view->headline = $this->translate('Threads') . ': ' . $username;
     $threads = Model_Forum::getThreadsByUser($username);
     $total_records = count($threads);
     if ($threads) {
         $model_images = new Model_Images();
         $page = (int) $request->getRequest('page', 1);
         if ($page < 1) {
             $page = 1;
         }
         $limit = JO_Registry::get('front_limit');
         if (JO_Session::get('msg_success')) {
             $this->view->msg_success = JO_Session::get('msg_success');
             JO_Session::clear('msg_success');
         }
         if (JO_Session::get('msg_error')) {
             $this->view->error = JO_Session::get('msg_error');
             $this->view->data = JO_Session::get('data');
             JO_Session::clear('msg_error');
             JO_Session::clear('data');
         }
         $total_records = count($threads);
         $start = $page * $limit - $limit;
         if ($start > $total_records) {
             $page = max(ceil($total_records / $limit), 1);
             $start = $page * $limit - $limit;
         } elseif ($start < 0) {
             $start = 0;
         }
         $threads = array_slice($threads, $start, $limit);
         foreach ($threads as $thread) {
             if ($thread['avatar']) {
                 $thread['avatar'] = $model_images->resize($thread['avatar'], JO_Registry::forceGet('user_avatar_width'), JO_Registry::forceGet('user_avatar_height'), true);
             } else {
                 $thread['avatar'] = 'data/themes/images/noavatar.png';
             }
             $thread['userhref'] = WM_Router::create($request->getBaseUrl() . '?controller=users&action=index&username='******'owner']));
             $thread_link = WM_Router::create($request->getBaseUrl() . '?controller=forum&action=topic/' . $thread['id'] . '/' . WM_Router::clearName($thread['name']));
             $thread['threadhref'] = $thread_link;
             $thread['reporthref'] = WM_Router::create($request->getBaseUrl() . '?controller=forum&action=report/' . $thread['id']);
             $thread['badges'] = Helper_Author::userBadges($thread['badges']);
             $thread['first_date'] = WM_Date::format($thread['datetime'], 'dd M yy H:i');
             $last_page = ceil($thread['cnt'] / $limit);
             if (!empty($thread['lusername'])) {
                 if ($thread['lavatar']) {
                     $thread['lavatar'] = $model_images->resize($thread['lavatar'], 50, 50, true);
                 } else {
                     $thread['lavatar'] = 'data/themes/images/small_noavatar.png';
                 }
                 $thread['lasthref'] = $thread_link . ($last_page > 1 ? '/page/' . $last_page : '');
                 $thread['lhref'] = WM_Router::create($request->getBaseUrl() . '?controller=users&action=index&username='******'lusername']));
                 $thread['last_date'] = WM_Date::format($thread['last_post'], 'dd M yy H:i');
             }
             $this->view->threads[] = $thread;
         }
         $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($request->getBaseUrl() . '?controller=forum&action=index&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);
         }
     }
     $this->view->children = array();
     $this->view->children['rightside'] = 'forum/rightside';
     $this->view->children['header_part'] = 'layout/header_part';
     $this->view->children['footer_part'] = 'layout/footer_part';
 }