Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,19 @@ public function getXmlRepresentation(string $a_entity, string $a_schema_version,
public function getValidSchemaVersions(string $a_entity): array
{
return [
"12.0" => [
'namespace' => 'https://www.ilias.de/Modules/Category/cat/12',
'xsd_file' => 'ilias_cat_12_0.xsd',
'uses_dataset' => false,
'min' => '12.0',
'max' => ''
],
"9.0.0" => [
'namespace' => 'https://www.ilias.de/Modules/Category/cat/9_0',
'xsd_file' => 'ilias_cat_9_0.xsd',
'uses_dataset' => false,
'min' => '9.0',
'max' => ''
'max' => '11.999'
],
"4.3.0" => [
"namespace" => "https://www.ilias.de/Modules/Category/cat/4_3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public function export(bool $a_with_header = true): void
}
$this->buildCategory();
$this->buildTranslations();
ilContainerSortingSettings::_exportContainerSortingSettings($this, $this->getCategory()->getId());
ilContainer::_exportContainerSettings($this, $this->category->getId());
$this->buildFooter();
}
Expand Down
68 changes: 68 additions & 0 deletions components/ILIAS/Container/Export/class.ilContainerXmlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*
*********************************************************************/

use ILIAS\Container\Sorting\Service\DomainService as SortingDomainService;

/**
* XML parser for container structure
*
Expand All @@ -26,6 +28,7 @@ class ilContainerXmlParser
protected ilSetting $settings;
protected ilObjectDefinition $obj_definition;
protected ilLogger $cont_log;
protected SortingDomainService $sorting_domain;
private int $source = 0;
private ?ilImportMapping $mapping = null;
private string $xml = '';
Expand All @@ -43,6 +46,7 @@ public function __construct(
$this->mapping = $mapping;
$this->xml = $xml;
$this->cont_log = ilLoggerFactory::getLogger('cont');
$this->sorting_domain = $DIC->container()->internal()->domain()->sorting();
}

public function getMapping(): ?ilImportMapping
Expand Down Expand Up @@ -121,6 +125,11 @@ protected function initItem(
$this->mapping->addMapping('components/ILIAS/COPage', 'pg', 'cstr:' . $obj_id, 'cstr:' . $new_obj_id);
}
}

// sorting
foreach ($item->Sort as $sort) {
$this->parseSorting($new_obj_id, $sort);
}
}

// Parse timing info
Expand Down Expand Up @@ -171,6 +180,65 @@ protected function parseTiming(
}
}

protected function parseSorting(
int $new_obj_id,
SimpleXMLElement $sorting
): void {
$mode = match ((string) ($sorting['type'] ?? '')) {
'Manual' => ilContainer::SORT_MANUAL,
'Creation' => ilContainer::SORT_CREATION,
'Activation' => ilContainer::SORT_ACTIVATION,
default => ilContainer::SORT_TITLE
};
$direction = match ((string) ($sorting['direction'] ?? '')) {
'DESC' => ilContainer::SORT_DIRECTION_DESC,
default => ilContainer::SORT_DIRECTION_ASC
};
$position = match((string) ($sorting['position'] ?? '')) {
'Top' => ilContainer::SORT_NEW_ITEMS_POSITION_TOP,
default => ilContainer::SORT_NEW_ITEMS_POSITION_BOTTOM
};
$order = match ((string) ($sorting['order'] ?? '')) {
'Creation' => ilContainer::SORT_NEW_ITEMS_ORDER_CREATION,
'Activation' => ilContainer::SORT_NEW_ITEMS_ORDER_ACTIVATION,
default => ilContainer::SORT_NEW_ITEMS_ORDER_TITLE
};
$this->sorting_domain->settings()->saveSettingsForObject(
$new_obj_id,
$mode,
$direction,
$position,
$order,
);

foreach ($sorting->Grouping as $grouping) {
$old_parent_id = (int) $grouping['parent_id'];
$new_parent_id = 0;
if ($old_parent_id !== 0) {
$new_parent_id = $this->mapping->getMapping('components/ILIAS/Container', 'objs', $old_parent_id);
}
if ($new_parent_id === null) {
continue;
}
$parent_type = (string) $grouping['parent_type'];
foreach ($grouping->Position as $position) {
$old_child_id = (int) $position['child_id'];
$new_child_id = $this->mapping->getMapping('components/ILIAS/Container', 'refs', $old_child_id);
if (!$new_child_id) {
continue;
}
$position = (int) $position;
$this->sorting_domain->positions()->savePositionForChild(
$new_obj_id,
$new_child_id,
$position,
$parent_type,
$new_parent_id
);
}
}
}

protected function createObject(
int $ref_id,
int $obj_id,
Expand Down
71 changes: 60 additions & 11 deletions components/ILIAS/Container/Export/class.ilContainerXmlWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*
*********************************************************************/

use ILIAS\Container\Sorting\Service\DomainService as SortingDomainService;

/**
* XML writer for container structure
*
Expand All @@ -27,6 +29,7 @@ class ilContainerXmlWriter extends ilXmlWriter
protected ?ilExportOptions $exp_options = null;
private int $source = 0;
protected ilObjectDefinition $objDefinition;
protected SortingDomainService $sorting_domain;

public function __construct(int $a_ref_id)
{
Expand All @@ -37,6 +40,7 @@ public function __construct(int $a_ref_id)
$this->source = $a_ref_id;
$this->exp_options = ilExportOptions::getInstance();
$this->objDefinition = $DIC['objDefinition'];
$this->sorting_domain = $DIC->container()->internal()->domain()->sorting();
}

/**
Expand Down Expand Up @@ -68,22 +72,23 @@ protected function writeSubitems(int $a_ref_id): void

$obj_id = ilObject::_lookupObjId($a_ref_id);

$atts = [];
$atts['RefId'] = $a_ref_id;
$atts['Id'] = $obj_id;
$atts['Title'] = ilObject::_lookupTitle($obj_id);
$atts['Type'] = ilObject::_lookupType($obj_id);
$atts['Page'] = ilContainerPage::_exists('cont', $obj_id);
$atts['StartPage'] = ilContainerStartObjectsPage::_exists('cstr', $obj_id);
$atts['Style'] = ilObjStyleSheet::lookupObjectStyle($obj_id);
if ($this->objDefinition->supportsOfflineHandling($atts['Type'])) {
$atts['Offline'] = ilObject::lookupOfflineStatus($obj_id) ? '1' : '0';
$attrs = [];
$attrs['RefId'] = $a_ref_id;
$attrs['Id'] = $obj_id;
$attrs['Title'] = ilObject::_lookupTitle($obj_id);
$attrs['Type'] = ilObject::_lookupType($obj_id);
$attrs['Page'] = ilContainerPage::_exists('cont', $obj_id);
$attrs['StartPage'] = ilContainerStartObjectsPage::_exists('cstr', $obj_id);
$attrs['Style'] = ilObjStyleSheet::lookupObjectStyle($obj_id);
if ($this->objDefinition->supportsOfflineHandling($attrs['Type'])) {
$attrs['Offline'] = ilObject::lookupOfflineStatus($obj_id) ? '1' : '0';
}
$this->xmlStartTag(
'Item',
$atts
$attrs
);
$this->writeCourseItemInformation($a_ref_id);
$this->writeContainerSorting($obj_id);

foreach ($tree->getChilds($a_ref_id) as $node) {
$this->writeSubitems($node['child']);
Expand Down Expand Up @@ -133,6 +138,50 @@ protected function writeCourseItemInformation(int $a_ref_id): void
$this->xmlEndTag('Timing');
}

protected function writeContainerSorting(
int $obj_id
): void {
$settings = $this->sorting_domain->settings()->getSettingsForObject($obj_id);

$attr = [];
$attr['direction'] = $settings->getSortDirection() === ilContainer::SORT_DIRECTION_ASC ? "ASC" : "DESC";
$attr['type'] = match ($settings->getSortMode()) {
ilContainer::SORT_MANUAL => 'Manual',
ilContainer::SORT_CREATION => 'Creation',
ilContainer::SORT_ACTIVATION => 'Activation',
ilContainer::SORT_INHERIT => 'Inherit',
default => 'Title'
};

if ($settings->getSortMode() !== ilContainer::SORT_MANUAL) {
$this->xmlElement('Sort', $attr);
return;
}

$attr['position'] = $settings->getSortNewItemsPosition() === ilContainer::SORT_NEW_ITEMS_POSITION_BOTTOM ? "Bottom" : "Top";
$attr['order'] = match ($settings->getSortNewItemsOrder()) {
ilContainer::SORT_NEW_ITEMS_ORDER_ACTIVATION => 'Activation',
ilContainer::SORT_NEW_ITEMS_ORDER_CREATION => 'Creation',
default => 'Title'
};

$groupings = $this->sorting_domain->positions()->getPositionsInObject($obj_id);

$this->xmlStartTag('Sort', $attr);
foreach ($groupings as $grouping) {
$grouping_attr = [
'parent_id' => $grouping->getParentId(),
'parent_type' => $grouping->getParentId() ? $grouping->getParentType() : ''
];
$this->xmlStartTag('Grouping', $grouping_attr);
foreach ($grouping->getPositions() as $position) {
$this->xmlElement('Position', ['child_id' => $position->getChildID()], $position->getPosition());
}
$this->xmlEndTag('Grouping');
}
$this->xmlEndTag('Sort');
}

protected function buildHeader(): void
{
$this->xmlSetGenCmt("Container object");
Expand Down
36 changes: 36 additions & 0 deletions components/ILIAS/Container/Service/class.DomainService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

declare(strict_types=1);

namespace ILIAS\Container;

use ILIAS\Container\Sorting\Service\DomainService as SortingDomainService;

class DomainService
{
public function __construct(
protected InternalService $internal
) {
}

public function sorting(): SortingDomainService
{
return $this->internal->domain()->sorting();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,21 @@
class InternalDataService
{
protected Content\DataService $content_service;
protected Sorting\Service\DataService $sorting_service;

public function __construct()
{
$this->content_service = new Content\DataService();
$this->sorting_service = new Sorting\Service\DataService();
}

public function content(): Content\DataService
{
return $this->content_service;
}

public function sorting(): Sorting\Service\DataService
{
return $this->sorting_service;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use ILIAS\Container\Page\PageManager;
use ILIAS\Container\Classification\ClassificationManager;
use ILIAS\Container\Metadata\MetadataManager;
use ILIAS\Container\Sorting\Service\DomainService as SortingDomainService;

/**
* @author Alexander Killing <killing@leifos.de>
Expand Down Expand Up @@ -92,4 +93,9 @@ public function containerFilterRetrieval(
$ref_id
);
}

public function sorting(): SortingDomainService
{
return new SortingDomainService($this->repo_service, $this->data_service, $this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,12 @@ public function classification(int $base_ref_id): ClassificationSessionRepositor
$base_ref_id
);
}

public function sorting(): Sorting\Service\RepoService
{
return new Sorting\Service\RepoService(
$this->data,
$this->db
);
}
}
5 changes: 5 additions & 0 deletions components/ILIAS/Container/Service/class.Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public function __construct(DI\Container $DIC)
$this->DIC = $DIC;
}

public function domain(): DomainService
{
return new DomainService($this->internal());
}

/**
* Internal service, do not use in other components
*/
Expand Down
Loading
Loading