/** * 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 . 'models' . DS . 'question.php'; $results = \Components\Answers\Models\Question::all()->including(['responses', function ($response) { $response->select('id')->select('question_id')->where('state', '!=', 2); }])->whereEquals('state', 0)->select('#__answers_questions.*')->join('#__tags_object', '#__tags_object.objectid', '#__answers_questions.id')->join('#__tags', '#__tags.id', '#__tags_object.tagid')->whereEquals('#__tags_object.tbl', 'answers')->whereIn('#__tags.tag', ['tool' . $rows[$i]->toolname])->limit($limit)->ordered()->rows(); $unanswered = 0; if ($results) { foreach ($results as $r) { if ($r->responses->count() == 0) { $unanswered++; } } } $rows[$i]->q = $results->count(); $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::getInstance()); $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; }