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

[TASK] Splitting Attribute table on Property and Type

parent dae1abb5
No related branches found
No related tags found
No related merge requests found
Showing
with 464 additions and 322 deletions
......@@ -8,6 +8,8 @@ namespace SGalinski\TypoScriptReferenceFrontend\Controller;
* */
use SGalinski\TypoScriptReferenceFrontend\Domain\Model\Attribute;
use SGalinski\TypoScriptReferenceFrontend\Domain\Model\Property;
use SGalinski\TypoScriptReferenceFrontend\Domain\Model\Type;
use SGalinski\TypoScriptReferenceFrontend\Service\TsrefRestService;
use SGalinski\TypoScriptReferenceFrontend\Utilities\Conversion;
use TYPO3\Flow\Annotations as Flow;
......@@ -62,7 +64,7 @@ class TsrefController extends \TYPO3\Flow\Mvc\Controller\ActionController {
if ($typeUrlName !== NULL) {
$selectedType = $this->tsrefRestService->getTypeByUrlName($typeUrlName);
$this->session->putData('typoScriptGroup', $selectedType->typo3Group);
$properties = $this->tsrefRestService->getPropertiesByParentId(
$properties = $this->tsrefRestService->getPropertiesByParentTypeId(
$selectedType->id, $this->decodeTypo3Version($typo3Version), $selectedType->typo3Group
);
......@@ -72,7 +74,7 @@ class TsrefController extends \TYPO3\Flow\Mvc\Controller\ActionController {
// If the type extends a type (superType), the superType name is being fetched among other fields
if (isset($selectedType->parent_id)) {
$superType = $this->tsrefRestService->getAttributeById($selectedType->parent_id);
$superType = $this->tsrefRestService->getTypeById($selectedType->parent_id);
$this->view->assign('superType', $superType);
}
}
......@@ -87,25 +89,25 @@ class TsrefController extends \TYPO3\Flow\Mvc\Controller\ActionController {
/**
* Adds a new type or saves changes in edited type.
*
* @param Attribute $theType
* @param Type $theType
* @param boolean $editForm
* @param string $typo3Version
* @throws \TYPO3\Flow\Mvc\Exception\ForwardException
* @return void
*/
public function submitTypeAction( //TODO: Use session for typo3Version
Attribute $theType, $editForm = NULL, $typo3Version = TsrefRestService::TYPO3_CURRENT_VERSION_LABEL
Type $theType, $editForm = NULL, $typo3Version = TsrefRestService::TYPO3_CURRENT_VERSION_LABEL
) {
try {
$this->checkEditPermission($typo3Version);
if ($theType->getParent() === -1) {
$theType->setParent(NULL);
if ($theType->getExtends() === -1) {
$theType->setExtends(NULL);
}
if ($editForm) {
$result = $this->tsrefRestService->editAttribute($theType);
$result = $this->tsrefRestService->editType($theType);
} else {
$result = $this->tsrefRestService->addNewAttribute($theType);
$result = $this->tsrefRestService->addNewType($theType);
}
$this->addFlashMessage('The type is successfully submitted.', 'Success', Message::SEVERITY_OK);
......@@ -135,7 +137,7 @@ class TsrefController extends \TYPO3\Flow\Mvc\Controller\ActionController {
*/
public function editTypeAction($typeId = NULL, $typo3Version = TsrefRestService::TYPO3_CURRENT_VERSION_LABEL
) { //TODO: Use session for typo3Version
$theType = new Attribute();
$theType = new Type();
try {
$this->checkEditPermission($typo3Version);
......@@ -143,8 +145,8 @@ class TsrefController extends \TYPO3\Flow\Mvc\Controller\ActionController {
if ($typeId !== NULL) {
// Edit type
$selectedTypeAsStdClass = $this->tsrefRestService->getAttributeById($typeId);
$theType->initialiseAttribute($selectedTypeAsStdClass);
$selectedTypeAsStdClass = $this->tsrefRestService->getTypeById($typeId);
$theType->initialise($selectedTypeAsStdClass);
} else {
$theType->setTypo3Group($typoScriptGroup);
}
......@@ -172,34 +174,34 @@ class TsrefController extends \TYPO3\Flow\Mvc\Controller\ActionController {
/**
* Adds a new property or saves the changes in edited property.
*
* @param Attribute $theProperty
* @param Property $theProperty
* @param boolean $editForm
* @param string $typo3Version
* @throws \TYPO3\Flow\Mvc\Exception\ForwardException
* @return void
*/
public function submitPropertyAction( //TODO: Use session for typo3Version
Attribute $theProperty, $editForm, $typo3Version = TsrefRestService::TYPO3_CURRENT_VERSION_LABEL
Property $theProperty, $editForm, $typo3Version = TsrefRestService::TYPO3_CURRENT_VERSION_LABEL
) {
$parentType = NULL;
try {
$this->checkEditPermission($typo3Version);
if ($editForm) {
$result = $this->tsrefRestService->editAttribute($theProperty);
$result = $this->tsrefRestService->editProperty($theProperty);
} else {
$result = $this->tsrefRestService->addNewAttribute($theProperty);
$result = $this->tsrefRestService->addNewProperty($theProperty);
}
$this->addFlashMessage('The property is successfully submitted.', 'Success', Message::SEVERITY_OK);
$parentType = $this->tsrefRestService->getAttributeById($theProperty->getParent());
$parentType = $this->tsrefRestService->getTypeById($theProperty->getParentType());
} catch (\Exception $exception) {
$this->addFlashMessage($exception->getMessage(), 'Error', Message::SEVERITY_ERROR);
$this->redirect(
'editProperty', 'tsref', 'SGalinski.TypoScriptReferenceFrontend',
['parentTypeId' => $theProperty->getParent(), 'thePropertyId' => $theProperty->getId(),
['parentTypeId' => $theProperty->getParentType(), 'thePropertyId' => $theProperty->getId(),
'typo3Version' => $typo3Version]
);
}
......@@ -226,21 +228,21 @@ class TsrefController extends \TYPO3\Flow\Mvc\Controller\ActionController {
try {
$this->checkEditPermission($typo3Version);
$theProperty = new Attribute();
$theProperty = new Property();
$typoScriptGroup = (int) $this->session->getData('typoScriptGroup');
if ($thePropertyId !== NULL) {
// Edit type
$selectedPropertyAsStdClass = $this->tsrefRestService->getAttributeById($thePropertyId);
$theProperty->initialiseAttribute($selectedPropertyAsStdClass);
$selectedPropertyAsStdClass = $this->tsrefRestService->getPropertyById($thePropertyId);
$theProperty->initialise($selectedPropertyAsStdClass);
} else {
$theProperty->setTypo3Group($typoScriptGroup);
}
$theProperty->setParent($parentTypeId);
$parentType = $this->tsrefRestService->getAttributeById($parentTypeId);
$theProperty->setParentType($parentTypeId);
$parentType = $this->tsrefRestService->getTypeById($parentTypeId);
$selectMenuTypes = Conversion::attributesToAssociativeIdArray(
$selectMenuTypes = Conversion::typesToAssociativeIdArray(
$this->tsrefRestService->getTypes(TRUE, $this->decodeTypo3Version($typo3Version), NULL)
);
......@@ -257,9 +259,33 @@ class TsrefController extends \TYPO3\Flow\Mvc\Controller\ActionController {
}
/**
* Deletes attribute by $attributeId.
* If the attribute is a type, $parentTypeUrlName should be NULL.
* If the attribute is a property, $parentTypeUrlName should be specified,
* Deletes type by $attributeId.
*
* @param int $attributeId
* @param string $typo3Version
* @return void
*/
public function deleteTypeAction( //TODO: Use session for typo3Version
$attributeId, $typo3Version = TsrefRestService::TYPO3_CURRENT_VERSION_LABEL
) {
try {
$this->checkEditPermission($typo3Version);
$result = $this->tsrefRestService->patchType($attributeId, ['deleted' => TRUE]);
$this->addFlashMessage('Successfully deleted.', 'Success', Message::SEVERITY_OK);
} catch (\Exception $exception) {
$this->addFlashMessage($exception->getMessage(), 'Error', Message::SEVERITY_ERROR);
}
$this->redirect(
'index', 'tsref', 'SGalinski.TypoScriptReferenceFrontend',
['typeUrlName' => NULL, 'typo3Version' => $typo3Version]
);
}
/**
* Deletes property by $attributeId.
* $parentTypeUrlName should be specified,
* and then that type will be presented after deletion of the property.
*
* @param int $attributeId
......@@ -267,12 +293,12 @@ class TsrefController extends \TYPO3\Flow\Mvc\Controller\ActionController {
* @param string $typo3Version
* @return void
*/
public function deleteAttributeAction( //TODO: Use session for typo3Version
public function deletePropertyAction( //TODO: Use session for typo3Version
$attributeId, $parentTypeUrlName = NULL, $typo3Version = TsrefRestService::TYPO3_CURRENT_VERSION_LABEL
) {
try {
$this->checkEditPermission($typo3Version, $parentTypeUrlName);
$result = $this->tsrefRestService->patchAttribute($attributeId, ['deleted' => TRUE]);
$result = $this->tsrefRestService->patchProperty($attributeId, ['deleted' => TRUE]);
$this->addFlashMessage('Successfully deleted.', 'Success', Message::SEVERITY_OK);
} catch (\Exception $exception) {
......
......@@ -5,7 +5,7 @@ namespace SGalinski\TypoScriptReferenceFrontend\Domain\Model;
/**
* Attribute
*/
class Attribute {
abstract class Attribute {
/**
* Constant used in $typo3Group field.
*/
......@@ -59,41 +59,11 @@ class Attribute {
*/
private $typo3Group = Attribute::NORMAL_GROUP;
/**
* @var int
*/
private $type;
/**
* @var int
*/
private $parent;
// /**
// * @var ArrayCollection
// */
// private $children;
/**
* @var string
*/
private $default;
/**
* @var boolean
*/
private $isType;
/**
* @var boolean
*/
private $deleted = FALSE;
/**
* @var string
*/
private $category;
/**
* @param int $id
*/
......@@ -233,78 +203,6 @@ class Attribute {
return $this->typo3Group;
}
/**
* Set parent
*
* @param int $parent
* @return Attribute
*/
public function setParent($parent) {
$this->parent = $parent;
return $this;
}
/**
* Get parent id.
*
* @return int
*/
public function getParent() {
return $this->parent;
}
// /**
// * Set children
// *
// * @param ArrayCollection $children
// * @return Attribute
// */
// public function setChildren($children) {
// $this->children = $children;
//
// return $this;
// }
//
// /**
// * Get children
// *
// * @return ArrayCollection
// */
// public function getChildren() {
// return $this->children;
// }
//
// /**
// * Adds one child to the list.
// *
// * @param Attribute $child
// */
// public function addChild(Attribute $child) {
// $this->children[] = $child;
// }
/**
* Set isType
*
* @param boolean $isType
* @return Attribute
*/
public function setIsType($isType) {
$this->isType = $isType;
return $this;
}
/**
* Get isType
*
* @return boolean
*/
public function getIsType() {
return $this->isType;
}
/**
* Set deleted
*
......@@ -326,57 +224,6 @@ class Attribute {
return $this->deleted;
}
/**
* @return int
*/
public function getType() {
return $this->type;
}
/**
* @param int $type
* @return Attribute
*/
public function setType($type) {
$this->type = $type;
return $this;
}
/**
* @return string
*/
public function getDefault() {
return $this->default;
}
/**
* @param string $default
* @return Attribute
*/
public function setDefault($default) {
$this->default = $default;
return $this;
}
/**
* @return string
*/
public function getCategory() {
return $this->category;
}
/**
* @param string $category
* @return Attribute
*/
public function setCategory($category) {
$this->category = $category;
return $this;
}
/**
* Writes object properties to associative array. NULL and not-set properties are ignored.
*
......@@ -406,24 +253,13 @@ class Attribute {
if (isset($this->maxVersion)) {
$attributeArray ['maxVersion'] = $this->maxVersion;
}
if (isset($this->parent)) {
$attributeArray ['parent'] = $this->parent;
}
if (isset($this->type)) {
$attributeArray ['type'] = $this->type;
}
if (isset($this->typo3Group)) {
$attributeArray ['typo3Group'] = $this->typo3Group;
}
if (isset($this->deleted)) {
$attributeArray ['deleted'] = $this->deleted;
}
if (isset($this->isType)) {
$attributeArray ['isType'] = $this->isType;
}
if (isset($this->category)) {
$attributeArray ['category'] = $this->category;
}
return $attributeArray;
}
......@@ -432,7 +268,7 @@ class Attribute {
*
* @param \stdClass $attribute
*/
public function initialiseAttribute(\stdClass $attribute) {
public function initialise(\stdClass $attribute) {
if (isset($attribute->id)) {
$this->id = $attribute->id;
} else {
......@@ -453,11 +289,6 @@ class Attribute {
} else {
$this->description = NULL;
}
if (isset($attribute->default)) {
$this->default = $attribute->default;
} else {
$this->default = NULL;
}
if (isset($attribute->minVersion)) {
$this->minVersion = $attribute->minVersion;
} else {
......@@ -468,16 +299,6 @@ class Attribute {
} else {
$this->maxVersion = NULL;
}
if (isset($attribute->parent_id)) {
$this->parent = $attribute->parent_id;
} else {
$this->parent = NULL;
}
if (isset($attribute->type_id)) {
$this->type = $attribute->type_id;
} else {
$this->type = NULL;
}
if (isset($attribute->typo3Group)) {
$this->typo3Group = $attribute->typo3Group;
} else {
......@@ -488,15 +309,5 @@ class Attribute {
} else {
$this->deleted = NULL;
}
if (isset($attribute->isType)) {
$this->isType = $attribute->isType;
} else {
$this->isType = NULL;
}
if (isset($attribute->category)) {
$this->category = $attribute->category;
} else {
$this->category = NULL;
}
}
}
<?php
namespace SGalinski\TypoScriptReferenceFrontend\Domain\Model;
/**
* Property
*/
class Property extends Attribute {
/**
* @var int
*/
private $type;
/**
* @var int
*/
private $parentType;
/**
* @var int
*/
private $parentProperty;
/**
* @var string
*/
private $default;
/**
* Set parentType
*
* @param int $parentType
* @return Property
*/
public function setParentType($parentType) {
$this->parentType = $parentType;
return $this;
}
/**
* Get parentType id.
*
* @return int
*/
public function getParentType() {
return $this->parentType;
}
/**
* @return int
*/
public function getParentProperty() {
return $this->parentProperty;
}
/**
* @param int $parentProperty
* @return Property
*/
public function setParentProperty($parentProperty) {
$this->parentProperty = $parentProperty;
return $this;
}
/**
* @return int
*/
public function getType() {
return $this->type;
}
/**
* @param int $type
* @return Attribute
*/
public function setType($type) {
$this->type = $type;
return $this;
}
/**
* @return string
*/
public function getDefault() {
return $this->default;
}
/**
* @param string $default
* @return Attribute
*/
public function setDefault($default) {
$this->default = $default;
return $this;
}
/**
* Writes object properties to associative array. NULL and not-set properties are ignored.
*
* @param bool $ignoreId - if TRUE, id is not added to the array
* @return array
*/
public function toArray($ignoreId = FALSE) {
$propertyArray = parent::toArray($ignoreId);
if (isset($this->default)) {
$propertyArray ['default'] = $this->default;
}
if (isset($this->parentType)) {
$propertyArray ['parentType'] = $this->parentType;
}
if (isset($this->parentProperty)) {
$propertyArray ['parentProperty'] = $this->parentProperty;
}
if (isset($this->type)) {
$propertyArray ['type'] = $this->type;
}
return $propertyArray;
}
/**
* Initialises the attribute from the stdClass argument.
*
* @param \stdClass $attribute
*/
public function initialise(\stdClass $attribute) {
parent::initialise($attribute);
if (isset($attribute->default)) {
$this->default = $attribute->default;
} else {
$this->default = NULL;
}
if (isset($attribute->parent_type_id)) {
$this->parentType = $attribute->parent_type_id;
} else {
$this->parentType = NULL;
}
if (isset($attribute->parent_property_id)) {
$this->parentProperty = $attribute->parent_property_id;
} else {
$this->parentProperty = NULL;
}
if (isset($attribute->type_id)) {
$this->type = $attribute->type_id;
} else {
$this->type = NULL;
}
}
}
<?php
namespace SGalinski\TypoScriptReferenceFrontend\Domain\Model;
/**
* Type
*/
class Type extends Attribute {
/**
* @var int
*/
private $extends;
/**
* @var string
*/
private $category;
/**
* @return int
*/
public function getExtends() {
return $this->extends;
}
/**
* @param int $extends
* @return Type
*/
public function setExtends($extends) {
$this->extends = $extends;
return $this;
}
/**
* @return string
*/
public function getCategory() {
return $this->category;
}
/**
* @param string $category
* @return Type
*/
public function setCategory($category) {
$this->category = $category;
return $this;
}
/**
* Writes object properties to associative array. NULL and not-set properties are ignored.
*
* @param bool $ignoreId - if TRUE, id is not added to the array
* @return array
*/
public function toArray($ignoreId = FALSE) {
$typeArray = parent::toArray($ignoreId);
if (isset($this->category)) {
$typeArray ['category'] = $this->category;
}
if (isset($this->extends)) {
$typeArray ['extends'] = $this->extends;
}
return $typeArray;
}
/**
* Initialises the type from the stdClass argument.
*
* @param \stdClass $type
*/
public function initialise(\stdClass $type) {
parent::initialise($type);
if (isset($type->category)) {
$this->category = $type->category;
} else {
$this->category = NULL;
}
if (isset($type->extends)) {
$this->extends = $type->extends;
} else {
$this->extends = NULL;
}
}
}
......@@ -3,6 +3,8 @@
namespace SGalinski\TypoScriptReferenceFrontend\Service;
use SGalinski\TypoScriptReferenceFrontend\Domain\Model\Attribute;
use SGalinski\TypoScriptReferenceFrontend\Domain\Model\Property;
use SGalinski\TypoScriptReferenceFrontend\Domain\Model\Type;
use SGalinski\TypoScriptReferenceFrontend\Utilities\Conversion;
use TYPO3\Flow\Annotations as Flow;
......@@ -14,8 +16,8 @@ use TYPO3\Flow\Annotations as Flow;
*/
class TsrefRestService {
/**
* Default typo3 version of typoScript attributes.
* Filtering by this version (very high number) will fetch attributes of current version.
* Default typo3 version of typoScript types and properties.
* Filtering by this version (very high number) will fetch properties and types of current version.
*/
const TYPO3_DEFAULT_VERSION = '99999';
......@@ -46,7 +48,7 @@ class TsrefRestService {
* @param string $suffix
* @return resource
*/
protected function initialiseCurl($suffix = '/attributes') {
protected function initialiseCurl($suffix) {
// is cURL installed yet?
if (!function_exists('curl_init')) {
throw new \RuntimeException('Sorry cURL is not installed. Install cURL.');
......@@ -66,10 +68,10 @@ class TsrefRestService {
}
/**
* Fetches attributes from web resource: RESOURCE_URL.
* Fetches types from web resource: RESOURCE_URL.
*
* @param boolean|null $isType - filters by isType
* @param bool $namesOnly - get urlNames and names only of attributes.
* @param bool $namesOnly - get urlNames and names only of types.
* @param string $typo3Version - filters by typo3Version
* @param int $typo3Group - filters by typo3Group
* @return mixed
......@@ -78,7 +80,7 @@ class TsrefRestService {
$isType = NULL, $namesOnly = TRUE, $typo3Version = self::TYPO3_DEFAULT_VERSION,
$typo3Group = Attribute::NORMAL_GROUP
) {
$curlHandle = $this->initialiseCurl();
$resourceName = 'properties';
$headerProperties = [
'namesonly: ' . ($namesOnly ? '1' : '0'),
......@@ -87,8 +89,9 @@ class TsrefRestService {
];
if ($isType !== NULL) {
$headerProperties[] = 'istype: ' . ($isType ? '1' : '0');
$resourceName = 'types';
}
$curlHandle = $this->initialiseCurl('/' . $resourceName);
curl_setopt($curlHandle, CURLOPT_HTTPHEADER, $headerProperties);
......@@ -104,13 +107,14 @@ class TsrefRestService {
}
/**
* Returns an attribute by its ID from RESOURCE_URL.
* Returns a property\type by its ID from RESOURCE_URL.
*
* @param string $resourceName ('properties' or 'types')
* @param int $attributeId
* @return mixed JSON
*/
public function getAttributeByIdJson($attributeId) {
$curlHandle = $this->initialiseCurl('/attributes/' . $attributeId);
public function getAttributeByIdJson($resourceName, $attributeId) {
$curlHandle = $this->initialiseCurl('/' . $resourceName . '/' . $attributeId);
// Download the given URL, and return output
$output = curl_exec($curlHandle);
......@@ -130,7 +134,7 @@ class TsrefRestService {
* @return mixed JSON
*/
public function getTypeByUrlNameJson($typeUrlName) {
$curlHandle = $this->initialiseCurl('/types/' . $typeUrlName);
$curlHandle = $this->initialiseCurl('/types/' . $typeUrlName . '/byurlname');
// Download the given URL, and return output
$output = curl_exec($curlHandle);
......@@ -156,17 +160,17 @@ class TsrefRestService {
}
/**
* Returns properties of a type (attribute which is a type) by its ID from RESOURCE_URL/ID/properties.
* Returns properties of a type by its ID from RESOURCE_URL/propertiesID/byparenttype.
*
* @param int $attributeId
* @param int $typeId
* @param string $typo3Version
* @param int $typo3Group
* @return mixed
*/
public function getPropertiesByParentIdJson(
$attributeId, $typo3Version = self::TYPO3_DEFAULT_VERSION, $typo3Group = Attribute::NORMAL_GROUP
public function getPropertiesByParentTypeIdJson(
$typeId, $typo3Version = self::TYPO3_DEFAULT_VERSION, $typo3Group = Attribute::NORMAL_GROUP
) {
$curlHandle = $this->initialiseCurl('/attributes/' . $attributeId . '/properties');
$curlHandle = $this->initialiseCurl('/properties/' . $typeId . '/byparenttype');
$headerProperties = [
'version: ' . $typo3Version,
......@@ -187,35 +191,47 @@ class TsrefRestService {
}
/**
* Gets attribute by id.
* Gets a type by id.
*
* @param int $attributeId
* @param int $typeId
* @return \stdClass
*/
public function getAttributeById($attributeId) {
$attributeJson = $this->getAttributeByIdJson($attributeId);
$attributePhp = json_decode($attributeJson);
return $attributePhp;
public function getTypeById($typeId) {
$typeJson = $this->getAttributeByIdJson('types', $typeId);
$typePhp = json_decode($typeJson);
return $typePhp;
}
/**
* Gets all type attributes by $typo3Version and $typo3Group from RESOURCE_URL
* Gets a property by id.
*
* @param int $attributeId
* @param int $propertyId
* @return \stdClass
*/
public function getPropertyById($propertyId) {
$propertyJson = $this->getAttributeByIdJson('properties', $propertyId);
$propertyPhp = json_decode($propertyJson);
return $propertyPhp;
}
/**
* Gets all properties by parent type id, $typo3Version and $typo3Group from RESOURCE_URL
*
* @param int $parentTypeId
* @param string $typo3Version
* @param int $typo3Group
* @return mixed
*/
public function getPropertiesByParentId(
$attributeId, $typo3Version = self::TYPO3_DEFAULT_VERSION, $typo3Group = Attribute::NORMAL_GROUP
public function getPropertiesByParentTypeId(
$parentTypeId, $typo3Version = self::TYPO3_DEFAULT_VERSION, $typo3Group = Attribute::NORMAL_GROUP
) {
$propertiesJson = $this->getPropertiesByParentIdJson($attributeId, $typo3Version, $typo3Group);
$propertiesJson = $this->getPropertiesByParentTypeIdJson($parentTypeId, $typo3Version, $typo3Group);
$propertiesPhp = json_decode($propertiesJson);
return $propertiesPhp;
}
/**
* Gets all type attributes by $typo3Version and $typo3Group from RESOURCE_URL
* Gets all types by $typo3Version and $typo3Group from RESOURCE_URL
*
* @param bool $namesOnly
* @param string $typo3Version
......@@ -231,104 +247,121 @@ class TsrefRestService {
}
/**
* Adds new attribute to REST API resource by use of POST method.
* Adds new type to REST API resource by use of POST method.
*
* @param Attribute $attribute
* @param Type $type
* @return mixed
*/
public function addNewAttribute(Attribute $attribute) {
$attributeJson = json_encode($attribute->toArray());
$curlHandle = $this->initialiseCurl();
public function addNewType(Type $type) {
$typeJson = json_encode($type->toArray());
$curlHandle = $this->initialiseCurl('/types');
curl_setopt($curlHandle, CURLOPT_POST, 1);
curl_setopt(
$curlHandle, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'accesstoken: ' . $this->backendWriteAccessToken
]
);
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $attributeJson);
$outputJson = $this->submit($curlHandle, $typeJson);
// Download the given URL, and return output
$outputJson = curl_exec($curlHandle);
$statusCode = curl_getinfo($curlHandle, CURLINFO_HTTP_CODE);
return $outputJson;
}
// Close the cURL resource, and free system resources
curl_close($curlHandle);
$this->checkForErrors($statusCode, $outputJson);
/**
* Adds new property to REST API resource by use of POST method.
*
* @param Property $property
* @return mixed
*/
public function addNewProperty(Property $property) {
$propertyJson = json_encode($property->toArray());
$curlHandle = $this->initialiseCurl('/properties');
curl_setopt($curlHandle, CURLOPT_POST, 1);
$outputJson = $this->submit($curlHandle, $propertyJson);
return $outputJson;
}
/**
* Sends edited attribute to REST API resource by use of PUT method.
* Sends edited type to REST API resource by use of PUT method.
*
* @param Attribute $attribute
* @param Type $type
* @return mixed
*/
public function editAttribute(Attribute $attribute) {
if ($attribute->getId() === NULL) {
public function editType(Type $type) {
if ($type->getId() === NULL) {
throw new \RuntimeException(
'Edited attribute: ' . ($attribute->getName() ? $attribute->getName() : '...') . ' doesnt have ID.'
'Edited type: ' . ($type->getName() ? $type->getName() : '...') . ' doesnt have ID.'
);
}
$attributeJson = json_encode($attribute->toArray(TRUE));
$curlHandle = $this->initialiseCurl('/attributes/' . $attribute->getId());
$typeJson = json_encode($type->toArray(TRUE));
$curlHandle = $this->initialiseCurl('/types/' . $type->getId());
curl_setopt($curlHandle, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt(
$curlHandle, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'accesstoken: ' . $this->backendWriteAccessToken
]
);
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $attributeJson);
$outputJson = $this->submit($curlHandle, $typeJson);
// Download the given URL, and return output
$output = curl_exec($curlHandle);
$statusCode = curl_getinfo($curlHandle, CURLINFO_HTTP_CODE);
return $outputJson;
}
// Close the cURL resource, and free system resources
curl_close($curlHandle);
$this->checkForErrors($statusCode, $output);
/**
* Sends edited property to REST API resource by use of PUT method.
*
* @param Property $property
* @return mixed
*/
public function editProperty(Property $property) {
if ($property->getId() === NULL) {
throw new \RuntimeException(
'Edited property: ' . ($property->getName() ? $property->getName() : '...') . ' doesnt have ID.'
);
}
$dataJson = json_encode($property->toArray(TRUE));
$curlHandle = $this->initialiseCurl('/properties/' . $property->getId());
return $output;
curl_setopt($curlHandle, CURLOPT_CUSTOMREQUEST, 'PUT');
$outputJson = $this->submit($curlHandle, $dataJson);
return $outputJson;
}
/**
* Changes only those fields specified in the array $data. Attribute to change is specified with $id.
* Changes only those fields specified in the array $data. Type to change is specified with $id.
*
* @param int $id
* @param array $data
* @return mixed
*/
public function patchAttribute($id, array $data) {
public function patchType($id, array $data) {
if ($id === NULL) {
throw new \RuntimeException(
'$id must not be NULL.'
);
}
$dataJson = json_encode($data);
$curlHandle = $this->initialiseCurl('/attributes/' . $id);
$curlHandle = $this->initialiseCurl('/types/' . $id);
curl_setopt($curlHandle, CURLOPT_CUSTOMREQUEST, 'PATCH');
curl_setopt(
$curlHandle, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'accesstoken: ' . $this->backendWriteAccessToken
]
);
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $dataJson);
$outputJson = $this->submit($curlHandle, $dataJson);
// Download the given URL, and return output
$output = curl_exec($curlHandle);
$statusCode = curl_getinfo($curlHandle, CURLINFO_HTTP_CODE);
return $outputJson;
}
// Close the cURL resource, and free system resources
curl_close($curlHandle);
$this->checkForErrors($statusCode, $output);
/**
* Changes only those fields specified in the array $data. Property to change is specified with $id.
*
* @param int $id
* @param array $data
* @return mixed
*/
public function patchProperty($id, array $data) {
if ($id === NULL) {
throw new \RuntimeException(
'$id must not be NULL.'
);
}
$dataJson = json_encode($data);
$curlHandle = $this->initialiseCurl('/properties/' . $id);
return $output;
curl_setopt($curlHandle, CURLOPT_CUSTOMREQUEST, 'PATCH');
$outputJson = $this->submit($curlHandle, $dataJson);
return $outputJson;
}
/**
......@@ -428,7 +461,9 @@ class TsrefRestService {
* @return array
*/
public function getTypesWithNull($typo3Version, $typoScriptGroup = Attribute::NORMAL_GROUP) {
$typesAssociative = Conversion::attributesToAssociativeIdArray($this->getTypes(TRUE, $typo3Version, $typoScriptGroup));
$typesAssociative = Conversion::typesToAssociativeIdArray(
$this->getTypes(TRUE, $typo3Version, $typoScriptGroup)
);
$typesAssociative = [-1 => 'No type (NULL)'] + $typesAssociative;
return $typesAssociative;
}
......@@ -446,4 +481,30 @@ class TsrefRestService {
throw new \RuntimeException($message, $statusCode);
}
}
/**
* Submits by CURL json data and validates response.
*
* @param $curlHandle
* @param $dataJson
* @return mixed
*/
protected function submit($curlHandle, $dataJson) {
curl_setopt(
$curlHandle, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'accesstoken: ' . $this->backendWriteAccessToken
]
);
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $dataJson);
// Download the given URL, and return output
$outputJson = curl_exec($curlHandle);
$statusCode = curl_getinfo($curlHandle, CURLINFO_HTTP_CODE);
// Close the cURL resource, and free system resources
curl_close($curlHandle);
$this->checkForErrors($statusCode, $outputJson);
return $outputJson;
}
}
\ No newline at end of file
......@@ -9,7 +9,7 @@ class Conversion {
* @param array $attributes
* @return array
*/
public static function attributesToAssociativeIdArray(array $attributes) {
public static function typesToAssociativeIdArray(array $attributes) {
$idsAndNames = [];
foreach ($attributes as $attribute) {
$idsAndNames[$attribute->id] = $attribute->name;
......
......@@ -25,8 +25,7 @@
<f:form package="SGalinski.TypoScriptReferenceFrontend" controller="tsref" action="submitProperty"
object="{theProperty}" objectName="theProperty" arguments="{editForm: '{editForm}', typo3Version: selectedTypo3Version}" class="form-horizontal">
<f:form.hidden property="id" />
<f:form.hidden property="parent" />
<f:form.hidden property="isType" value="FALSE" />
<f:form.hidden property="parentType" />
<f:render partial="CommonAttributeFields" arguments="{_all}" />
......
......@@ -25,7 +25,6 @@
<f:form package="SGalinski.TypoScriptReferenceFrontend" controller="tsref" action="submitType"
object="{theType}" objectName="theType" arguments="{editForm: '{editForm}', typo3Version: selectedTypo3Version}" class="form-horizontal">
<f:form.hidden property="id" />
<f:form.hidden property="isType" value="TRUE" />
<f:render partial="CommonAttributeFields" arguments="{_all}" />
......@@ -33,7 +32,7 @@
<label for="extends" class="col-sm-2 control-label">Extends</label>
<div class="col-sm-10">
<f:form.select property="parent" options="{selectMenuTypes}" id="extends" class="form-control" />
<f:form.select property="extends" options="{selectMenuTypes}" id="extends" class="form-control" />
</div>
</div>
......
......@@ -27,7 +27,7 @@
</f:link.action>
|
<f:link.action package="SGalinski.TypoScriptReferenceFrontend" controller="tsref"
action="deleteAttribute" onclick="return confirmDeleteType()"
action="deleteType" onclick="return confirmDeleteType()"
arguments="{attributeId: selectedType.id, typo3Version: selectedTypo3Version}">
delete type
</f:link.action>
......@@ -57,7 +57,7 @@
<tr class="no-borders">
<td class="table-left-col"><h4>Extends</h4></td>
<td class="table-right-col">
<f:if condition="{selectedType.parent_id}">
<f:if condition="{selectedType.extends_id}">
<f:then>
<f:if condition="{superType.deleted}">
<f:then>
......@@ -89,18 +89,18 @@
<br>
<f:if condition="{properties}">
<f:for each="{properties}" as="propertyIterator">
<h3 class="sub-header" id="{propertyIterator.property.urlName}">{propertyIterator.property.name}
<h3 class="sub-header" id="{propertyIterator.0.urlName}">{propertyIterator.0.name}
<f:security.ifHasRole role="SGalinski.TypoScriptReferenceFrontend:Admin">
<div class="right-side-link">
[
<f:link.action package="SGalinski.TypoScriptReferenceFrontend" controller="tsref" action="editProperty"
arguments="{parentTypeId: selectedType.id, thePropertyId: propertyIterator.property.id, typo3Version: selectedTypo3Version}">
arguments="{parentTypeId: selectedType.id, thePropertyId: propertyIterator.0.id, typo3Version: selectedTypo3Version}">
edit property
</f:link.action>
|
<f:link.action package="SGalinski.TypoScriptReferenceFrontend" controller="tsref"
action="deleteAttribute" onclick="return confirmDeleteProperty()"
arguments="{ attributeId: propertyIterator.property.id, parentTypeUrlName: selectedType.urlName, typo3Version: selectedTypo3Version}">
action="deleteProperty" onclick="return confirmDeleteProperty()"
arguments="{ attributeId: propertyIterator.0.id, parentTypeUrlName: selectedType.urlName, typo3Version: selectedTypo3Version}">
delete property
</f:link.action>
]
......@@ -110,7 +110,7 @@
</h3>
<f:format.nl2br>
{propertyIterator.property.description}
{propertyIterator.0.description}
</f:format.nl2br>
<table class="table">
......@@ -118,15 +118,15 @@
<tr class="no-borders">
<td class="table-left-col"><h4>TYPO3 version range</h4></td>
<td class="table-right-col">
{f:if( condition: '{propertyIterator.property.minVersion}', then: '{propertyIterator.property.minVersion}', else: 'unknown')}
- {f:if( condition: '{propertyIterator.property.maxVersion}', then: '{propertyIterator.property.maxVersion}', else: 'current')}
{f:if( condition: '{propertyIterator.0.minVersion}', then: '{propertyIterator.0.minVersion}', else: 'unknown')}
- {f:if( condition: '{propertyIterator.0.maxVersion}', then: '{propertyIterator.0.maxVersion}', else: 'current')}
</td>
</tr>
<tr class="no-borders">
<td class="table-left-col"><h4>TypoScript Group</h4></td>
<td class="table-right-col">
<sg:accessArray array="{typo3Groups}" index="{propertyIterator.property.typo3Group}" />
<sg:accessArray array="{typo3Groups}" index="{propertyIterator.0.typo3Group}" />
</td>
</tr>
......@@ -150,7 +150,7 @@
<tr class="no-borders">
<td class="table-left-col"><h4>Default value</h4></td>
<td class="table-right-col">
{propertyIterator.property.default}
{propertyIterator.0.default}
</td>
</tr>
</tbody>
......
......@@ -48,7 +48,7 @@ class TsrefRestServiceTest extends UnitTestCase {
*/
public function addNewAttributeTest() {
$attribute = $this->createAttribute();
$response = $this->tsrefRestService->addNewAttribute($attribute);
$response = $this->tsrefRestService->addNewType($attribute);
echo ' Response: ' . $response;
}
......
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