Skip to content
Snippets Groups Projects
Commit 34125461 authored by damjan's avatar damjan
Browse files

[FEATURE] Getting the data of a type(properties and super type)

parent 6f935d23
No related branches found
No related tags found
No related merge requests found
......@@ -26,18 +26,27 @@ class TsrefController extends \TYPO3\Flow\Mvc\Controller\ActionController {
}
/**
* The action which fetches initial data for typoScript reference page, and displays the page.
* The action which fetches the data for typoScript reference page, and displays the page.
*
* @param string $typeId
* @param int $typeId
* @param null $superTypeId
* @return void
*/
public function indexAction($typeId = NULL) {
public function indexAction($typeId = NULL, $superTypeId = NULL) {
$attributes = $this->tsrefRestService->getTypes();
if($typeId !== NULL) {
if ($typeId !== NULL) {
//TODO: fetch all data for attribute with id: $typeId
$properties = $this->tsrefRestService->getPropertiesByParentId($typeId);
$this->view->assign('properties', $properties);
}
if ($superTypeId !== NULL) {
//TODO: fetch all data for attribute with id: $typeId
$superType = $this->tsrefRestService->getAttributeById($superTypeId);
$this->view->assign('superType', $superType);
}
$this->view->assign('types', $attributes);
$this->view->assign('typeId', $typeId);
$this->view->assign('types', $attributes);
$this->view->assign('typeId', $typeId);
}
}
\ No newline at end of file
......@@ -26,9 +26,10 @@ class TsrefRestService {
* Makes curl handle, sets some general options and returns the handle.
* It also checks if cURL is installed.
*
* @param string $suffix
* @return resource
*/
protected function initialiseCurl() {
protected function initialiseCurl($suffix = '') {
// is cURL installed yet?
if (!function_exists('curl_init')) {
throw new \RuntimeException('Sorry cURL is not installed. Install cURL.');
......@@ -37,7 +38,7 @@ class TsrefRestService {
$curlHandle = curl_init();
// Set URL to download
curl_setopt($curlHandle, CURLOPT_URL, self::RESOURCE_URL);
curl_setopt($curlHandle, CURLOPT_URL, self::RESOURCE_URL . $suffix);
// Should cURL return or print out the data? (true = return, false = print)
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, TRUE);
......@@ -78,6 +79,66 @@ class TsrefRestService {
return $output;
}
/**
* Returns an attribute by its ID from RESOURCE_URL.
*
* @param int $attributeId
* @return mixed
*/
public function getAttributeByIdJson($attributeId) {
$curlHandle = $this->initialiseCurl('/' . $attributeId);
// Download the given URL, and return output
$output = curl_exec($curlHandle);
// Close the cURL resource, and free system resources
curl_close($curlHandle);
return $output;
}
/**
* Returns properties of a type (attribute which is a type) by its ID from RESOURCE_URL/ID/properties.
*
* @param int $attributeId
* @return mixed
*/
public function getPropertiesByParentIdJson($attributeId) {
$curlHandle = $this->initialiseCurl('/' . $attributeId . '/properties');
// Download the given URL, and return output
$output = curl_exec($curlHandle);
// Close the cURL resource, and free system resources
curl_close($curlHandle);
return $output;
}
/**
* Gets all type attributes by $typo3Version and $typo3Group from RESOURCE_URL
*
* @param int $attributeId
* @return mixed
*/
public function getAttributeById($attributeId) {
$attributeJson = $this->getPropertiesByParentIdJson($attributeId);
$attributePhp = json_decode($attributeJson);
return $attributePhp;
}
/**
* Gets all type attributes by $typo3Version and $typo3Group from RESOURCE_URL
*
* @param int $attributeId
* @return mixed
*/
public function getPropertiesByParentId($attributeId) {
$propertiesJson = $this->getPropertiesByParentIdJson($attributeId);
$propertiesPhp = json_decode($propertiesJson);
return $propertiesPhp;
}
/**
* Gets all type attributes by $typo3Version and $typo3Group from RESOURCE_URL
*
......
......@@ -21,6 +21,18 @@
</div>
<div class="col-sm-9">
test {typeId}
<f:if condition="{properties}">
<ul>
<f:for each="{properties}" as="property">
<li>
<f:link.action package="SGalinski.TypoScriptReferenceFrontend" controller="tsref" action="index"
arguments="{typeId: property.property.type_id}">
{property.property.name} {property.type_name}
</f:link.action>
</li>
</f:for>
</ul>
</f:if>
</div>
</f:section>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment