示例#1
0
 /**
  * Short description for 'getToolVersions'
  *
  * Long description (if any) ...
  *
  * @param      string $toolid Parameter description (if any) ...
  * @param      array &$versions Parameter description (if any) ...
  * @param      string $toolname Parameter description (if any) ...
  * @param      integer $exclude_dev Parameter description (if any) ...
  * @return     array Return description (if any) ...
  */
 public function getToolVersions($toolid, &$versions, $toolname = '', $exclude_dev = 0)
 {
     $objA = new \Components\Tools\Tables\Author($this->_db);
     $query = "SELECT v.*, d.* ";
     $query .= "FROM #__tool_version as v LEFT JOIN #__doi_mapping as d ON d.alias = v.toolname AND d.local_revision=v.revision ";
     if ($toolid) {
         $query .= "WHERE v.toolid = " . $this->_db->quote($toolid) . " ";
     } else {
         if ($toolname) {
             $query .= "WHERE v.toolname = " . $this->_db->quote($toolname) . " ";
         }
     }
     if (($toolname or $toolid) && $exclude_dev) {
         $query .= "AND v.state != '3'";
     }
     $query .= " ORDER BY v.state DESC, v.revision DESC";
     $this->_db->setQuery($query);
     $versions = $this->_db->loadObjectList();
     if ($versions) {
         require_once PATH_CORE . DS . 'components' . DS . 'com_tools' . DS . 'models' . DS . 'tool.php';
         foreach ($versions as $version) {
             // get list of authors
             if ($version->state != 3) {
                 $version->authors = $objA->getToolAuthors($version->id);
             } else {
                 $rid = \Components\Tools\Models\Tool::getResourceId($version->toolid);
                 $version->authors = $objA->getToolAuthors('dev', $rid);
             }
         }
     }
     return $versions;
 }
示例#2
0
 /**
  * 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;
 }
示例#3
0
 /**
  * Update a tool version
  *
  * @return     void
  */
 public function updateTask()
 {
     // get vars
     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);
         }
     }
     if (!$this->_error) {
         $this->_error = Request::getVar('error', '');
     }
     $error = '';
     //$id = $this->_toolid;
     // make sure user is authorized to go further
     if (!$this->_checkAccess($this->_toolid)) {
         App::abort(403, Lang::txt('COM_TOOLS_ALERTNOTAUTH'));
         return;
     }
     $newstate = Request::getVar('newstate', '');
     $priority = Request::getVar('priority', 3);
     $comment = Request::getVar('comment', '');
     $access = Request::getInt('access', 0);
     $newversion = Request::getVar('newversion', '');
     $editversion = Request::getVar('editversion', 'dev');
     $hzt = \Components\Tools\Models\Tool::getInstance($this->_toolid);
     $hztv = $hzt->getRevision($editversion);
     $oldstatus = $hztv ? $hztv->toArray() : array();
     $oldstatus['toolstate'] = $hzt->state;
     if ($newstate && !intval($newstate)) {
         $newstate = \Components\Tools\Helpers\Html::getStatusNum($newstate);
     }
     if (intval($newstate) && $newstate != $oldstatus['toolstate']) {
         Log::debug(__FUNCTION__ . "() state changing");
         if ($newstate == \Components\Tools\Helpers\Html::getStatusNum('Approved') && \Components\Tools\Models\Tool::validateVersion($oldstatus['version'], $error, $hzt->id)) {
             $this->_error = $error;
             Log::debug(__FUNCTION__ . "() state changing to approved, action confirm");
             $this->_action = 'confirm';
             $this->_task = Lang::txt('COM_TOOLS_CONTRIBTOOL_APPROVE_TOOL');
             $this->versionsTask();
             return;
         } else {
             if ($newstate == \Components\Tools\Helpers\Html::getStatusNum('Approved')) {
                 $this->_error = $error;
                 Log::debug(__FUNCTION__ . "() state changing to approved, action new");
                 $this->_action = 'new';
                 $this->_task = Lang::txt('COM_TOOLS_CONTRIBTOOL_APPROVE_TOOL');
                 $this->versionsTask();
                 return;
             } else {
                 if ($newstate == \Components\Tools\Helpers\Html::getStatusNum('Published')) {
                     Log::debug(__FUNCTION__ . "() state changing to published");
                     $hzt->published = '1';
                 }
             }
         }
         $this->_error = $error;
         // update dev screenshots of a published tool changes status
         if ($oldstatus['state'] == \Components\Tools\Helpers\Html::getStatusNum('Published')) {
             // Create a Tool Version object
             $objV = new \Components\Tools\Tables\Version($this->database);
             Log::debug(__FUNCTION__ . "() state changing away from  published");
             // Get version ids
             $rid = \Components\Tools\Models\Tool::getResourceId($hzt->toolname, $hzt->id);
             $to = $objV->getVersionIdFromResource($rid, 'dev');
             $from = $objV->getVersionIdFromResource($rid, 'current');
             $dev_hztv = $hzt->getRevision('dev');
             $current_hztv = $hzt->getRevision('current');
             Log::debug("update: to={$to} from={$from}   dev=" . $dev_hztv->id . " current=" . $current_hztv->id);
             if ($to && $from) {
                 require_once __DIR__ . DS . 'screenshots.php';
                 $ss = new Screenshots();
                 $ss->transfer($from, $to, $rid);
             }
         }
         // If the tool was cancelled ...
         if ($oldstatus['state'] == \Components\Tools\Helpers\Html::getStatusNum('Abandoned')) {
             include_once __DIR__ . DS . 'resource.php';
             $r = new \Components\Resources\Tables\Resource($this->database);
             $r->loadAlias($hzt->toolname);
             if ($r && $r->id) {
                 $rstatus = 2;
                 if ($newstate == \Components\Tools\Helpers\Html::getStatusNum('Published')) {
                     $rstatus = 1;
                 }
                 $resource = new Resource();
                 $resource->updatePage($r->id, $oldstatus, $rstatus);
             }
         }
         Log::debug(__FUNCTION__ . "() state changing to {$newstate}");
         $hzt->state = $newstate;
         $hzt->state_changed = Date::toSql();
     }
     // if priority changes
     if (intval($priority) && $priority != $oldstatus['priority']) {
         $hzt->priority = $priority;
     }
     // save tool info
     $hzt->update();
     $hztv->update();
     //@FIXME: look
     // get tool status after updates
     $status = $hztv->toArray();
     $status['toolstate'] = $hzt->state;
     // update history ticket
     Log::debug(__FUNCTION__ . "() before newUpdateTicket test");
     if ($oldstatus != $status || !empty($comment)) {
         Log::debug(__FUNCTION__ . "() before newUpdateTicket");
         $this->_newUpdateTicket($hzt->id, $hzt->ticketid, $oldstatus, $status, $comment, $access, 1);
         Log::debug(__FUNCTION__ . "() after newUpdateTicket");
     }
     $this->_msg = Lang::txt('COM_TOOLS_NOTICE_STATUS_CHANGED');
     $this->statusTask();
 }