Example #1
0
 /**
  * Method to get tool information
  *
  * @apiMethod GET
  * @apiUri    /tools/{tool}
  * @apiParameter {
  * 		"name":          "tool",
  * 		"description":   "Tool identifier",
  * 		"type":          "string",
  * 		"required":      true,
  * 		"default":       ""
  * }
  * @apiParameter {
  * 		"name":          "version",
  * 		"description":   "Tool version",
  * 		"type":          "string",
  * 		"required":      true,
  * 		"default":       "current"
  * }
  * @return     void
  */
 public function infoTask()
 {
     $database = \App::get('db');
     $tool = Request::getVar('tool', '');
     $version = Request::getVar('version', 'current');
     //we need a tool to continue
     if ($tool == '') {
         throw new Exception(Lang::txt('Tool Alias Required.'), 400);
     }
     //poll database for tool matching alias
     $sql = "SELECT r.id, r.alias, tv.toolname, tv.title, tv.description, tv.toolaccess as access, tv.mw, tv.instance, tv.revision, r.fulltxt as abstract, r.created\n\t\t\t\tFROM #__resources as r, #__tool_version as tv\n\t\t\t\tWHERE r.published=1\n\t\t\t\tAND r.type=7\n\t\t\t\tAND r.standalone=1\n\t\t\t\tAND r.access!=4\n\t\t\t\tAND r.alias=tv.toolname\n\t\t\t\tAND tv.state=1\n\t\t\t\tAND r.alias='{$tool}'\n\t\t\t\tORDER BY revision DESC";
     $database->setQuery($sql);
     $tool_info = $database->loadObject();
     //veryify we have result
     if ($tool_info == null) {
         throw new Exception(Lang::txt('No Tool Found Matching the Alias: "%s"', $tool), 404);
     }
     //add tool alias to tool info from db
     $tool_info->alias = $tool;
     //remove tags and slashes from abastract
     $tool_info->abstract = stripslashes(strip_tags($tool_info->abstract));
     //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';
     $this->rt = new \Components\Resources\Helpers\Tags(0);
     $supportedtagusage = $this->rt->getTagUsage($supportedtag, 'alias');
     $tool_info->supported = in_array($tool_info->alias, $supportedtagusage) ? 1 : 0;
     //get screenshots
     include_once Component::path('com_resources') . DS . 'tables' . DS . 'screenshot.php';
     include_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'version.php';
     $ts = new \Components\Resources\Tables\Screenshot($database);
     $tv = new \Components\Tools\Tables\Version($database);
     $vid = $tv->getVersionIdFromResource($tool_info->id, $version);
     $shots = $ts->getScreenshots($tool_info->id, $vid);
     //get base path
     $path = \Components\Tools\Helpers\Utils::getResourcePath($tool_info->created, $tool_info->id, $vid);
     //add full path to screenshot
     $s = array();
     foreach ($shots as $shot) {
         $s[] = $path . DS . $shot->filename;
     }
     $tool_info->screenshots = $s;
     $object = new stdClass();
     $object->tool = $tool_info;
     $this->send($object);
 }