/** * Constructor. * * @param JInput $input The input object. * @param JApplicationBase $app The application object. */ public function __construct(JInput $input = null, JApplicationBase $app = null) { parent::__construct($input, $app); // Use the default database. $this->setDatabase(); // Set the controller options. $serviceOptions = array('contentType' => 'application/vnd.joomla.item.v1; schema=weblinks.v1', 'describedBy' => 'http://docs.joomla.org/Schemas/weblinks/v1', 'primaryRel' => 'joomla:weblinks', 'resourceMap' => __DIR__ . '/resource.json', 'self' => '/joomla:weblinks/' . (int) $this->input->get('id'), 'tableName' => '#__weblinks'); $this->setOptions($serviceOptions); }
/** * Constructor. * * @param JInput $input The input object. * @param JApplicationBase $app The application object. */ public function __construct(JInput $input = null, JApplicationBase $app = null) { parent::__construct($input, $app); // Use the default database. $this->setDatabase(); // Set the controller options. $serviceOptions = array('contentType' => 'application/vnd.joomla.item.v1; schema=articles.v1', 'describedBy' => 'http://docs.joomla.org/Schemas/articles/v1', 'primaryRel' => 'joomla:articles', 'resourceMap' => __DIR__ . '/resource.json', 'tableName' => '#__content', 'tableClass' => 'Content'); $this->setOptions($serviceOptions); }
/** * Constructor. * * @param JInput $input The input object. * @param JApplicationBase $app The application object. */ public function __construct(JInput $input = null, JApplicationBase $app = null) { parent::__construct($input, $app); jimport('joomla.filesystem.file'); // Use the default database. $this->_db = JFactory::getDBO(); // Set the controller options. $serviceOptions = array('contentType' => 'application/vnd.joomla.item.v1; schema=webservices.v1', 'describedBy' => 'http://docs.joomla.org/Schemas/articles/v1', 'primaryRel' => 'webservices:time', 'resourceMap' => __DIR__ . '/resource.json', 'self' => '/webservices:time/'); // Set the service options $this->setOptions($serviceOptions); }
/** * Get database query. * * May be overridden in child classes. * * @param string $table Primary table name. * * @return JDatabaseDriver object. */ public function getQuery($table) { // Get the user $user = $this->app->getIdentity(); // Get the base query. $query = parent::getQuery($table); // Filter by access level. if ($user->guest != 1) { $groups = implode(',', $user->getAuthorisedViewLevels()); $query->where('access IN (' . $groups . ')'); } else { if ($user->guest == 1) { $query->where('access = 1'); } } return $query; }
/** * Execute the request. */ public function execute() { // Get resource item id from input. $this->id = (int) $this->input->get('id'); // Get resource item data. $data = $this->getData(); // Get service object. $service = $this->getService(); // We need to add a link from the current category to the content items that // exist within the category. However, we only know the name of the extension // and not the resource name used by the API. We try to work out the correct // entry to make by doing a reverse-lookup on the router maps. if (isset($data->extension)) { // Get the component name (without the com_ prefix). $extension = str_replace('com_', '', $data->extension); // Get the router maps. $maps = $this->app->getMaps(); // Construct the regex pattern of the route we want to find. $pattern = '#component/' . $extension . '/(.*)List#'; // Look for an appropriate route. foreach ($maps as $rel => $route) { if (substr($rel, 0, 17) == 'joomla:categories') { // Look for a match for our route. $matches = array(); preg_match($pattern, $route, $matches); if (!empty($matches)) { // Add a link to the resources associated with the category. $linkRel = 'joomla:' . strtolower($matches[1]); $linkHref = '/' . str_replace(':catid', $this->id, $rel); $service->addLink(new ApiApplicationHalLink($linkRel, $linkHref)); } } } } // Load the data into the HAL object. $service->load($data); parent::execute(); }