Beispiel #1
0
 /**
  * Constructor
  *
  * @param      integer $id  Resource ID or alias
  * @param      object  &$db JDatabase
  * @return     void
  */
 public function __construct($oid, $revision = null)
 {
     $this->_db = \App::get('db');
     $this->resource = new Tables\Resource($this->_db);
     $this->resource->load($oid);
     $this->params = Component::params('com_resources');
     $this->params->merge(new \Hubzero\Config\Registry($this->resource->params));
     $this->attribs = new \Hubzero\Config\Registry($this->resource->attribs);
     if ($this->isTool()) {
         $this->thistool = null;
         $this->curtool = null;
         $tables = $this->_db->getTableList();
         $table = $this->_db->getPrefix() . 'tool_version';
         if (in_array($table, $tables)) {
             $tv = new \Components\Tools\Tables\Version($this->_db);
             //$tv->getToolVersions('', $alltools, $this->resource->alias);
             if ($this->revisions()) {
                 foreach ($this->revisions() as $tool) {
                     // Archive version, if requested
                     if ($revision && $tool->revision == $revision && $revision != 'dev' or $revision == 'dev' and $tool->state == 3) {
                         $this->thistool = $tool;
                     }
                     // Current version
                     if ($tool->state == 1 && (count($this->revisions()) == 1 || count($this->revisions()) > 1 && $this->revisions(1)->version == $tool->version)) {
                         $this->curtool = $tool;
                         $revision = $revision ? $revision : $tool->revision;
                     }
                     // Dev version
                     if (!$revision && count($this->revisions()) == 1 && $tool->state == 3) {
                         $this->thistool = $tool;
                         $revision = 'dev';
                     }
                 }
                 if (!$this->thistool && !$this->curtool && count($this->revisions()) > 1) {
                     // Tool is retired, display latest unpublished version
                     $this->thistool = $this->revisions(1);
                     $revision = $this->thistool->revision;
                 }
                 // If the revision is the same as the current version
                 if ($this->curtool && $this->thistool && $this->thistool == $this->curtool) {
                     // Display default resource page for current version
                     $this->thistool = null;
                 }
             }
             $tconfig = Component::params('com_tools');
             // Replace resource info with requested version
             $tv->compileResource($this->thistool, $this->curtool, $this->resource, $revision, $tconfig);
         }
         $this->revision = $revision;
     }
     $this->type = new Tables\Type($this->_db);
     $this->type->bind($this->types($this->resource->type));
     $this->type->params = new \Hubzero\Config\Registry($this->type->params);
 }
Beispiel #2
0
 /**
  * Preview the resource
  *
  * @return     void
  */
 public function previewTask()
 {
     // Incoming
     $alias = Request::getVar('app', '');
     $version = Request::getVar('editversion', 'dev');
     $rid = Request::getInt('rid', 0);
     // Load the tool
     $obj = new \Components\Tools\Tables\Tool($this->database);
     $this->_toolid = $obj->getToolId($alias);
     if (!$this->_toolid) {
         // not a tool resource page
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=pipeline'));
         return;
     }
     // Make sure user is authorized to go further
     if (!$this->_checkAccess($this->_toolid)) {
         App::abort(403, Lang::txt('COM_TOOLS_ALERTNOTAUTH'));
         return;
     }
     // Get tool version (dev or current) information
     $obj->getToolStatus($this->_toolid, $this->_option, $status, $version);
     // Instantiate our tag object
     $tagcloud = new \Components\Resources\Helpers\Tags($rid);
     $tags = Request::getVar('tags', '', 'post');
     $tagfa = Request::getVar('tagfa', '', 'post');
     // Process new tags
     $newtags = '';
     if ($tagfa) {
         $newtags = $tagfa . ', ';
     }
     if ($tags) {
         $newtags .= $tags;
     }
     $tagcloud->setTags($newtags, User::get('id'));
     // Get some needed libraries
     include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'html.php';
     // Load the resource object
     $resource = new \Components\Resources\Tables\Resource($this->database);
     $resource->loadAlias($alias);
     if (!User::isGuest()) {
         $xgroups = \Hubzero\User\Helper::getGroups(User::get('id'), 'all');
         // Get the groups the user has access to
         $usersgroups = $this->_getUsersGroups($xgroups);
     } else {
         $usersgroups = array();
     }
     // Get updated version
     $objV = new \Components\Tools\Tables\Version($this->database);
     $thistool = $objV->getVersionInfo('', $version, $resource->alias, '');
     $thistool = $thistool ? $thistool[0] : '';
     // Replace resource info with requested version
     $objV->compileResource($thistool, '', $resource, 'dev', $this->rconfig);
     // get language library
     $lang = Lang::getRoot();
     if (!$lang->load(strtolower('com_resources'), JPATH_BASE)) {
         $this->setError(Lang::txt('COM_TOOLS_ERROR_LOADING_LANGUAGE'));
     }
     // Set the document title
     $this->view->title = Lang::txt(strtoupper($this->_option)) . ': ' . Lang::txt('COM_TOOLS_PREVIEW_TOOL_PAGE') . ' (' . $resource->alias . ')';
     Document::setTitle($this->view->title);
     // Set the document pathway (breadcrumbs)
     if (Pathway::count() <= 0) {
         Pathway::append(Lang::txt(strtoupper($this->_name)), 'index.php?option=' . $this->_option);
     }
     if (Pathway::count() <= 1) {
         Pathway::append(Lang::txt('COM_TOOLS_STATUS_FOR', $thistool->toolname), 'index.php?option=' . $this->_option . '&controller=pipeline&task=status&app=' . $alias);
         Pathway::append(Lang::txt('COM_TOOLS_EDIT_TOOL_PAGE'), 'index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&app=' . $alias . '&task=start&step=1');
     }
     $this->view->toolid = $this->_toolid;
     $this->view->step = 5;
     $this->view->version = $version;
     $this->view->resource = $resource;
     $this->view->config = $this->rconfig;
     $this->view->usersgroups = $usersgroups;
     $this->view->status = $status;
     // Pass error messages to the view
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     // Output HTML
     $this->view->display();
 }