Skip to content

Commit

Permalink
Merge pull request #4 from basilicom/feature/add-option-to-include-un…
Browse files Browse the repository at this point in the history
…published-objects

Feature/add option to include unpublished objects
  • Loading branch information
clemenskapelle authored Jan 25, 2022
2 parents 07a80ec + fb8db94 commit 193e47c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function exportAction(Request $request)

$this->xmlService->setIncludeVariants(($config['include_variants'] == true));
$this->xmlService->setOmitRelationObjectFields(($config['omit_relation_object_fields'] == true));
$this->xmlService->setIncludeUnpublished($config['include_unpublished'] == true);

$this->xmlService->setXslt($config['xslt']);

Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function getConfigTreeBuilder()
->scalarNode('token')->defaultValue('')->end()
->scalarNode('xslt')->defaultValue('')->end()
->scalarNode('include_variants')->defaultValue('false')->end()
->scalarNode('include_unpublished')->defaultValue('false')->end()
->scalarNode('omit_relation_object_fields')->defaultValue('false')->end()
->end()
->end()
Expand Down
24 changes: 22 additions & 2 deletions Service/Xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Xml
private $xslt = false;

private $includeVariants = false;
private $includeUnpublished = false;
private $omitRelationObjectFields = false;

private $language = null;
Expand Down Expand Up @@ -48,6 +49,16 @@ public function setIncludeVariants(bool $includeVariants): void
$this->includeVariants = $includeVariants;
}

/**
* @param bool $includeUnpublished
*
* @return void
*/
public function setIncludeUnpublished(bool $includeUnpublished): void
{
$this->includeUnpublished = $includeUnpublished;
}

/**
* @return bool
*/
Expand All @@ -56,6 +67,14 @@ public function isOmitRelationObjectFields(): bool
return $this->omitRelationObjectFields;
}

/**
* @return bool
*/
public function isIncludeUnpublished(): bool
{
return $this->includeUnpublished;
}

/**
* @param bool $omitRelationObjectFields
*
Expand Down Expand Up @@ -130,7 +149,7 @@ private function exportObject(DataObject $object, $useRecursion=true, $addFields
$childDataList = [];

if ($useRecursion) {
$children = $object->getChildren();
$children = $object->getChildren([DataObject\AbstractObject::OBJECT_TYPE_OBJECT, DataObject\AbstractObject::OBJECT_TYPE_FOLDER], $this->isIncludeUnpublished());
foreach ($children as $child) {
$childData = $this->exportObject($child);
if (!array_key_exists($childData['_attributes']['class'], $childDataList)) {
Expand All @@ -143,7 +162,7 @@ private function exportObject(DataObject $object, $useRecursion=true, $addFields
$variantDataList = [];

if ($this->includeVariants) {
$children = $object->getChildren([DataObject\AbstractObject::OBJECT_TYPE_VARIANT]);
$children = $object->getChildren([DataObject\AbstractObject::OBJECT_TYPE_VARIANT], $this->isIncludeUnpublished());
foreach ($children as $child) {
$childData = $this->exportObject($child);
if (!array_key_exists($childData['_attributes']['class'], $variantDataList)) {
Expand All @@ -169,6 +188,7 @@ private function exportObject(DataObject $object, $useRecursion=true, $addFields
'class' => $className,
'is-variant-leaf' => (($object->getType()==='variant')&&(count($variantDataList)===0)?'true':'false'),
'is-object-leaf' => (($object->getType()==='object')&&(count($childDataList)===0)?'true':'false'),
'is-published' => (($object->getType()==='object')&&(count($childDataList)===0)&&($object->isPublished()) ?'true':'false'),
];

return $objectData;
Expand Down

0 comments on commit 193e47c

Please sign in to comment.