/** * Get private topic recipients. * * @param Model_Forum_Private_Topic $topic * @return View_Users_List */ public function section_recipients(Model_Forum_Private_Topic $topic) { $section = new View_Users_List($recipients = $topic->recipients()); $section->title = __('Recipients') . ' <small><i class="icon-user"></i> ' . count($recipients) . '</small>'; return $section; }
/** * Refresh area data. * Potentially heavy function, use with caution! * * @param boolean $save */ public function refresh($save = true) { if (!$this->loaded()) { return false; } // Get table names if ($this instanceof Anqh_Model_Forum_Area) { $topic_table = Model_Forum_Topic::factory()->get_table_name(); $post_table = Model_Forum_Post::factory()->get_table_name(); } else { $topic_table = Model_Forum_Private_Topic::factory()->get_table_name(); $post_table = Model_Forum_Private_Post::factory()->get_table_name(); } // Stats $this->topic_count = (int) DB::select(array(DB::expr('COUNT(id)'), 'topics'))->from($topic_table)->where('forum_area_id', '=', $this->id)->execute($this->_db)->get('topics'); $this->post_count = (int) DB::select(array(DB::expr('COUNT(id)'), 'posts'))->from($post_table)->where('forum_area_id', '=', $this->id)->execute($this->_db)->get('posts'); // Last topic $this->last_topic_id = (int) DB::select(array(DB::expr('MAX(id)'), 'topic_id'))->from($topic_table)->where('forum_area_id', '=', $this->id)->execute($this->_db)->get('topic_id'); if ($save) { $this->save(); } return true; }
/** * Find private message topics * * @static * @param Model_User $user * @param integer $offset * @param integer $limit * @return Model_Forum_Private_Topic[] */ public static function find_topics(Model_User $user, $offset = 0, $limit = 10) { $topic = new Model_Forum_Private_Topic(); return $topic->load(DB::select_array($topic->fields())->join('forum_private_recipients')->on('forum_private_topics.id', '=', 'forum_private_recipients.forum_topic_id')->where('user_id', '=', $user->id)->order_by('last_post_id', 'DESC')->offset($offset), $limit); }
/** * Action: private */ public function action_messages() { Permission::required(new Model_Forum_Private_Area(), Model_Forum_Private_Area::PERMISSION_READ, self::$user); // Build page $this->view = new View_Page(__('Private messages')); $this->view->tab = 'private-messages'; $this->view->subtitle = __('Personal and group messages'); // Set actions if (Permission::has(new Model_Forum_Private_Area(), Model_Forum_Private_Area::PERMISSION_POST, self::$user)) { $this->view->actions[] = array('link' => Route::url('forum_private_topic_add', array('action' => 'post')), 'text' => '<i class="icon-plus-sign icon-white"></i> ' . __('New message'), 'class' => 'btn btn-primary'); } // Pagination $pagination = $this->section_pagination(Model_Forum_Private_Topic::factory()->get_count(self::$user)); $this->view->add(View_Page::COLUMN_MAIN, $pagination); // Posts $this->view->add(View_Page::COLUMN_MAIN, $this->section_topics_private(Model_Forum_Private_Area::factory()->find_topics(self::$user, $pagination->offset, $pagination->items_per_page))); // Pagination $this->view->add(View_Page::COLUMN_MAIN, $pagination); $this->_side_views(); }