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

[FEATURE] When fetching properties of a type, also fetching and sub properties

parent 765427ed
No related branches found
No related tags found
No related merge requests found
......@@ -27,6 +27,7 @@ use Symfony\Component\Security\Core\Exception\AuthenticationException;
abstract class AbstractPropertyController extends FOSRestController {
/**
* Action which returns an array of properties of the Type by it's id.
* Also fetches sub properties recursively.
* Returns empty array if there is no properties.
*
* @param Request $request
......@@ -40,11 +41,12 @@ abstract class AbstractPropertyController extends FOSRestController {
public function getPropertiesByparenttype(Request $request, $id, $typo3Group) {
$parameters = $request->headers->all();
$typo3Version = array_key_exists('version', $parameters) ? $parameters['version'][0] : NULL;
$maxDepth = array_key_exists('maxdepth', $parameters) ? $parameters['maxdepth'][0] : NULL;
/** @var PropertyRepository $propertyRepository */
$propertyRepository = $this->getDoctrine()->getRepository('TypoScriptBackendBundle:Property');
$properties = $propertyRepository->getPropertiesByParentTypeIdWithTypeNames(
$id, 'name', $typo3Group, $typo3Version
$properties = $propertyRepository->getPropertiesAndSubPropertiesByParentTypeIdWithTypeNames(
$id, 'name', $typo3Group, $typo3Version, ($maxDepth === NULL ? 6 : $maxDepth)
);
return $properties;
......
......@@ -39,13 +39,15 @@ class PropertyController extends AbstractPropertyController {
/**
* REST action which returns an array of properties of the Type by it's id.
* Also fetches sub properties recursively.
* Returns empty array if there is no properties.
* Method: GET, url: /api/page-tsconfig/properties/{id}/byparenttype.{_format}
*
* @ApiDoc(
* resource = true,
* description = "Gets en array of properties of the Type by it's id.
* Returns empty array if there is no properties. Also gets type names of properties.
* Returns empty array if there is no properties. Also gets for the property type: name, urlName and deleted fields.
* Also fetches sub properties recursively.
* This method has 2 header parameters:
* version - a TYPO3 version and
* 'typo3group' - typo script group (can be 1, 2 or 3 = normal, page and user group respectively)",
......
......@@ -39,13 +39,15 @@ class PropertyController extends AbstractPropertyController {
/**
* REST action which returns an array of properties of the Type by it's id.
* Also fetches sub properties recursively.
* Returns empty array if there is no properties.
* Method: GET, url: /api/typoscript/properties/{id}/byparenttype.{_format}
*
* @ApiDoc(
* resource = true,
* description = "Gets en array of properties of the Type by it's id.
* Returns empty array if there is no properties. Also gets type names of properties.
* Returns empty array if there is no properties. Also gets for the property type: name, urlName and deleted fields.
* Also fetches sub properties recursively.
* This method has 2 header parameters:
* version - a TYPO3 version and
* 'typo3group' - typo script group (can be 1, 2 or 3 = normal, page and user group respectively)",
......@@ -135,7 +137,7 @@ class PropertyController extends AbstractPropertyController {
* @throws NotFoundHttpException when property not exist
*/
public function putPropertyAction(Request $request, $id) {
return parent::putProperty($request,$id, Type::NORMAL_GROUP);
return parent::putProperty($request, $id, Type::NORMAL_GROUP);
}
/**
......
......@@ -39,13 +39,15 @@ class PropertyController extends AbstractPropertyController {
/**
* REST action which returns an array of properties of the Type by it's id.
* Also fetches sub properties recursively.
* Returns empty array if there is no properties.
* Method: GET, url: /api/user-tsconfig/properties/{id}/byparenttype.{_format}
*
* @ApiDoc(
* resource = true,
* description = "Gets en array of properties of the Type by it's id.
* Returns empty array if there is no properties. Also gets type names of properties.
* Returns empty array if there is no properties. Also gets for the property type: name, urlName and deleted fields.
* Also fetches sub properties recursively.
* This method has 2 header parameters:
* version - a TYPO3 version and
* 'typo3group' - typo script group (can be 1, 2 or 3 = normal, page and user group respectively)",
......
......@@ -83,14 +83,14 @@ class PropertyRepository extends EntityRepository {
* @param string|NULL $orderBy
* @param int $typo3Group
* @param string $typo3Version
* @return array example: [{"property":{"id":1163,"name":"wrap","description":"Wraps the links.","minVersion":"1.0","maxVersion":"7.4",
* @return array example: [{"0":{"id":1163,"name":"wrap","description":"Wraps the links.","minVersion":"1.0","maxVersion":"7.4",
* example: [{"property":{"id":1163,"name":"wrap","description":"Wraps the links.","minVersion":"1.0","maxVersion":"7.4",
* "typo3Group":1,"default":"\n","deleted":false,"type_id":"687","parent_type_id":"1164"},
* "type_name":"wrap","type_deleted":false}, ...]
*/
public function getPropertiesByParentTypeIdWithTypeNames(
$id, $orderBy = NULL, $typo3Group = Type::NORMAL_GROUP, $typo3Version = NULL
) {//TODO: Try with left join
) {
/** @var QueryBuilder $queryBuilder */
$queryBuilder = $this->createQueryBuilder('property')
->select(
......@@ -116,6 +116,110 @@ class PropertyRepository extends EntityRepository {
return $propertyArray;
}
/**
* Returns properties with parent_property_id = $id as en array of properties with names of property types.
* Returns only properties which are not marked as deleted.
*
* @param $id - parent_property_id
* @param string|NULL $orderBy
* @param int $typo3Group
* @param string $typo3Version
* @return array example: [{"0":{"id":1050,"name":"subProperty","urlName":"subProperty","typo3Group":1,"deleted":false,"type_id":"1"},
* "type_name":"cObj","type_url_name":"cObj","type_deleted":false}]
*/
public function getSubPropertiesByParentPropertyIdWithTypeNames(
$id, $orderBy = NULL, $typo3Group = Type::NORMAL_GROUP, $typo3Version = NULL
) {
/** @var QueryBuilder $queryBuilder */
$queryBuilder = $this->createQueryBuilder('property')
->select(
'property, property_type.name AS type_name, property_type.urlName AS type_url_name, property_type.deleted AS type_deleted'
)
->from('TypoScriptBackendBundle:Type', 'property_type')
->where('property.parentProperty = :id AND property_type.id = property.type')
->andWhere(':typo3Group IS NULL OR property.typo3Group = :typo3Group')
->andWhere(':typo3Version IS NULL OR property.minVersion IS NULL OR property.minVersion <= :typo3Version')
->andWhere(':typo3Version IS NULL OR property.maxVersion IS NULL OR property.maxVersion >= :typo3Version')
->andWhere('property.deleted IS NULL OR property.deleted = FALSE')
->setParameter('typo3Group', $typo3Group)
->setParameter('typo3Version', $typo3Version)
->setParameter('id', $id);
if ($orderBy) {
$queryBuilder->orderBy('property.' . $orderBy);
}
/** @var Query $query */
$query = $queryBuilder->getQuery();
$query->setHint(Query::HINT_INCLUDE_META_COLUMNS, TRUE);
$propertyArray = $query->getArrayResult();
return $propertyArray;
}
/**
* Returns properties with parent_property_id = $id as en array of properties with names of property types.
* Returns only properties which are not marked as deleted.
*
* @param $id - parent_property_id
* @param string|NULL $orderBy
* @param int $typo3Group
* @param string $typo3Version
* @param int $maxDepth
* @return array example: [{"property":{"id":1163,"name":"wrap","description":"Wraps the links.","minVersion":"4.5",
* example: [{"0":{"id":1050,"name":"firstSubProperty","urlName":"firstSubProperty","typo3Group":1,"deleted":false,"type_id":"1","parent_property_id":"48"},
* "type_name":"cObj","type_url_name":"cObj","type_deleted":false,
* "subProperties":[{"0":{"id":1051,"name":"subSubProperty","urlName":"subSubProperty","typo3Group":1,"deleted":false,"type_id":"1","parent_property_id":"1050"},
* "type_name":"cObj","type_url_name":"cObj","type_deleted":false,"subProperties":[]}]}]
*/
public function getRecursiveSubPropertiesByParentPropertyIdWithTypeNames(
$id, $orderBy = NULL, $typo3Group = Type::NORMAL_GROUP, $typo3Version = NULL, $maxDepth = 5
) {
if ($maxDepth <= 0) {
return [];
}
$propertyArray = $this->getSubPropertiesByParentPropertyIdWithTypeNames(
$id, $orderBy, $typo3Group, $typo3Version
);
foreach ($propertyArray as &$property) {
$subProperties = $this->getRecursiveSubPropertiesByParentPropertyIdWithTypeNames(
$property[0]['id'], $orderBy, $typo3Group, $typo3Version, $maxDepth - 1
);
$property['subProperties'] = $subProperties;
}
return $propertyArray;
}
/**
* Returns properties with parent_type_id = $id as en array with names of property types.
* Also fetches sub properties recursively.
* Returns only properties which are not marked as deleted.
*
* @param $id - parent_type_id
* @param string|NULL $orderBy
* @param int $typo3Group
* @param string $typo3Version
* @param int $maxDepth
* @return array example: [{"0":{"id":1163,"name":"wrap","description":"Wraps the links.","minVersion":"1.0","maxVersion":"7.4",
* example: [{"property":{"id":1163,"name":"wrap","description":"Wraps the links.","minVersion":"1.0","maxVersion":"7.4",
* "typo3Group":1,"default":"\n","deleted":false,"type_id":"687","parent_type_id":"1164"},
* "type_name":"wrap","type_deleted":false}, ...]
*/
public function getPropertiesAndSubPropertiesByParentTypeIdWithTypeNames(
$id, $orderBy = NULL, $typo3Group = Type::NORMAL_GROUP, $typo3Version = NULL, $maxDepth = 6
) {
$propertyArray = $this->getPropertiesByParentTypeIdWithTypeNames($id, $orderBy, $typo3Group, $typo3Version);
if ($maxDepth <= 0) {
return $propertyArray;
}
foreach ($propertyArray as &$property) {
$subProperties = $this->getRecursiveSubPropertiesByParentPropertyIdWithTypeNames(
$property[0]['id'], $orderBy, $typo3Group, $typo3Version, $maxDepth
);
$property['subProperties'] = $subProperties;
}
return $propertyArray;
}
/**
* Lists all properties by $version, $typo3Group parameters.
* Returns non persisted array of properties which are not marked as deleted.
......
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