Tdt\Core\Formatters\FormatHelper::getAvailableFormats PHP Method

getAvailableFormats() public method

Return a list of the available formats that the data structure can be formatted into
public getAvailableFormats ( Tdt\Core\Datasets\Data $data ) : array
$data Tdt\Core\Datasets\Data
return array
    public function getAvailableFormats($data)
    {
        return $this->getFormatsForType($data->source_definition);
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Retrieve a Data object identified by $uri
  *
  * @param string $uri The identifier that identifies a resource
  *
  * @return \Response
  */
 public function get($uri)
 {
     // Check permissions
     Auth::requirePermissions('dataset.view');
     // Split for an (optional) extension
     list($uri, $extension) = $this->processURI($uri);
     // Check for caching
     // Based on: URI / Rest parameters / Query parameters / Paging headers
     $cache_string = $uri;
     list($limit, $offset) = Pager::calculateLimitAndOffset();
     $cache_string .= '/limit=' . $limit . 'offset=' . $offset;
     $cache_string .= http_build_query(\Input::except('limit', 'offset', 'page', 'page_size'));
     $cache_string = sha1($cache_string);
     if (Cache::has($cache_string)) {
         return ContentNegotiator::getResponse(Cache::get($cache_string), $extension);
     } else {
         // Get definition
         $definition = $this->definition->getByIdentifier($uri);
         if ($definition) {
             // Get source definition
             $source_definition = $this->definition->getDefinitionSource($definition['source_id'], $definition['source_type']);
             if ($source_definition) {
                 $source_type = $source_definition['type'];
                 // Create the right datacontroller
                 $controller_class = 'Tdt\\Core\\DataControllers\\' . $source_type . 'Controller';
                 $data_controller = \App::make($controller_class);
                 // Get REST parameters
                 $rest_parameters = str_replace($definition['collection_uri'] . '/' . $definition['resource_name'], '', $uri);
                 $rest_parameters = ltrim($rest_parameters, '/');
                 $rest_parameters = explode('/', $rest_parameters);
                 if (empty($rest_parameters[0]) && !is_numeric($rest_parameters[0])) {
                     $rest_parameters = array();
                 }
                 // Retrieve dataobject from datacontroller
                 $data = $data_controller->readData($source_definition, $rest_parameters);
                 $data->rest_parameters = $rest_parameters;
                 // REST filtering
                 if ($source_type != 'INSTALLED' && count($data->rest_parameters) > 0) {
                     $data->data = self::applyRestFilter($data->data, $data->rest_parameters);
                 }
                 // Add definition to the object
                 $data->definition = $definition;
                 // Add source definition to the object
                 $data->source_definition = $source_definition;
                 // Add the available, supported formats to the object
                 $format_helper = new FormatHelper();
                 $data->formats = $format_helper->getAvailableFormats($data);
                 // Store in cache
                 Cache::put($cache_string, $data, $source_definition['cache']);
                 // Return the formatted response with content negotiation
                 return ContentNegotiator::getResponse($data, $extension);
             } else {
                 \App::abort(404, "Source for the definition could not be found.");
             }
         } else {
             // Coulnd't find a definition, but it might be a collection
             $resources = $this->definition->getByCollection($uri);
             if (count($resources) > 0) {
                 $data = new Data();
                 $data->data = new \stdClass();
                 $data->data->datasets = array();
                 $data->data->collections = array();
                 foreach ($resources as $res) {
                     // Check if it's a subcollection or a dataset
                     $collection_uri = rtrim($res['collection_uri'], '/');
                     if ($collection_uri == $uri) {
                         array_push($data->data->datasets, \URL::to($collection_uri . '/' . $res['resource_name']));
                     } else {
                         // Push the subcollection if it's not already in the array
                         if (!in_array(\URL::to($collection_uri), $data->data->collections)) {
                             array_push($data->data->collections, \URL::to($collection_uri));
                         }
                     }
                 }
                 // Fake a definition
                 $data->definition = new \Definition();
                 $uri_array = explode('/', $uri);
                 $last_chunk = array_pop($uri_array);
                 $data->definition->collection_uri = join('/', $uri_array);
                 $data->definition->resource_name = $last_chunk;
                 // Return the formatted response with content negotiation
                 return ContentNegotiator::getResponse($data, $extension);
             } else {
                 \App::abort(404, "The dataset or collection you were looking for could not be found (URI: {$uri}).");
             }
         }
     }
 }
All Usage Examples Of Tdt\Core\Formatters\FormatHelper::getAvailableFormats