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

[FEATURE] (IN PROGRESS) URL with typeName and getting type by name from rest service

parent 7cba618f
No related branches found
No related tags found
No related merge requests found
......@@ -45,13 +45,17 @@ class TsrefController extends \TYPO3\Flow\Mvc\Controller\ActionController {
/**
* The action which fetches the data for typoScript reference page, and displays the page.
*
* @param int $typeId
* @param string $typeName
* @param string $typo3Version
*/
public function indexAction($typeId = NULL, $typo3Version = TsrefRestService::TYPO3_CURRENT_VERSION_LABEL) {
if ($typeId !== NULL) {
$selectedType = $this->tsrefRestService->getAttributeById($typeId);
$properties = $this->tsrefRestService->getPropertiesByParentId($typeId);
public function indexAction($typeName = NULL, $typo3Version = TsrefRestService::TYPO3_CURRENT_VERSION_LABEL) {
echo ' called! name: ' . $typeName . ";\n";
if ($typeName !== NULL) {
$selectedType = $this->tsrefRestService->getTypeByName($typeName);
echo " Last error: " . json_last_error() . "\n";
var_dump($selectedType);
echo 'type id: ' . $selectedType->id . "\n";die();
$properties = $this->tsrefRestService->getPropertiesByParentId($selectedType->id);
$this->view->assign('properties', $properties);
$this->view->assign('selectedType', $selectedType);
......@@ -63,7 +67,7 @@ class TsrefController extends \TYPO3\Flow\Mvc\Controller\ActionController {
}
// $account = $this->securityContext->getAccount(); // TODO: Check if user is admin, view helper can be used
$this->prepareTypeMenu($typeId, $typo3Version);
$this->prepareTypeMenu((isset($selectedType) ? $selectedType->id : NULL), $typo3Version);
}
/**
......
......@@ -16,7 +16,7 @@ class TsrefRestService {
/**
* URL of REST API resource.
*/
const RESOURCE_URL = '127.0.0.1:8000/api/attributes';
const RESOURCE_URL = '127.0.0.1:8000/api';
/**
* Default typo3 version of typoScript attributes.
......@@ -38,14 +38,14 @@ class TsrefRestService {
* @param string $suffix
* @return resource
*/
protected function initialiseCurl($suffix = '') {
protected function initialiseCurl($suffix = '/attributes') {
// is cURL installed yet?
if (!function_exists('curl_init')) {
throw new \RuntimeException('Sorry cURL is not installed. Install cURL.');
}
$curlHandle = curl_init();
echo "URL: " . self::RESOURCE_URL . $suffix . "\n";
// Set URL to download
curl_setopt($curlHandle, CURLOPT_URL, self::RESOURCE_URL . $suffix);
......@@ -100,7 +100,7 @@ class TsrefRestService {
* @return mixed JSON
*/
public function getAttributeByIdJson($attributeId) {
$curlHandle = $this->initialiseCurl('/' . $attributeId);
$curlHandle = $this->initialiseCurl('/attributes/' . $attributeId);
// Download the given URL, and return output
$output = curl_exec($curlHandle);
......@@ -111,6 +111,36 @@ class TsrefRestService {
return $output;
}
/**
* Returns a type by its name from RESOURCE_URL.
*
* @param string $typeName
* @return mixed JSON
*/
public function getTypeByNameJson($typeName) {
$curlHandle = $this->initialiseCurl('/types/' . $typeName);
// Download the given URL, and return output
$output = curl_exec($curlHandle);
// Close the cURL resource, and free system resources
curl_close($curlHandle);
echo 'rest returned: ' . $output . "\n";
return $output;
}
/**
* Gets type by name.
*
* @param string $typeName
* @return \stdClass
*/
public function getTypeByName($typeName) {
$typeJson = $this->getTypeByNameJson($typeName);
$typePhp = json_decode($typeJson);
return $typePhp;
}
/**
* Returns properties of a type (attribute which is a type) by its ID from RESOURCE_URL/ID/properties.
*
......@@ -118,7 +148,7 @@ class TsrefRestService {
* @return mixed
*/
public function getPropertiesByParentIdJson($attributeId) {
$curlHandle = $this->initialiseCurl('/' . $attributeId . '/properties');
$curlHandle = $this->initialiseCurl('/attributes/' . $attributeId . '/properties');
// Download the given URL, and return output
$output = curl_exec($curlHandle);
......@@ -210,7 +240,7 @@ class TsrefRestService {
);
}
$attributeJson = json_encode($attribute->toArray(TRUE));
$curlHandle = $this->initialiseCurl('/' . $attribute->getId());
$curlHandle = $this->initialiseCurl('/attributes/' . $attribute->getId());
curl_setopt($curlHandle, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt(
......@@ -244,7 +274,7 @@ class TsrefRestService {
);
}
$dataJson = json_encode($data);
$curlHandle = $this->initialiseCurl('/' . $id);
$curlHandle = $this->initialiseCurl('/attributes/' . $id);
curl_setopt($curlHandle, CURLOPT_CUSTOMREQUEST, 'PATCH');
curl_setopt(
......@@ -299,7 +329,7 @@ class TsrefRestService {
* @return array
*/
public function getTypesWithNull($typo3Version) {
$typesAssociative =Conversion::toAssociativeIdNamesArray($this->getTypes(TRUE, $typo3Version));
$typesAssociative = Conversion::toAssociativeIdNamesArray($this->getTypes(TRUE, $typo3Version));
$typesAssociative = [-1 => 'No type (NULL)'] + $typesAssociative;
return $typesAssociative;
}
......
-
name: 'Used for viewing the data'
uriPattern: '{@controller}/{typeId}/{typo3Version}'
uriPattern: '{@controller}/{typeName}/{typo3Version}'
defaults:
'typo3Version': 'current'
'typeId': NULL
'typeName': NULL
'@action': 'index'
'@controller': 'Tsref'
'@package': 'SGalinski.TypoScriptReferenceFrontend'
......@@ -26,7 +26,7 @@
uriPattern: '{@controller}'
defaults:
'typo3Version': 'current'
'typeId': NULL
'typeName': NULL
'@action': 'index'
'@controller': 'Tsref'
'@package': 'SGalinski.TypoScriptReferenceFrontend'
......
......@@ -22,7 +22,7 @@
<f:for each="{types}" as="typeName" key="typeId">
<li class="{f:if(condition: '{selectedTypeId} == {typeId}', then: 'active')}">
<f:link.action package="SGalinski.TypoScriptReferenceFrontend" controller="tsref" action="index"
arguments="{typeId: typeId, typo3Version: selectedTypo3Version}">
arguments="{typeName: typeName, typo3Version: selectedTypo3Version}">
{typeName}
<f:if condition="{selectedTypeId} == {typeId}">
<span class="sr-only">(current)</span>
......
......@@ -50,7 +50,7 @@
</f:then>
<f:else>
<f:link.action package="SGalinski.TypoScriptReferenceFrontend" controller="tsref" action="index"
arguments="{typeId: selectedType.parent_id, typo3Version: selectedTypo3Version}">
arguments="{typeName: superType.name, typo3Version: selectedTypo3Version}">
{superType.name}
</f:link.action>
</f:else>
......@@ -110,7 +110,7 @@
</f:then>
<f:else>
<f:link.action package="SGalinski.TypoScriptReferenceFrontend" controller="tsref" action="index"
arguments="{typeId: propertyIterator.property.type_id, typo3Version: selectedTypo3Version}">
arguments="{typeName: propertyIterator.type_name, typo3Version: selectedTypo3Version}">
{propertyIterator.type_name}
</f:link.action>
</f:else>
......
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