/**
  * gets all the threads of the user
  */
 public function action_index()
 {
     //get single thread
     if (is_numeric($this->request->param('id'))) {
         $this->action_get();
     } else {
         $messages = Model_Message::get_threads($this->user->id_user);
         //by default all except spam
         if (empty($this->_filter_params)) {
             $this->_filter_params['status'] = array('field' => 'status', 'operator' => '!=', 'value' => Model_Message::STATUS_SPAM);
         }
         //filter results by param, verify field exists and has a value
         $messages->api_filter($this->_filter_params);
         //how many? used in header X-Total-Count
         $count = $messages->count_all();
         //by default sort by status not read and when was created
         if (empty($this->_sort)) {
             $this->_sort['status'] = 'asc';
             $this->_sort['created'] = 'desc';
         }
         //after counting sort values
         $messages->api_sort($this->_sort);
         //pagination with headers
         $pagination = $messages->api_pagination($count, $this->_params['items_per_page']);
         $messages = $messages->cached()->find_all();
         $m = array();
         //convert it to array
         foreach ($messages as $message) {
             $m[] = $message->as_array();
         }
         $this->rest_output(array('messages' => $m), 200, $count, $pagination !== FALSE ? $pagination : NULL);
     }
 }
Ejemplo n.º 2
0
 public function action_index()
 {
     $messages = Model_Message::get_threads($this->user, core::get('status'));
     $res_count = $messages->count_all();
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Messaging'))->set_url(Route::url('oc-panel', array('controller' => 'messages', 'action' => 'index'))));
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Inbox')));
     Controller::$full_width = TRUE;
     if ($res_count > 0) {
         $pagination = Pagination::factory(array('view' => 'oc-panel/crud/pagination', 'total_items' => $res_count, 'items_per_page' => core::config('advertisement.advertisements_per_page')))->route_params(array('controller' => $this->request->controller(), 'action' => $this->request->action()));
         Breadcrumbs::add(Breadcrumb::factory()->set_title(sprintf(__("Page %d"), $pagination->current_page)));
         $messages = $messages->order_by('created', 'desc')->limit($pagination->items_per_page)->offset($pagination->offset)->find_all();
         $this->template->styles = array('css/jquery.sceditor.default.theme.min.css' => 'screen');
         $this->template->scripts['footer'] = array('js/jquery.sceditor.bbcode.min.js', 'js/messages.js');
         $this->template->content = View::factory('oc-panel/pages/messages/index', array('messages' => $messages, 'pagination' => $pagination, 'user' => $this->user));
     } else {
         $this->template->content = View::factory('oc-panel/pages/messages/index', array('messages' => NULL, 'pagination' => NULL, 'user' => $this->user));
     }
 }
Ejemplo n.º 3
0
 /**
  * returns all the unread threads for a user
  * @param  Model_User $user        
  * @return Model_Message                    
  */
 public static function get_unread_threads($user)
 {
     return Model_Message::get_threads($user, Model_Message::STATUS_NOTREAD);
 }