/** * Get a list of tools * * @param integer $show_questions Show question count for tool * @param integer $show_wishes Show wish count for tool * @param integer $show_tickets Show ticket count for tool * @param string $limit_tools Number of records to pull * @return mixed False if error, otherwise array */ private function _getToollist($show_questions, $show_wishes, $show_tickets, $limit_tools = '40') { $database = \App::get('db'); // Query filters defaults $filters = array(); $filters['sortby'] = 'f.published DESC'; $filters['filterby'] = 'all'; include_once Component::path('com_tools') . DS . 'tables' . DS . 'tool.php'; require_once Component::path('com_tools') . DS . 'models' . DS . 'tool.php'; // Create a Tool object $rows = \Components\Tools\Models\Tool::getTools($filters, false); $limit = 100000; if ($rows) { for ($i = 0; $i < count($rows); $i++) { // What is resource id? $rid = \Components\Tools\Models\Tool::getResourceId($rows[$i]->id); $rows[$i]->rid = $rid; // Get questions, wishes and tickets on published tools if ($rows[$i]->published == 1 && $i <= $limit_tools) { if ($show_questions) { // Get open questions require_once Component::path('com_answers') . DS . 'tables' . DS . 'question.php'; require_once Component::path('com_answers') . DS . 'tables' . DS . 'response.php'; $aq = new \Components\Answers\Tables\Question($database); $filters = array('limit' => $limit, 'start' => 0, 'filterby' => 'open', 'sortby' => 'date', 'mine' => 0, 'tag' => 'tool' . $rows[$i]->toolname); $results = $aq->getResults($filters); $unanswered = 0; if ($results) { foreach ($results as $r) { if ($r->rcount == 0) { $unanswered++; } } } $rows[$i]->q = count($results); $rows[$i]->q_new = $unanswered; } if ($show_wishes) { // Get open wishes require_once Component::path('com_wishlist') . DS . 'site' . DS . 'controllers' . DS . 'wishlists.php'; require_once Component::path('com_wishlist') . DS . 'tables' . DS . 'wish.php'; require_once Component::path('com_wishlist') . DS . 'tables' . DS . 'wishlist.php'; $objWishlist = new \Components\Wishlist\Tables\Wishlist($database); $objWish = new \Components\Wishlist\Tables\Wish($database); $listid = $objWishlist->get_wishlistID($rid, 'resource'); $rows[$i]->w = 0; $rows[$i]->w_new = 0; if ($listid) { $controller = new \Components\Wishlist\Site\Controllers\Wishlists(); $filters = $controller->getFilters(1); $wishes = $objWish->get_wishes($listid, $filters, 1, User::getRoot()); $unranked = 0; if ($wishes) { foreach ($wishes as $w) { if ($w->ranked == 0) { $unranked++; } } } $rows[$i]->w = count($wishes); $rows[$i]->w_new = $unranked; } } if ($show_tickets) { // Get open tickets $group = $rows[$i]->devgroup; // Find support tickets on the user's contributions $database->setQuery("SELECT id, summary, category, status, severity, owner, created, login, name,\n\t\t\t\t\t\t\t (SELECT COUNT(*) FROM `#__support_comments` as sc WHERE sc.ticket=st.id AND sc.access=0) as comments\n\t\t\t\t\t\t\t FROM `#__support_tickets` as st WHERE (st.status=0 OR st.status=1) AND type=0 AND st.group='{$group}'\n\t\t\t\t\t\t\t ORDER BY created DESC\n\t\t\t\t\t\t\t LIMIT {$limit}"); $tickets = $database->loadObjectList(); if ($database->getErrorNum()) { echo $database->stderr(); return false; } $unassigned = 0; if ($tickets) { foreach ($tickets as $t) { if ($t->comments == 0 && $t->status == 0 && !$t->owner) { $unassigned++; } } } $rows[$i]->s = count($tickets); $rows[$i]->s_new = $unassigned; } } } } return $rows; }
/** * Retrieves a user's questions * * @param string $kind The kind of results to retrieve * @param array $interests Array of tags * @return array Database results */ private function _getQuestions($kind = 'open', $interests = array()) { $database = \App::get('db'); // Get some classes we need require_once Component::path('com_answers') . DS . 'models' . DS . 'question.php'; require_once Component::path('com_answers') . DS . 'tables' . DS . 'response.php'; require_once Component::path('com_answers') . DS . 'tables' . DS . 'log.php'; require_once Component::path('com_answers') . DS . 'tables' . DS . 'questionslog.php'; require_once Component::path('com_answers') . DS . 'helpers' . DS . 'economy.php'; $aq = new \Components\Answers\Tables\Question($database); if ($this->banking) { $AE = new \Components\Answers\Helpers\Economy($database); $BT = new \Hubzero\Bank\Transaction($database); } $params =& $this->params; $moduleclass = $params->get('moduleclass'); $limit = intval($params->get('limit', 10)); $limit = $limit ? $limit : 10; $filters = array('limit' => $limit, 'start' => 0, 'tag' => '', 'filterby' => 'open', 'sortby' => 'date'); switch ($kind) { case 'mine': $filters['mine'] = 1; $filters['sortby'] = 'responses'; break; case 'assigned': $filters['mine'] = 0; require_once Component::path('com_tools') . DS . 'tables' . DS . 'author.php'; $TA = new \Components\Tools\Tables\Author($database); $tools = $TA->getToolContributions(User::get('id')); if ($tools) { foreach ($tools as $tool) { $filters['tag'] .= 'tool' . $tool->toolname . ','; } } if (!$filters['tag']) { $filters['filterby'] = 'none'; } break; case 'interest': $filters['mine'] = 0; $interests = count($interests) <= 0 ? $this->_getInterests() : $interests; $filters['filterby'] = !$interests ? 'none' : 'open'; $filters['tag'] = $interests; break; } $results = $aq->getResults($filters); if ($this->banking && $results) { $awards = array(); foreach ($results as $result) { // Calculate max award $result->marketvalue = round($AE->calculate_marketvalue($result->id, 'maxaward')); $result->maxaward = round(2 * ($result->marketvalue / 3)); if ($kind != 'mine') { $result->maxaward = $result->maxaward + $result->reward; } $awards[] = $result->maxaward ? $result->maxaward : 0; } // re-sort by max reponses array_multisort($awards, SORT_DESC, $results); } foreach ($results as $k => $result) { $results[$k] = new \Components\Answers\Models\Question($result); } return $results; }
/** * Display a list of questions * * @apiMethod GET * @apiUri /answers/questions/list * @apiParameter { * "name": "limit", * "description": "Number of result to return.", * "required": false, * "default": 25 * } * @apiParameter { * "name": "start", * "description": "Number of where to start returning results.", * "required": false, * "default": 0 * } * @apiParameter { * "name": "search", * "description": "A word or phrase to search for.", * "required": false, * "default": "" * } * @apiParameter { * "name": "sort", * "description": "Field to sort results by.", * "required": false, * "default": "created", * "allowedValues": "created, title, alias, id, publish_up, publish_down, state" * } * @apiParameter { * "name": "sort_Dir", * "description": "Direction to sort results by.", * "required": false, * "default": "desc", * "allowedValues": "asc, desc" * } * @return void */ public function listTask() { $database = \App::get('db'); $model = new \Components\Answers\Tables\Question($database); $filters = array('limit' => Request::getInt('limit', 25), 'start' => Request::getInt('limitstart', 0), 'search' => Request::getVar('search', ''), 'filterby' => Request::getword('filterby', ''), 'sortby' => Request::getWord('sort', 'date'), 'sort_Dir' => strtoupper(Request::getWord('sortDir', 'DESC'))); $response = new stdClass(); $response->questions = array(); $response->total = $model->getCount($filters); if ($response->total) { $base = rtrim(Request::base(), '/'); foreach ($model->getResults($filters) as $i => $q) { $question = new \Components\Answers\Models\Question($q); $obj = new stdClass(); $obj->id = $question->get('id'); $obj->subject = $question->subject(); $obj->quesion = $question->content(); $obj->state = $question->get('state'); $obj->url = str_replace('/api', '', $base . '/' . ltrim(Route::url($question->link()), '/')); $obj->responses = $question->comments('count'); $response->questions[] = $obj; } } $response->success = true; $this->send($response); }
/** * Display the status of the current app * * @return void */ public function statusTask() { $this->view->setLayout('status'); if (!$this->_toolid) { $this->_toolid = Request::getInt('toolid', 0); } // Create a Tool object $obj = new \Components\Tools\Tables\Tool($this->database); // do we have an alias? if ($this->_toolid == 0) { if ($alias = Request::getVar('app', '')) { $this->_toolid = $obj->getToolId($alias); } } // Couldn't get ID, exit if (!$this->_toolid) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller)); return; } if (!$this->_error) { $this->_error = ''; } if (!$this->_msg) { $this->_msg = Request::getVar('msg', '', 'post'); } // check access rights if (!$this->_checkAccess($this->_toolid)) { App::abort(403, Lang::txt('COM_TOOLS_ALERTNOTAUTH')); return; } // get tool status $obj->getToolStatus($this->_toolid, $this->_option, $status, 'dev'); if (!$status) { App::abort(404, Lang::txt('COM_TOOLS_ERR_STATUS_CANNOT_FIND')); return; } // get tickets/wishes/questions if ($status['published']) { $status['questions'] = 'N/A'; if (Component::isEnabled('com_answers')) { require_once PATH_CORE . DS . 'components' . DS . 'com_answers' . DS . 'tables' . DS . 'question.php'; require_once PATH_CORE . DS . 'components' . DS . 'com_answers' . DS . 'tables' . DS . 'response.php'; require_once PATH_CORE . DS . 'components' . DS . 'com_answers' . DS . 'tables' . DS . 'log.php'; require_once PATH_CORE . DS . 'components' . DS . 'com_answers' . DS . 'tables' . DS . 'questionslog.php'; $aq = new \Components\Answers\Tables\Question($this->database); $status['questions'] = $aq->getCount(array('filterby' => 'all', 'sortby' => 'date', 'tag' => 'tool' . $status['toolname'])); } $status['wishes'] = 'N/A'; if (Component::isEnabled('com_wishlist')) { require_once PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'models' . DS . 'wishlist.php'; require_once PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'site' . DS . 'controllers' . DS . 'wishlists.php'; $objWishlist = new \Components\Wishlist\Tables\Wishlist($this->database); $objWish = new \Components\Wishlist\Tables\Wish($this->database); $listid = $objWishlist->get_wishlistID($status['resourceid'], 'resource'); if ($listid) { $controller = new \Components\Wishlist\Controllers\Wishlist(); $filters = $controller->getFilters(1); $wishes = $objWish->get_wishes($listid, $filters, 1, User::getRoot()); $status['wishes'] = count($wishes); } else { $status['wishes'] = 0; } } } $this->view->status = $status; $this->view->msg = isset($this->_msg) ? $this->_msg : ''; $this->view->config = $this->config; $this->view->admin = $this->config->get('access-admin-component'); // Set the page title $this->view->title = Lang::txt(strtoupper($this->_option)) . ': ' . Lang::txt(strtoupper($this->_option . '_' . $this->_task)); $this->view->title .= $status['toolname'] ? ' ' . Lang::txt('COM_TOOLS_FOR') . ' ' . $status['toolname'] : ''; Document::setTitle($this->view->title); if (Pathway::count() <= 0) { Pathway::append(Lang::txt(strtoupper($this->_option)), 'index.php?option=' . $this->_option); } Pathway::append(Lang::txt('COM_TOOLS_PIPELINE'), 'index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=pipeline'); Pathway::append(Lang::txt('COM_TOOLS_STATUS_FOR', $status['toolname']), 'index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=status&app=' . $status['toolname']); foreach ($this->getErrors() as $error) { $this->view->setError($error); } $this->view->display(); }