/** * Get a list of applications that the user might invoke. * * @param array $lst List of tools * @return array List of tools */ private function _getToollist($lst = NULL) { require_once Component::path('com_tools') . DS . 'models' . DS . 'tool.php'; $toollist = array(); // Create a Tool object $database = \App::get('db'); if (is_array($lst)) { $tools = array(); // Check if the list is empty or not if (empty($lst)) { return $tools; } ksort($lst); $items = array(); // Get info for tools in the list foreach ($lst as $item) { if (strstr($item, '_r')) { $bits = explode('_r', $item); $rev = is_array($bits) && count($bits > 1) ? array_pop($bits) : ''; $item = trim(implode('_r', $bits)); } $items[] = $item; } $tools = \Components\Tools\Models\Version::getVersionInfo('', 'current', $items, ''); } else { // Get all available tools $tools = \Components\Tools\Models\Tool::getMyTools(); } $toolnames = array(); // Turn it into an App array. foreach ($tools as $tool) { if (!in_array(strtolower($tool->toolname), $toolnames)) { // include only one version $toollist[strtolower($tool->instance)] = new App($tool->instance, $tool->title, $tool->description, $tool->mw, 0, '', 0, 1, $tool->revision, $tool->toolname); } $toolnames[] = strtolower($tool->toolname); } return $toollist; }
/** * Method to get list of tools * * @apiMethod GET * @apiUri /tools/list * @apiParameter { * "name": "user_id", * "description": "Member identifier", * "type": "integer", * "required": true, * "default": 0 * } * @return void */ public function listTask() { //get the userid and attempt to load user profile $userid = Request::getInt('user_id', 0); $result = User::getInstance($userid); //make sure we have a user //if ($result === false) return $this->not_found(); //instantiate database object $database = \App::get('db'); //get list of tools $tools = \Components\Tools\Models\Tool::getMyTools(); //get the supported tag $rconfig = Component::params('com_resources'); $supportedtag = $rconfig->get('supportedtag', ''); //get supportedtag usage include_once Component::path('com_resources') . DS . 'helpers' . DS . 'tags.php'; $resource_tags = new \Components\Resources\Helpers\Tags(0); $supportedtagusage = $resource_tags->getTagUsage($supportedtag, 'alias'); //create list of tools $t = array(); foreach ($tools as $k => $tool) { if (isset($t[$tool->alias])) { $t[$tool->alias]['versions'][] = $tool->revision; continue; } $t[$tool->alias]['alias'] = $tool->alias; $t[$tool->alias]['title'] = $tool->title; $t[$tool->alias]['description'] = $tool->description; $t[$tool->alias]['versions'] = array($tool->revision); $t[$tool->alias]['supported'] = in_array($tool->alias, $supportedtagusage) ? 1 : 0; } //encode and return result $object = new stdClass(); $object->tools = array_values($t); $this->send($object); }
$assets = array(); foreach ($this->course->offering()->units() as $unit) { foreach ($unit->assetgroups() as $agt) { foreach ($agt->children() as $ag) { $assetgroups[] = array('id' => $ag->get('id'), 'title' => $ag->get('title')); foreach ($ag->assets() as $a) { if ($a->isPublished()) { $a->set('longTitle', $unit->get('title') . ' - ' . $ag->get('title') . ' - ' . $a->get('title')); $assets[] = $a; } } } } } require_once PATH_CORE . DS . 'components' . DS . 'com_tools' . DS . 'models' . DS . 'tool.php'; $tools = \Components\Tools\Models\Tool::getMyTools(); $config = Component::params('com_courses'); $tool_path = $config->get('tool_path'); ?> <div class="edit-asset"> <h3>Edit Asset</h3> <form action="<?php echo Request::base(true); ?> /api/courses/asset/save" method="POST" class="edit-form"> <p> <label for="title">Title:</label> <input type="text" name="title" value="<?php
/** * 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; }
/** * 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; }
/** * Edit an entry version * * @param mixed $row * @return void */ public function editTask($row = null) { Request::setVar('hidemainmenu', 1); // Incoming instance ID $id = Request::getInt('id', 0); $version = Request::getInt('version', 0); // Do we have an ID? if (!$id || !$version) { return $this->cancelTask(); } $this->view->parent = Tool::getInstance($id); if (!is_object($row)) { $row = Version::getInstance($version); } $this->view->row = $row; // Set any errors foreach ($this->getErrors() as $error) { $this->view->setError($error); } // Display results $this->view->setLayout('edit')->display(); }
/** * Set ticket update * * @return void */ public function messageTask() { // get vars if (!$this->_toolid) { $this->_toolid = Request::getInt('toolid', 0); } // do we have an alias? if ($this->_toolid == 0) { if ($alias = Request::getVar('app', '')) { // Create a Tool object $obj = new \Components\Tools\Tables\Tool($this->database); $this->_toolid = $obj->getToolId($alias); } } // 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', ''); $access = Request::getInt('access', 0); $comment = Request::getVar('comment', '', 'post', 'none', 2); if ($newstate && !intval($newstate)) { $newstate = \Components\Tools\Helpers\Html::getStatusNum($newstate); } $hzt = \Components\Tools\Models\Tool::getInstance($this->_toolid); if ($comment) { $this->_newUpdateTicket($hzt->id, $hzt->ticketid, '', '', $comment, $access, 1); $this->_msg = Lang::txt('COM_TOOLS_NOTICE_MSG_SENT'); } $this->statusTask(); }
/** * Display the primary child * For most resources, this will be the first child of a standalone resource * Tools are the only exception in which case the button launches a tool session * * @param string $option Component name * @param object $resource Resource * @param object $firstChild First resource child * @param string $xact Extra parameters to add * @return string */ public static function primary_child($option, $resource, $firstChild, $xact = '') { $database = \App::get('db'); $html = ''; switch ($resource->type) { case 7: $authorized = User::authorise('core.manage', 'com_tools.' . $resource->id); $mconfig = Component::params('com_tools'); // Ensure we have a connection to the middleware if (!$mconfig->get('mw_on') || $mconfig->get('mw_on') > 1 && !$authorized) { $pop = '<p class="warning">' . Lang::txt('COM_RESOURCES_TOOL_SESSION_INVOKE_DISABLED') . '</p>'; $html .= self::primaryButton('link_disabled', '', Lang::txt('COM_RESOURCES_LAUNCH_TOOL'), '', '', '', 1, $pop); return $html; } //get tool params $params = Component::params('com_tools'); $launchOnIpad = $params->get('launch_ipad', 0); // Generate the URL that launches a tool session $lurl = ''; $database = \App::get('db'); $tables = $database->getTableList(); $table = $database->getPrefix() . 'tool_version'; if (in_array($table, $tables)) { if (isset($resource->revision) && $resource->toolpublished) { $sess = $resource->tool ? $resource->tool : $resource->alias . '_r' . $resource->revision; $v = (!isset($resource->revision) or $resource->revision == 'dev') ? 'test' : $resource->revision; $lurl = 'index.php?option=com_tools&app=' . $resource->alias . '&task=invoke&version=' . $v; } elseif (!isset($resource->revision) or $resource->revision == 'dev') { // serve dev version $lurl = 'index.php?option=com_tools&app=' . $resource->alias . '&task=invoke&version=dev'; } } else { $lurl = 'index.php?option=com_tools&task=invoke&app=' . $resource->alias; } require_once PATH_CORE . DS . 'components' . DS . 'com_tools' . DS . 'models' . DS . 'tool.php'; // Create some tool objects $hztv = \Components\Tools\Models\Version::getInstance($resource->tool); $ht = \Components\Tools\Models\Tool::getInstance($hztv->toolid); if ($ht) { // @FIXME: this only seems to fail on hubbub VMs where workspace resource is incomplete/incorrect (bad data in DB?) $toolgroups = $ht->getToolGroupsRestriction($hztv->toolid, $resource->tool); } // Get current users groups $xgroups = \Hubzero\User\Helper::getGroups(User::get('id'), 'members'); $ingroup = false; $groups = array(); if ($xgroups) { foreach ($xgroups as $xgroup) { $groups[] = $xgroup->cn; } // Check if they're in the admin tool group $admingroup = Component::params('com_tools')->get('admingroup'); if ($admingroup && in_array($admingroup, $groups)) { $ingroup = true; } else { if ($toolgroups) { foreach ($toolgroups as $toolgroup) { if (in_array($toolgroup->cn, $groups)) { $ingroup = true; } } } } } if (!User::isGuest() && !$ingroup && $toolgroups) { // see if tool is restricted to a group and if current user is in that group $pop = '<p class="warning">' . Lang::txt('COM_RESOURCES_TOOL_IS_RESTRICTED') . '</p>'; $html .= self::primaryButton('link_disabled', '', Lang::txt('COM_RESOURCES_LAUNCH_TOOL'), '', '', '', 1, $pop); } else { if (isset($resource->revision) && $resource->toolpublished or !isset($resource->revision)) { // dev or published tool //if (User::isGuest()) { // Not logged-in = show message //$html .= self::primaryButton('launchtool disabled', $lurl, Lang::txt('COM_RESOURCES_LAUNCH_TOOL')); //$html .= self::warning('You must <a href="'.Route::url('index.php?option=com_users&view=login').'">log in</a> before you can run this tool.')."\n"; //} else { $pop = User::isGuest() ? '<p class="warning">' . Lang::txt('COM_RESOURCES_TOOL_LOGIN_REQUIRED_TO_RUN') . '</p>' : ''; $pop = $resource->revision == 'dev' ? '<p class="warning">' . Lang::txt('COM_RESOURCES_TOOL_VERSION_UNDER_DEVELOPMENT') . '</p>' : $pop; $html .= self::primaryButton('launchtool', $lurl, Lang::txt('COM_RESOURCES_LAUNCH_TOOL'), '', '', '', 0, $pop); //} } else { // tool unpublished $pop = '<p class="warning">' . Lang::txt('COM_RESOURCES_TOOL_VERSION_UNPUBLISHED') . '</p>'; $html .= self::primaryButton('link_disabled', '', Lang::txt('COM_RESOURCES_LAUNCH_TOOL'), '', '', '', 1, $pop); } } break; case 4: // write primary button and downloads for a Learning Module $html .= self::primaryButton('', Route::url('index.php?option=com_resources&id=' . $resource->id . '&task=play'), 'Start learning module'); break; case 6: case 8: case 31: case 2: // do nothing $mesg = Lang::txt('COM_RESOURCES_VIEW') . ' '; $mesg .= $resource->type == 6 ? 'Course Lectures' : ''; $mesg .= $resource->type == 2 ? 'Workshop ' : ''; $mesg .= $resource->type == 6 ? '' : 'Series'; $html .= self::primaryButton('download', Route::url('index.php?option=com_resources&id=' . $resource->id) . '#series', $mesg, '', $mesg, ''); break; default: $firstChild->title = str_replace('"', '"', $firstChild->title); $firstChild->title = str_replace('&', '&', $firstChild->title); $firstChild->title = str_replace('&', '&', $firstChild->title); $mesg = ''; $class = ''; $action = ''; $xtra = ''; //$lt = new \Components\Resources\Tables\Type($database); //$lt->load($firstChild->logicaltype); $lt = \Components\Resources\Tables\Type::getRecordInstance($firstChild->logicaltype); $ltparams = new \Hubzero\Config\Registry($lt->params); //$rt = new \Components\Resources\Tables\Type($database); //$rt->load($firstChild->type); $rt = \Components\Resources\Tables\Type::getRecordInstance($firstChild->type); $tparams = new \Hubzero\Config\Registry($rt->params); if ($firstChild->logicaltype) { $rtLinkAction = $ltparams->get('linkAction', 'extension'); } else { $rtLinkAction = $tparams->get('linkAction', 'extension'); } switch ($rtLinkAction) { case 'download': $mesg = Lang::txt('COM_RESOURCES_DOWNLOAD'); $class = 'download'; //$action = 'rel="download"'; $linkAction = 3; break; case 'lightbox': $mesg = Lang::txt('COM_RESOURCES_VIEW_RESOURCE'); $class = 'play'; //$action = 'rel="internal"'; $linkAction = 2; break; case 'newwindow': case 'external': $mesg = Lang::txt('COM_RESOURCES_VIEW_RESOURCE'); //$class = 'popup'; $action = 'rel="external"'; $linkAction = 1; break; case 'extension': default: $linkAction = 0; $mediatypes = array('elink', 'quicktime', 'presentation', 'presentation_audio', 'breeze', 'quiz', 'player', 'video_stream', 'video', 'hubpresenter'); $downtypes = array('thesis', 'handout', 'manual', 'software_download'); if (in_array($lt->alias, $downtypes)) { $mesg = Lang::txt('COM_RESOURCES_DOWNLOAD'); $class = 'download'; } elseif (in_array($rt->alias, $mediatypes)) { $mesg = Lang::txt('COM_RESOURCES_VIEW_PRESENTATION'); $mediatypes = array('flash_paper', 'breeze', '32', '26'); if (in_array($firstChild->type, $mediatypes)) { $class = 'play'; } } else { $mesg = Lang::txt('COM_RESOURCES_DOWNLOAD'); $class = 'download'; } if ($firstChild->standalone == 1) { $mesg = Lang::txt('COM_RESOURCES_VIEW_RESOURCE'); $class = ''; //'play'; } if (substr($firstChild->path, 0, 7) == 'http://' || substr($firstChild->path, 0, 8) == 'https://' || substr($firstChild->path, 0, 6) == 'ftp://' || substr($firstChild->path, 0, 9) == 'mainto://' || substr($firstChild->path, 0, 9) == 'gopher://' || substr($firstChild->path, 0, 7) == 'file://' || substr($firstChild->path, 0, 7) == 'news://' || substr($firstChild->path, 0, 7) == 'feed://' || substr($firstChild->path, 0, 6) == 'mms://') { $mesg = Lang::txt('COM_RESOURCES_VIEW_LINK'); } break; } // IF (not a simulator) THEN show the first child as the primary button if ($firstChild->access == 1 && User::isGuest()) { // first child is for registered users only and the visitor is not logged in $pop = '<p class="warning">' . Lang::txt('COM_RESOURCES_LOGIN_REQUIRED_TO_DOWNLOAD') . '</p>' . "\n"; $html .= self::primaryButton($class . ' disabled', Route::url('index.php?option=com_users&view=login'), $mesg, '', '', '', '', $pop); } else { $childParams = new \Hubzero\Config\Registry($firstChild->params); $linkAction = intval($childParams->get('link_action', $linkAction)); $url = self::processPath($option, $firstChild, $resource->id, $linkAction); switch ($linkAction) { case 3: $mesg = Lang::txt('COM_RESOURCES_DOWNLOAD'); $class = 'download'; break; case 2: $mesg = Lang::txt('COM_RESOURCES_VIEW_RESOURCE'); $class = 'play'; break; case 1: $mesg = Lang::txt('COM_RESOURCES_VIEW_RESOURCE'); //$class = 'popup'; $action = 'rel="external"'; break; case 0: default: // Do nothing break; } $attribs = new \Hubzero\Config\Registry($firstChild->attribs); $width = intval($attribs->get('width', 640)); $height = intval($attribs->get('height', 360)); if ($width > 0 && $height > 0) { $class .= ' ' . $width . 'x' . $height; } //$xtra = ''; //if ($firstChild->type == 13 || $firstChild->type == 15 || $firstChild->type == 33) { //$xtra = ' '. self::getFileAttribs($firstChild->path); //} //load a resouce type object on child resource type //$rt = new \Components\Resources\Tables\Type($database); //$rt->load($firstChild->type); //if we are a hubpresenter resource type, do not show file type in button if ($rt->alias == 'hubpresenter') { //$xtra = ""; //$class = "play 1000x600"; $class = 'hubpresenter'; } else { $mesg .= ' ' . self::getFileAttribs($firstChild->path); } if ($rt->alias == 'video') { $class = 'video'; } $pt = \Components\Resources\Tables\Type::getRecordInstance($resource->type); if ($pt->alias == 'databases') { $mesg = "Dataview"; } if ($xact) { $action = $xact; } $html .= self::primaryButton($class, $url, $mesg, $xtra, $firstChild->title, $action); } break; } return $html; }
/** * Short description for 'saveMemberGroups' * * Long description (if any) ... * * @param string $toolid Parameter description (if any) ... * @param array $newgroups Parameter description (if any) ... * @param string $editversion Parameter description (if any) ... * @param array $membergroups Parameter description (if any) ... * @return boolean Return description (if any) ... */ public function saveMemberGroups($toolid = NULL, $newgroups, $editversion = 'dev', $membergroups = array()) { if (!$toolid) { return false; } require_once PATH_CORE . DS . 'components' . DS . 'com_tools' . DS . 'models' . DS . 'tool.php'; $membergroups = \Components\Tools\Models\Tool::getToolGroups($toolid); $membergroups = \Components\Tools\Helpers\Utils::transform($membergroups, 'cn'); $newgroups = \Components\Tools\Helpers\Utils::transform($newgroups, 'cn'); $to_delete = array_diff($membergroups, $newgroups); if (count($to_delete) > 0 && $editversion != 'current') { foreach ($to_delete as $del) { $query = "DELETE FROM {$this->_tbl} WHERE cn=" . $this->_db->quote($del) . " AND toolid=" . $this->_db->quote($toolid) . " AND role=0"; $this->_db->setQuery($query); $this->_db->query(); } } if (count($newgroups) > 0) { foreach ($newgroups as $newgroup) { if (\Hubzero\User\Group::exists($newgroup) && !in_array($newgroup, $membergroups)) { // create an entry in tool_groups table $this->save($newgroup, $toolid, '0'); } } } return true; }
/** * Save an entry * * @return void */ public function saveTask() { Request::checkToken(); // Incoming instance ID $fields = Request::getVar('fields', array(), 'post'); // Do we have an ID? if (!$fields['id']) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_TOOLS_ERROR_MISSING_ID'), 'error'); return; } $row = Tool::getInstance(intval($fields['id'])); if (!$row) { Request::setVar('id', $fields['id']); Notify::error(Lang::txt('COM_TOOLS_ERROR_TOOL_NOT_FOUND')); return $this->editTask(); } $row->title = trim($fields['title']); if (!$row->title) { Notify::error(Lang::txt('COM_TOOLS_ERROR_MISSING_TITLE'), 'error'); return $this->editTask($row); } $row->update(); if ($this->getTask() == 'apply') { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=edit&id=' . $fields['id'], false)); return; } App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_TOOLS_ITEM_SAVED')); }
/** * Publish a tool * * @return void */ public function publishTask() { // Set the layout (note: all the views for this controller use the same layout) $this->view->setLayout('display'); // Create a Tool object $obj = new \Components\Tools\Tables\Tool($this->database); // Do we have an alias? if ($alias = Request::getVar('app', '')) { $this->_toolid = $obj->getToolId($alias); } // Do we have a tool ID if (!$this->_toolid) { App::abort(403, Lang::txt('COM_TOOLS_ERROR_TOOL_NOT_FOUND')); return; } // Get the tool status $obj->getToolStatus($this->_toolid, $this->_option, $status, 'dev'); // Check for a status if (count($status) <= 0) { App::abort(500, Lang::txt('COM_TOOLS_ERR_CANNOT_RETRIEVE')); return; } $result = true; Log::debug("publish(): checkpoint 1:{$result}"); // get config // Create a Tool Version object $objV = new \Components\Tools\Tables\Version($this->database); $objV->getToolVersions($this->_toolid, $tools, '', 1); // make checks if (!is_numeric($status['revision'])) { // bad format $result = false; $this->setError(Lang::txt('COM_TOOLS_ERR_MISSING_REVISION_OR_BAD_FORMAT')); } else { if (count($tools) > 0 && $status['revision']) { // check for duplicate revision foreach ($tools as $t) { if ($t->revision == $status['revision']) { $result = false; $this->setError(Lang::txt('COM_TOOLS_ERR_REVISION_EXISTS') . ' ' . $status['revision']); } } // check that revision number is greater than in previous version $currentrev = $objV->getCurrentVersionProperty($status['toolname'], 'revision'); if ($currentrev && intval($currentrev) > intval($status['revision'])) { $result = false; $this->setError(Lang::txt('COM_TOOLS_ERR_REVISION_GREATER')); } } } // Log checkpoint Log::debug("publish(): checkpoint 2:{$result}, check revision"); // check if version is valid if (!\Components\Tools\Models\Tool::validateVersion($status['version'], $error_v, $this->_toolid)) { $result = false; $this->setError($error_v); } // Log checkpoint Log::debug("publish(): checkpoint 3:{$result}, running finalize tool"); // Run finalizetool if (!$this->getError()) { if ($this->_finalizeTool($out)) { $this->setMessage(Lang::txt('COM_TOOLS_Version finalized.')); } else { $this->setError($out); $result = false; } } Log::debug("publish(): checkpoint 4:{$result}, running doi stuff"); // Register DOI handle if ($result && $this->config->get('new_doi', 0)) { include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'tables' . DS . 'doi.php'; // Collect metadata $url = Request::base() . ltrim(Route::url('index.php?option=com_resources&id=' . $status['resourceid'] . '&rev=' . $status['revision']), DS); // Check if DOI exists for this revision $objDOI = new \Components\Resources\Tables\Doi($this->database); $bingo = $objDOI->getDoi($status['resourceid'], $status['revision'], '', 1); // DOI already exists for this revision if ($bingo) { $this->setError(Lang::txt('COM_TOOLS_ERR_DOI_ALREADY_EXISTS') . ': ' . $bingo); } else { // Get latest DOI label $latestdoi = $objDOI->getLatestDoi($status['resourceid']); $newlabel = $latestdoi ? intval($latestdoi) + 1 : 1; // Collect metadata $metadata = array('targetURL' => $url, 'title' => htmlspecialchars(stripslashes($status['title'])), 'version' => $status['version'], 'abstract' => htmlspecialchars(stripslashes($status['description']))); // Get authors $objA = new \Components\Tools\Tables\Author($this->database); $authors = $objA->getAuthorsDOI($status['resourceid']); // Register DOI $doiSuccess = $objDOI->registerDOI($authors, $this->config, $metadata, $doierr); // Save [new] DOI record if ($doiSuccess) { if (!$objDOI->loadDOI($status['resourceid'], $status['revision'])) { if ($objDOI->saveDOI($status['revision'], $newlabel, $status['resourceid'], $status['toolname'], 0, $doiSuccess)) { $this->setMessage(Lang::txt('COM_TOOLS_SUCCESS_DOI_CREATED') . ' ' . $doiSuccess); } else { $this->setError(Lang::txt('COM_TOOLS_ERR_DOI_STORE_FAILED')); $result = false; } } else { $this->setError(Lang::txt('COM_TOOLS_DOI already exists: ') . $objDOI->doi); } } else { $this->setError(Lang::txt('COM_TOOLS_ERR_DOI_STORE_FAILED')); $this->setError($doierr); $result = false; } } } if ($result) { $invokedir = rtrim($this->config->get('invokescript_dir', DS . 'apps'), "\\/"); $hzt = \Components\Tools\Models\Tool::getInstance($this->_toolid); $hztv_cur = $hzt->getCurrentVersion(); $hztv_dev = $hzt->getDevelopmentVersion(); Log::debug("publish(): checkpoint 6:{$result}, running database stuff"); // create tool instance in the database $newtool = $status['toolname'] . '_r' . $status['revision']; // get version id $currentid = is_object($hztv_cur) ? $hztv_cur->id : null; $new = $currentid ? 0 : 1; $devid = $hztv_dev->id; $exportmap = array('@OPEN' => null, '@GROUP' => null, '@US' => 'us', '@PU' => 'pu', '@D1' => 'd1'); $new_hztv = \Components\Tools\Models\Version::createInstance($status['toolname'], $newtool); $new_hztv->toolname = $status['toolname']; $new_hztv->instance = $newtool; $new_hztv->toolid = $this->_toolid; $new_hztv->state = 1; $new_hztv->title = $status['title']; $new_hztv->version = $status['version']; $new_hztv->revision = $status['revision']; $new_hztv->description = $status['description']; $new_hztv->toolaccess = $status['exec']; $new_hztv->codeaccess = $status['code']; $new_hztv->wikiaccess = $status['wiki']; $new_hztv->vnc_geometry = $status['vncGeometry']; $new_hztv->vnc_command = $invokedir . DS . $status['toolname'] . DS . 'r' . $status['revision'] . DS . 'middleware' . DS . 'invoke -T r' . $status['revision']; $new_hztv->mw = $status['mw']; $new_hztv->released = Date::toSql(); $new_hztv->released_by = User::get('username'); $new_hztv->license = $status['license']; $new_hztv->fulltxt = $status['fulltxt']; $new_hztv->exportControl = $exportmap[strtoupper($status['exec'])]; $new_hztv->owner = $hztv_dev->owner; $new_hztv->member = $hztv_dev->member; $new_hztv->vnc_timeout = $hztv_dev->vnc_timeout; $new_hztv->hostreq = $hztv_dev->hostreq; $new_hztv->params = $status['params']; if (!$new_hztv->update()) { $this->setError(Lang::txt('COM_TOOLS_ERROR_UPDATING_INSTANCE')); $result = false; } else { $this->_setTracAccess($new_hztv->toolname, $new_hztv->codeaccess, $new_hztv->wikiaccess); // update tool entry $hzt = \Components\Tools\Models\Tool::getInstance($this->_toolid); $hzt->add('version', $new_hztv->instance); $hzt->update(); if ($hzt->published != 1) { $hzt->published = 1; // save tool info if (!$hzt->update()) { $this->setError(Lang::txt('COM_TOOLS_ERROR_UPDATING_INSTANCE')); } else { $this->setMessage(Lang::txt('COM_TOOLS_NOTICE_TOOL_MARKED_PUBLISHED')); } } // unpublish previous version if (!$new) { if ($hzt->unpublishVersion($hztv_cur->instance)) { $this->setMessage(Lang::txt('COM_TOOLS_NOTICE_UNPUBLISHED_PREV_VERSION_DB')); } else { $this->setError(Lang::txt('COM_TOOLS_ERR_FAILED_TO_UNPUBLISH_PREV_VERSION_DB')); } } // get version id $currentid = $new_hztv->id; // save authors for this version $objA = new \Components\Tools\Tables\Author($this->database); if ($objA->saveAuthors($status['developers'], $currentid, $status['resourceid'], $status['revision'], $status['toolname'])) { $this->setMessage(Lang::txt('COM_TOOLS_AUTHORS_SAVED')); } else { $this->setError(Lang::txt('COM_TOOLS_ERROR_SAVING_AUTHORS', $currentid)); } // transfer screenshots if ($devid && $currentid) { include_once __DIR__ . DS . 'screenshots.php'; $screenshots = new Screenshots(); if ($screenshots->transfer($devid, $currentid, $status['resourceid'])) { $this->setMessage(Lang::txt('COM_TOOLS_SCREENSHOTS_TRANSFERRED')); } else { $this->setError(Lang::txt('COM_TOOLS_ERROR_TRANSFERRING_SCREENSHOTS')); } } include_once __DIR__ . DS . 'resource.php'; $resource = new Resource(); // update and publish resource page $resource->updatePage($status['resourceid'], $status, '1', $new); } } Log::debug("publish(): checkpoint 7:{$result}, gather output"); // Set errors to view foreach ($this->getErrors() as $error) { $this->view->setError($error); } // Set messages to view $this->view->messages = $this->getMessages(); // Output HTML if (!($no_html = Request::getInt('no_html', 0))) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=pipeline&task=status&app=' . $alias)); return; } $this->view->display(); }