예제 #1
0
 /**
  * Displays a list of tickets
  *
  * @return	void
  */
 public function displayTask()
 {
     $obj = new Tables\Ticket($this->database);
     // Get filters
     $this->view->total = 0;
     $this->view->rows = array();
     $this->view->filters = array('limit' => Request::getState($this->_option . '.' . $this->_controller . '.limit', 'limit', Config::get('list_limit'), 'int'), 'start' => Request::getState($this->_option . '.' . $this->_controller . '.limitstart', 'limitstart', 0, 'int'), 'show' => Request::getState($this->_option . '.' . $this->_controller . '.show', 'show', 0, 'int'), 'search' => '', 'sort' => 'id', 'sortdir' => 'DESC');
     // Get query list
     $sf = new Tables\QueryFolder($this->database);
     $this->view->folders = $sf->find('list', array('user_id' => User::get('id'), 'sort' => 'ordering', 'sort_Dir' => 'asc'));
     // Does the user have any folders?
     if (!count($this->view->folders)) {
         // Get all the default folders
         $this->view->folders = $sf->cloneCore(User::get('id'));
     }
     $sq = new Tables\Query($this->database);
     $queries = $sq->getRecords(array('user_id' => User::get('id'), 'sort' => 'ordering', 'sort_Dir' => 'asc'));
     foreach ($queries as $query) {
         $filters = $this->view->filters;
         if ($query->id != $this->view->filters['show']) {
             $filters['search'] = '';
         }
         $query->query = $sq->getQuery($query->conditions);
         // Get a record count
         $query->count = $obj->getCount($query->query, $filters);
         foreach ($this->view->folders as $k => $v) {
             if (!isset($this->view->folders[$k]->queries)) {
                 $this->view->folders[$k]->queries = array();
             }
             if ($query->folder_id == $v->id) {
                 $this->view->folders[$k]->queries[] = $query;
             }
         }
         if ($query->id == $this->view->filters['show']) {
             // Search
             $this->view->filters['search'] = urldecode(Request::getState($this->_option . '.' . $this->_controller . '.search', 'search', ''));
             // Set the total for the pagination
             $this->view->total = $this->view->filters['search'] ? $obj->getCount($query->query, $this->view->filters) : $query->count;
             // Incoming sort
             $this->view->filters['sort'] = trim(Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', $query->sort));
             $this->view->filters['sortdir'] = trim(Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', $query->sort_dir));
             // Get the records
             $this->view->rows = $obj->getRecords($query->query, $this->view->filters);
         }
     }
     if (!$this->view->filters['show']) {
         // Jump back to the beginning of the folders list
         // and try to find the first query available
         // to make it the current "active" query
         reset($this->view->folders);
         foreach ($this->view->folders as $folder) {
             if (!empty($folder->queries)) {
                 $query = $folder->queries[0];
                 $this->view->filters['show'] = $query->id;
                 break;
             } else {
                 // for no custom queries.
                 $query = new Tables\Query($this->database);
                 $query->count = 0;
             }
         }
         //$folder = reset($this->view->folders);
         //$query = $folder->queries[0];
         // Search
         $this->view->filters['search'] = urldecode(Request::getState($this->_option . '.' . $this->_controller . '.search', 'search', ''));
         // Set the total for the pagination
         $this->view->total = $this->view->filters['search'] ? $obj->getCount($query->query, $this->view->filters) : $query->count;
         // Incoming sort
         $this->view->filters['sort'] = trim(Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', $query->sort));
         $this->view->filters['sortdir'] = trim(Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', $query->sort_dir));
         // Get the records
         $this->view->rows = $obj->getRecords($query->query, $this->view->filters);
     }
     $watching = new Tables\Watching($this->database);
     $this->view->watch = array('open' => $watching->count(array('user_id' => User::get('id'), 'open' => 1)), 'closed' => $watching->count(array('user_id' => User::get('id'), 'open' => 0)));
     if ($this->view->filters['show'] < 0) {
         if (!isset($this->view->filters['sort']) || !$this->view->filters['sort']) {
             $this->view->filters['sort'] = trim(Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'created'));
         }
         if (!isset($this->view->filters['sortdir']) || !$this->view->filters['sortdir']) {
             $this->view->filters['sortdir'] = trim(Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'DESC'));
         }
         $records = $watching->find(array('user_id' => User::get('id'), 'open' => $this->view->filters['show'] == -1 ? 1 : 0));
         if (count($records)) {
             $ids = array();
             foreach ($records as $record) {
                 $ids[] = $record->ticket_id;
             }
             $this->view->rows = $obj->getRecords("(f.id IN ('" . implode("','", $ids) . "'))", $this->view->filters);
         }
     }
     // Set any errors
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     // Output the HTML
     $this->view->display();
 }
예제 #2
0
 /**
  * Get a count of or list of watchers on this ticket
  *
  * @param   string   $rtrn     Data to return state in [count, list]
  * @param   array    $filters  Filters to apply to the query
  * @param   boolean  $clear    Clear data cache?
  * @return  mixed
  */
 public function watchers($rtrn = 'list', $filters = array(), $clear = false)
 {
     if (!isset($filters['ticket_id'])) {
         $filters['ticket_id'] = $this->get('id');
     }
     switch (strtolower($rtrn)) {
         case 'count':
             if (!is_numeric($this->_data->get('watchers.count')) || $clear) {
                 $tbl = new Tables\Watching($this->_db);
                 $this->_data->set('watchers.count', $tbl->count($filters));
             }
             return $this->_data->get('watchers.count');
             break;
         case 'list':
         case 'results':
         default:
             if (!$this->_data->get('watchers.list') instanceof ItemList || $clear) {
                 $tbl = new Tables\Watching($this->_db);
                 if (!($results = $tbl->find($filters))) {
                     $results = array();
                 }
                 $this->_data->set('watchers.list', new ItemList($results));
             }
             return $this->_data->get('watchers.list');
             break;
     }
 }
예제 #3
0
 /**
  * Displays a list of support tickets
  *
  * @return     void
  */
 public function displayTask()
 {
     if (User::isGuest()) {
         $return = base64_encode(Request::getVar('REQUEST_URI', Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=' . $this->_task, false, true), 'server'));
         App::redirect(Route::url('index.php?option=com_users&view=login&return=' . $return, false));
         return;
     }
     $this->view->database = $this->database;
     // Create a Ticket object
     $obj = new Tables\Ticket($this->database);
     $this->view->total = 0;
     $this->view->rows = array();
     $this->view->filters = $this->_getFilters();
     // Paging
     $this->view->filters['limit'] = Request::getState($this->_option . '.' . $this->_controller . '.limit', 'limit', Config::get('list_limit'), 'int');
     $this->view->filters['start'] = Request::getState($this->_option . '.' . $this->_controller . '.limitstart', 'limitstart', 0, 'int');
     // Query to filter by
     $this->view->filters['show'] = Request::getState($this->_option . '.' . $this->_controller . '.show', 'show', 0, 'int');
     // Search
     $this->view->filters['search'] = urldecode(Request::getState($this->_option . '.' . $this->_controller . '.search', 'search', ''));
     // Get query list
     $sf = new Tables\QueryFolder($this->database);
     $sq = new Tables\Query($this->database);
     if (!$this->acl->check('read', 'tickets')) {
         $this->view->folders = $sf->find('list', array('user_id' => 0, 'sort' => 'ordering', 'sort_Dir' => 'asc', 'iscore' => 2));
         $queries = $sq->find('list', array('user_id' => 0, 'sort' => 'ordering', 'sort_Dir' => 'asc', 'iscore' => 4));
     } else {
         $this->view->folders = $sf->find('list', array('user_id' => User::get('id'), 'sort' => 'ordering', 'sort_Dir' => 'asc'));
         // Does the user have any folders?
         if (!count($this->view->folders)) {
             // Get all the default folders
             $this->view->folders = $sf->cloneCore(User::get('id'));
         }
         $queries = $sq->find('list', array('user_id' => User::get('id'), 'sort' => 'ordering', 'sort_Dir' => 'asc'));
     }
     $this->view->filters['sort'] = 'id';
     $this->view->filters['sortdir'] = 'DESC';
     foreach ($queries as $query) {
         $filters = $this->view->filters;
         if ($query->id != $this->view->filters['show']) {
             $filters['search'] = '';
         }
         $query->query = $sq->getQuery($query->conditions);
         // Get a record count
         $query->count = $obj->getCount($query->query, $filters);
         foreach ($this->view->folders as $k => $v) {
             if (!isset($this->view->folders[$k]->queries)) {
                 $this->view->folders[$k]->queries = array();
             }
             if ($query->folder_id == $v->id) {
                 $this->view->folders[$k]->queries[] = $query;
             }
         }
         if ($query->id == $this->view->filters['show']) {
             // Search
             $this->view->filters['search'] = urldecode(Request::getState($this->_option . '.' . $this->_controller . '.search', 'search', ''));
             // Set the total for the pagination
             $this->view->total = $this->view->filters['search'] ? $obj->getCount($query->query, $this->view->filters) : $query->count;
             // Incoming sort
             $this->view->filters['sort'] = trim(Request::getState($this->_option . '.' . $this->_controller . '.sort', 'sort', $query->sort));
             $this->view->filters['sortdir'] = trim(Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'sortdir', $query->sort_dir));
             // Get the records
             $this->view->rows = $obj->getRecords($query->query, $this->view->filters);
         }
     }
     if (!$this->view->filters['show']) {
         // Jump back to the beginning of the folders list
         // and try to find the first query available
         // to make it the current "active" query
         reset($this->view->folders);
         foreach ($this->view->folders as $folder) {
             if (!empty($folder->queries)) {
                 $query = $folder->queries[0];
                 $this->view->filters['show'] = $query->id;
                 break;
             } else {
                 // for no custom queries.
                 $query = new Tables\Query($this->database);
                 $query->count = 0;
             }
         }
         //$folder = reset($this->view->folders);
         //$query = $folder->queries[0];
         // Search
         $this->view->filters['search'] = urldecode(Request::getState($this->_option . '.' . $this->_controller . '.search', 'search', ''));
         // Set the total for the pagination
         $this->view->total = $this->view->filters['search'] ? $obj->getCount($query->query, $this->view->filters) : $query->count;
         // Incoming sort
         $this->view->filters['sort'] = trim(Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', $query->sort));
         $this->view->filters['sortdir'] = trim(Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', $query->sort_dir));
         // Get the records
         $this->view->rows = $obj->getRecords($query->query, $this->view->filters);
     }
     $watching = new Tables\Watching($this->database);
     $this->view->watch = array('open' => $watching->count(array('user_id' => User::get('id'), 'open' => 1)), 'closed' => $watching->count(array('user_id' => User::get('id'), 'open' => 0)));
     if ($this->view->filters['show'] < 0) {
         $records = $watching->find(array('user_id' => User::get('id'), 'open' => $this->view->filters['show'] == -1 ? 1 : 0));
         if (count($records)) {
             $ids = array();
             foreach ($records as $record) {
                 $ids[] = $record->ticket_id;
             }
             $this->view->rows = $obj->getRecords("(f.id IN ('" . implode("','", $ids) . "'))", $this->view->filters);
         } else {
             $this->view->rows = array();
         }
     }
     // Set the page title
     $this->_buildTitle();
     $this->view->title = $this->_title;
     // Set the pathway
     $this->_buildPathway();
     $this->view->acl = $this->acl;
     // Output HTML
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     $this->view->display();
 }