diff --git a/components/ILIAS/Category/Export/class.ilCategoryExporter.php b/components/ILIAS/Category/Export/class.ilCategoryExporter.php index ece67162fc54..344047efe9a7 100755 --- a/components/ILIAS/Category/Export/class.ilCategoryExporter.php +++ b/components/ILIAS/Category/Export/class.ilCategoryExporter.php @@ -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", diff --git a/components/ILIAS/Category/Export/class.ilCategoryXmlWriter.php b/components/ILIAS/Category/Export/class.ilCategoryXmlWriter.php index aa5a20d91e5e..064ba522e7e7 100755 --- a/components/ILIAS/Category/Export/class.ilCategoryXmlWriter.php +++ b/components/ILIAS/Category/Export/class.ilCategoryXmlWriter.php @@ -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(); } diff --git a/components/ILIAS/Container/Export/class.ilContainerXmlParser.php b/components/ILIAS/Container/Export/class.ilContainerXmlParser.php index 435af8e380a7..cee2b1c32cdb 100755 --- a/components/ILIAS/Container/Export/class.ilContainerXmlParser.php +++ b/components/ILIAS/Container/Export/class.ilContainerXmlParser.php @@ -16,6 +16,8 @@ * *********************************************************************/ +use ILIAS\Container\Sorting\Service\DomainService as SortingDomainService; + /** * XML parser for container structure * @@ -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 = ''; @@ -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 @@ -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 @@ -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, diff --git a/components/ILIAS/Container/Export/class.ilContainerXmlWriter.php b/components/ILIAS/Container/Export/class.ilContainerXmlWriter.php index 157145850fc2..a813d4b0b337 100755 --- a/components/ILIAS/Container/Export/class.ilContainerXmlWriter.php +++ b/components/ILIAS/Container/Export/class.ilContainerXmlWriter.php @@ -16,6 +16,8 @@ * *********************************************************************/ +use ILIAS\Container\Sorting\Service\DomainService as SortingDomainService; + /** * XML writer for container structure * @@ -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) { @@ -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(); } /** @@ -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']); @@ -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"); diff --git a/components/ILIAS/Container/Service/class.DomainService.php b/components/ILIAS/Container/Service/class.DomainService.php new file mode 100755 index 000000000000..65b3ad01cc2f --- /dev/null +++ b/components/ILIAS/Container/Service/class.DomainService.php @@ -0,0 +1,36 @@ +internal->domain()->sorting(); + } +} diff --git a/components/ILIAS/Container/Service/class.InternalDataService.php b/components/ILIAS/Container/Service/class.InternalDataService.php index f9dafa941671..bed3fedd1e81 100755 --- a/components/ILIAS/Container/Service/class.InternalDataService.php +++ b/components/ILIAS/Container/Service/class.InternalDataService.php @@ -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; + } } diff --git a/components/ILIAS/Container/Service/class.InternalDomainService.php b/components/ILIAS/Container/Service/class.InternalDomainService.php index 06f044d6ac4b..455d058e37f3 100755 --- a/components/ILIAS/Container/Service/class.InternalDomainService.php +++ b/components/ILIAS/Container/Service/class.InternalDomainService.php @@ -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 @@ -92,4 +93,9 @@ public function containerFilterRetrieval( $ref_id ); } + + public function sorting(): SortingDomainService + { + return new SortingDomainService($this->repo_service, $this->data_service, $this); + } } diff --git a/components/ILIAS/Container/Service/class.InternalRepoService.php b/components/ILIAS/Container/Service/class.InternalRepoService.php index c38c2c12a415..cacfdcacb803 100755 --- a/components/ILIAS/Container/Service/class.InternalRepoService.php +++ b/components/ILIAS/Container/Service/class.InternalRepoService.php @@ -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 + ); + } } diff --git a/components/ILIAS/Container/Service/class.Service.php b/components/ILIAS/Container/Service/class.Service.php index d1309011c1ad..a158a1d568e6 100755 --- a/components/ILIAS/Container/Service/class.Service.php +++ b/components/ILIAS/Container/Service/class.Service.php @@ -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 */ diff --git a/components/ILIAS/Container/Sorting/Positions/Grouping.php b/components/ILIAS/Container/Sorting/Positions/Grouping.php new file mode 100755 index 000000000000..8a909e054490 --- /dev/null +++ b/components/ILIAS/Container/Sorting/Positions/Grouping.php @@ -0,0 +1,63 @@ +positions = $positions; + } + + public function getObjId(): int + { + return $this->obj_id; + } + + public function getParentType(): string + { + return $this->parent_type; + } + + public function getParentID(): int + { + return $this->parent_id; + } + + /** + * @return PositionData[] + */ + public function getPositions(): Generator + { + yield from $this->positions; + } +} diff --git a/components/ILIAS/Container/Sorting/Positions/Manager.php b/components/ILIAS/Container/Sorting/Positions/Manager.php new file mode 100755 index 000000000000..0a10f468d159 --- /dev/null +++ b/components/ILIAS/Container/Sorting/Positions/Manager.php @@ -0,0 +1,185 @@ +repo->sorting()->positions()->getPositions($obj_id); + } + + public function clonePositions( + int $obj_id, + int $target_ref_id, + int $copy_id + ): void { + $logger = $this->domain->logger()->cont(); + $logger->debug("Cloning container sorting."); + + $target_obj_id = ilObject::_lookupObjId($target_ref_id); + $mappings = ilCopyWizardOptions::_getInstance($copy_id)->getMappings(); + + $logger->debug("Read container_sorting for obj_id = " . $obj_id); + + $groupings = $this->repo->sorting()->positions()->getPositions($obj_id); + + foreach ($groupings as $grouping) { + $new_parent_id = 0; + if ($grouping->getParentID()) { + // see bug #20347 + // at least in the case of sessions and item groups parent_ids in container sorting are object IDs but $mappings store references + if (in_array($grouping->getParentType(), ["sess", "itgr"])) { + $par_refs = ilObject::_getAllReferences($grouping->getParentID()); + $par_ref_id = current($par_refs); // should be only one + $logger->debug("Got ref id: " . $par_ref_id . " for obj_id " . $grouping->getParentID() . " map ref id: " . ($mappings[$par_ref_id] ?? "") . "."); + if (isset($mappings[$par_ref_id])) { + $new_parent_ref_id = (int) $mappings[$par_ref_id]; + $new_parent_id = ilObject::_lookupObjectId($new_parent_ref_id); + } + } else { // not sure if this is still used for other cases that expect ref ids + (int) $new_parent_id = $mappings[$grouping->getParentID()]; + } + if ((int) $new_parent_id === 0) { + $logger->debug("No mapping found for parent id:" . $grouping->getParentID()); + continue; + } + } + + foreach ($grouping->getPositions() as $position) { + if (!isset($mappings[$position->getChildID()]) || !$mappings[$position->getChildID()]) { + $logger->debug("No mapping found for child id:" . $position->getChildID()); + continue; + } + + $this->repo->sorting()->positions()->deletePositionsForChild( + $target_obj_id, + $mappings[$position->getChildID()], + $new_parent_id + ); + $this->repo->sorting()->positions()->savePositionForChild( + $target_obj_id, + $mappings[$position->getChildID()], + $position->getPosition(), + $grouping->getParentType(), + $new_parent_id + ); + } + } + } + + public function savePositionForChild( + int $obj_id, + int $child_id, + int $position, + string $parent_type, + int $parent_id + ): void { + if (!$parent_id) { + $parent_type = ''; + } + $this->repo->sorting()->positions()->savePositionForChild( + $obj_id, + $child_id, + $position, + $parent_type, + $parent_id + ); + } + + /** + * @param array $type_positions positions e.g array(crs => array(1,2,3),'lres' => array(3,5,6)) + */ + public function saveFromPost(int $obj_id, array $type_positions): void + { + $items = []; + foreach ($type_positions as $key => $position) { + if (!is_array($position)) { + $items[$key] = ((float) $position) * 100; + } else { + foreach ($position as $parent_id => $sub_items) { + $this->saveSubItemsFromPost($obj_id, $key, $parent_id, $sub_items ?: []); + } + } + } + + if (!count($items)) { + $this->saveItemsFromPost($obj_id, []); + return; + } + + asort($items); + $new_indexed = []; + $position = 0; + foreach ($items as $key => $null) { + $new_indexed[$key] = ++$position; + } + + $this->saveItemsFromPost($obj_id, $new_indexed); + } + + protected function saveItemsFromPost(int $obj_id, array $items): void + { + foreach ($items as $child_id => $position) { + $this->savePositionForChild( + $obj_id, + (int) $child_id, + (int) $position, + '', + 0 + ); + } + } + + protected function saveSubItemsFromPost( + int $obj_id, + string $parent_type, + int $parent_id, + array $items + ): void { + foreach ($items as $child_id => $position) { + $this->savePositionForChild( + $obj_id, + (int) $child_id, + (int) $position, + $parent_type, + $parent_id + ); + } + } +} diff --git a/components/ILIAS/Container/Sorting/Positions/PositionData.php b/components/ILIAS/Container/Sorting/Positions/PositionData.php new file mode 100755 index 000000000000..1bf81f3b17f3 --- /dev/null +++ b/components/ILIAS/Container/Sorting/Positions/PositionData.php @@ -0,0 +1,40 @@ +child_id; + } + + public function getPosition(): int + { + return $this->position; + } +} diff --git a/components/ILIAS/Container/Sorting/Positions/Repository.php b/components/ILIAS/Container/Sorting/Positions/Repository.php new file mode 100755 index 000000000000..ba8763df51c0 --- /dev/null +++ b/components/ILIAS/Container/Sorting/Positions/Repository.php @@ -0,0 +1,112 @@ +db->quote($obj_id, ilDBConstants::T_INTEGER) . " ORDER BY position"; + $res = $this->db->query($query); + while ($row = $res->fetchAssoc()) { + $data = $this->data->sorting()->positionData($row['child_id'], $row['position']); + if ($row['parent_id'] ?? 0) { + $data_by_parent[$row['parent_type']][$row['parent_id']][] = $data; + } else { + $data_by_parent['all'][0][] = $data; + } + } + foreach ($data_by_parent as $parent_type => $parents) { + foreach ($parents as $parent_id => $positions) { + yield $this->data->sorting()->positionGrouping( + $obj_id, + (string) $parent_type, + (int) $parent_id, + ...$positions + ); + } + } + } + + public function savePositionForChild( + int $obj_id, + int $child_id, + int $position, + string $parent_type, + int $parent_id + ): void { + $this->db->replace( + 'container_sorting', + [ + 'obj_id' => [ilDBConstants::T_INTEGER, $obj_id], + 'child_id' => [ilDBConstants::T_INTEGER, $child_id], + 'parent_id' => [ilDBConstants::T_INTEGER, $parent_id] + ], + [ + 'parent_type' => [ilDBConstants::T_TEXT, $parent_type], + 'position' => [ilDBConstants::T_INTEGER, $position] + ] + ); + } + + public function deletePositions(int $obj_id): void + { + $this->db->manipulate( + "DELETE FROM container_sorting WHERE obj_id = " . + $this->db->quote($obj_id, ilDBConstants::T_INTEGER) + ); + } + + public function deleteGrouping(int $obj_id, int $parent_id): void + { + $this->db->manipulate( + "DELETE FROM container_sorting WHERE obj_id = " . + $this->db->quote($obj_id, ilDBConstants::T_INTEGER) . + " AND parent_id = " . $this->db->quote($parent_id, ilDBConstants::T_INTEGER) + ); + } + + public function deletePositionsForChild(int $obj_id, int $child_id, int $parent_id): void + { + $this->db->manipulate( + "DELETE FROM container_sorting WHERE obj_id = " . + $this->db->quote($obj_id, ilDBConstants::T_INTEGER) . + " AND child_id = " . $this->db->quote($child_id, ilDBConstants::T_INTEGER) . + " AND parent_id = " . $this->db->quote($parent_id, ilDBConstants::T_INTEGER) + ); + } +} diff --git a/components/ILIAS/Container/Sorting/Service/DataService.php b/components/ILIAS/Container/Sorting/Service/DataService.php new file mode 100755 index 000000000000..7ddb3abc3003 --- /dev/null +++ b/components/ILIAS/Container/Sorting/Service/DataService.php @@ -0,0 +1,71 @@ + + */ +class DataService +{ + public function settings( + int $obj_id, + int $sort_mode, + int $sort_direction, + int $new_items_position, + int $new_items_order + ): SortingSettings { + return new SortingSettings( + $obj_id, + $sort_mode, + $sort_direction, + $new_items_position, + $new_items_order + ); + } + + public function positionGrouping( + int $obj_id, + string $parent_type, + int $parent_id, + PositionData ...$positions + ): Grouping { + return new Grouping( + $obj_id, + $parent_type, + $parent_id, + ...$positions + ); + } + + public function positionData( + int $child_id, + int $position, + ): PositionData { + return new PositionData( + $child_id, + $position + ); + } +} diff --git a/components/ILIAS/Container/Sorting/Service/DomainService.php b/components/ILIAS/Container/Sorting/Service/DomainService.php new file mode 100755 index 000000000000..213e1ac1ac0d --- /dev/null +++ b/components/ILIAS/Container/Sorting/Service/DomainService.php @@ -0,0 +1,47 @@ +data_service, $this->repo_service, $this->domain_service); + } + + public function positions(): PositionsManager + { + return new PositionsManager($this->data_service, $this->repo_service, $this->domain_service); + } +} diff --git a/components/ILIAS/Container/Sorting/Service/RepoService.php b/components/ILIAS/Container/Sorting/Service/RepoService.php new file mode 100755 index 000000000000..7c52a8662ed1 --- /dev/null +++ b/components/ILIAS/Container/Sorting/Service/RepoService.php @@ -0,0 +1,45 @@ +data, $this->db); + } + + public function positions(): PositionsRepo + { + return new PositionsRepo($this->data, $this->db); + } +} diff --git a/components/ILIAS/Container/Sorting/Settings/Manager.php b/components/ILIAS/Container/Sorting/Settings/Manager.php new file mode 100755 index 000000000000..d1a465cba929 --- /dev/null +++ b/components/ILIAS/Container/Sorting/Settings/Manager.php @@ -0,0 +1,171 @@ +getSettingsForObject($obj_id); + if ($direct_settings->getSortMode() !== ilContainer::SORT_INHERIT) { + return $direct_settings; + } + + $inherited_settings = $this->getInheritedSettings($obj_id); + if ( + $inherited_settings === null || + $inherited_settings->getSortMode() === ilContainer::SORT_INHERIT + ) { + return $this->data->sorting()->settings( + $obj_id, + ilContainer::SORT_TITLE, + $direct_settings->getSortDirection(), + $direct_settings->getSortNewItemsPosition(), + $direct_settings->getSortNewItemsOrder() + ); + } else { + return $this->data->sorting()->settings( + $obj_id, + $inherited_settings->getSortMode(), + $direct_settings->getSortDirection(), + $inherited_settings->getSortNewItemsPosition(), + $inherited_settings->getSortNewItemsOrder() + ); + } + } + + /** + * Returns null if there is nothing to inherit. + */ + protected function getInheritedSettings(int $obj_id): ?Settings + { + $ref_ids = ilObject::_getAllReferences($obj_id); + $ref_id = current($ref_ids); + + if ($cont_ref_id = $this->domain->repositoryTree()->checkForParentType($ref_id, 'grp', true)) { + $parent_obj_id = ilObject::_lookupObjId($cont_ref_id); + $parent_settings = $this->getSettingsForObject($parent_obj_id); + + if ($parent_settings->getSortMode() === ilContainer::SORT_INHERIT) { + return $this->getInheritedSettings($parent_obj_id); + } + return $parent_settings; + } + if ($cont_ref_id = $this->domain->repositoryTree()->checkForParentType($ref_id, 'crs', true)) { + $parent_obj_id = ilObject::_lookupObjId($cont_ref_id); + return $this->getSettingsForObject($parent_obj_id); + } + return null; + } + + public function lookupSortModeForObject(int $obj_id): int + { + $sort_mode = $this->repo->sorting()->settings()->getSortModeForObject($obj_id); + if ($sort_mode !== ilContainer::SORT_INHERIT) { + return $sort_mode; + } + return $this->getInheritedSettings($obj_id)?->getSortMode() ?? $sort_mode; + } + + public function cloneSettings( + int $old_id, + int $new_id + ): void { + $old_settings = $this->repo->sorting()->settings()->getSettings($old_id); + if ($old_settings !== null) { + $this->repo->sorting()->settings()->save( + $new_id, + $old_settings->getSortMode(), + $old_settings->getSortDirection(), + $old_settings->getSortNewItemsPosition(), + $old_settings->getSortNewItemsOrder() + ); + } + } + + public function saveSettingsForObject( + int $obj_id, + int $sort_mode, + int $sort_direction, + int $new_items_position, + int $new_items_order + ): void { + $this->repo->sorting()->settings()->save( + $obj_id, + $sort_mode, + $sort_direction, + $new_items_position, + $new_items_order + ); + } + + public function deleteSettingsForObject(int $obj_id): void + { + $this->repo->sorting()->settings()->delete($obj_id); + } + + public function getSettingsForObject(int $obj_id): Settings + { + return $this->repo->sorting()->settings()->getSettings($obj_id) ?? + $this->defaultSettings($obj_id); + } + + protected function defaultSettings(int $obj_id): Settings + { + return $this->data->sorting()->settings( + $obj_id, + ilContainer::SORT_TITLE, + ilContainer::SORT_DIRECTION_ASC, + ilContainer::SORT_NEW_ITEMS_POSITION_BOTTOM, + ilContainer::SORT_NEW_ITEMS_ORDER_TITLE + ); + } + + public function sortModeToString(int $sort_mode): string + { + $lng = $this->domain->lng(); + $lng->loadLanguageModule('crs'); + + return match ($sort_mode) { + ilContainer::SORT_ACTIVATION => $lng->txt('crs_sort_activation'), + ilContainer::SORT_MANUAL => $lng->txt('crs_sort_manual'), + ilContainer::SORT_TITLE => $lng->txt('crs_sort_title'), + ilContainer::SORT_CREATION => $lng->txt('sorting_creation_header'), + default => '', + }; + } +} diff --git a/components/ILIAS/Container/Sorting/Settings/Repository.php b/components/ILIAS/Container/Sorting/Settings/Repository.php new file mode 100755 index 000000000000..173528a67a9e --- /dev/null +++ b/components/ILIAS/Container/Sorting/Settings/Repository.php @@ -0,0 +1,96 @@ +db->quote($obj_id, ilDBConstants::T_INTEGER) . " "; + $res = $this->db->query($query); + + if ($row = $res->fetchAssoc()) { + return (int) $row['sort_mode']; + } + return ilContainer::SORT_INHERIT; + } + + public function save( + int $obj_id, + int $sort_mode, + int $sort_direction, + int $new_items_position, + int $new_items_order + ): void { + $query = "INSERT INTO container_sorting_set " . + "(obj_id, sort_mode, sort_direction, new_items_position, new_items_order) " . + "VALUES ( " . + $this->db->quote($obj_id, ilDBConstants::T_INTEGER) . ", " . + $this->db->quote($sort_mode, ilDBConstants::T_INTEGER) . ", " . + $this->db->quote($sort_direction, ilDBConstants::T_INTEGER) . ', ' . + $this->db->quote($new_items_position, ilDBConstants::T_INTEGER) . ', ' . + $this->db->quote($new_items_order, ilDBConstants::T_INTEGER) . + ") ON DUPLICATE KEY UPDATE " . + "sort_mode = " . $this->db->quote($sort_mode, ilDBConstants::T_INTEGER) . ", " . + "sort_direction = " . $this->db->quote($sort_direction, ilDBConstants::T_INTEGER) . ', ' . + "new_items_position = " . $this->db->quote($new_items_position, ilDBConstants::T_INTEGER) . ', ' . + "new_items_order = " . $this->db->quote($new_items_order, ilDBConstants::T_INTEGER); + + $this->db->manipulate($query); + } + + public function delete(int $obj_id): void + { + $query = 'DELETE FROM container_sorting_set WHERE obj_id = ' . + $this->db->quote($obj_id, ilDBConstants::T_INTEGER); + $this->db->query($query); + } + + public function getSettings(int $obj_id): ?Settings + { + $query = "SELECT * FROM container_sorting_set " . + "WHERE obj_id = " . $this->db->quote($obj_id, ilDBConstants::T_INTEGER); + + $res = $this->db->query($query); + if ($row = $res->fetchAssoc()) { + return $this->data->sorting()->settings( + $obj_id, + (int) $row['sort_mode'], + (int) $row['sort_direction'], + (int) $row['new_items_position'], + (int) $row['new_items_order'] + ); + } + return null; + } +} diff --git a/components/ILIAS/Container/Sorting/Settings/Settings.php b/components/ILIAS/Container/Sorting/Settings/Settings.php new file mode 100755 index 000000000000..2f779a5a4b15 --- /dev/null +++ b/components/ILIAS/Container/Sorting/Settings/Settings.php @@ -0,0 +1,58 @@ +obj_id; + } + + public function getSortMode(): int + { + return $this->sort_mode; + } + + public function getSortDirection(): int + { + return $this->sort_direction; + } + + public function getSortNewItemsPosition(): int + { + return $this->new_items_position; + } + + public function getSortNewItemsOrder(): int + { + return $this->new_items_order; + } +} diff --git a/components/ILIAS/Container/Sorting/class.ilContainerSorting.php b/components/ILIAS/Container/Sorting/class.ilContainerSorting.php index ca82fc6388d5..9d85d33aaf9a 100755 --- a/components/ILIAS/Container/Sorting/class.ilContainerSorting.php +++ b/components/ILIAS/Container/Sorting/class.ilContainerSorting.php @@ -16,20 +16,21 @@ * *********************************************************************/ +use ILIAS\Container\Sorting\Service\DomainService as SortingDomainService; + /** - * + * @deprecated Please use the sorting domain service from the Container services. Will be removed with ILIAS 13. * @author Stefan Meyer */ class ilContainerSorting { - protected const ORDER_DEFAULT = 999999; + protected const int ORDER_DEFAULT = 999999; + + protected SortingDomainService $sorting_domain; - protected ilLogger $log; - protected ilTree $tree; /** @var array */ protected static array $instances = []; protected int $obj_id; - protected ilDBInterface $db; protected ?ilContainerSortingSettings $sorting_settings = null; protected array $sorting = []; @@ -37,11 +38,8 @@ private function __construct(int $a_obj_id) { global $DIC; - $this->log = $DIC["ilLog"]; - $this->tree = $DIC->repositoryTree(); - $ilDB = $DIC->database(); + $this->sorting_domain = $DIC->container()->internal()->domain()->sorting(); - $this->db = $ilDB; $this->obj_id = $a_obj_id; $this->read(); @@ -65,16 +63,13 @@ public static function lookupPositions(int $a_obj_id): array { global $DIC; - $ilDB = $DIC->database(); + $groupings = $DIC->container()->internal()->domain()->sorting()->positions()->getPositionsInObject($a_obj_id); $sorted = []; - - $query = "SELECT child_id, position FROM container_sorting WHERE " . - "obj_id = " . $ilDB->quote($a_obj_id, 'integer'); - $res = $ilDB->query($query); - while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) { - $sorted[(int) $row->child_id] = (int) $row->position; + foreach ($groupings as $grouping) { + foreach ($grouping->getPositions() as $position) { + $sorted[$position->getChildID()] = $position->getPosition(); + } } - return $sorted; } @@ -82,102 +77,16 @@ public function cloneSorting( int $a_target_id, int $a_copy_id ): void { - $ilDB = $this->db; - - $ilLog = ilLoggerFactory::getLogger("cont"); - $ilLog->debug("Cloning container sorting."); - - $target_obj_id = ilObject::_lookupObjId($a_target_id); - - $mappings = ilCopyWizardOptions::_getInstance($a_copy_id)->getMappings(); - - - // copy blocks sorting - $set = $ilDB->queryF( - "SELECT * FROM container_sorting_bl " . - " WHERE obj_id = %s ", - ["integer"], - [$this->obj_id] + $this->sorting_domain->positions()->clonePositions( + $this->obj_id, + $a_target_id, + $a_copy_id ); - if (($rec = $ilDB->fetchAssoc($set)) && $rec["block_ids"] != "") { - $ilLog->debug("Got block sorting for obj_id = " . $this->obj_id . ": " . $rec["block_ids"]); - $new_block_ids = []; - foreach (explode(";", $rec["block_ids"]) as $block_id) { - if (is_numeric($block_id) && isset($mappings[$block_id])) { - $new_block_ids[] = $mappings[$block_id]; - } else { - $new_block_ids[] = $block_id; - } - } - $new_ids = implode(";", $new_block_ids); - - $ilDB->replace( - "container_sorting_bl", - ["obj_id" => ["integer", $target_obj_id]], - ["block_ids" => ["text", $new_ids]] - ); - - $ilLog->debug("Write block sorting for obj_id = " . $target_obj_id . ": " . $new_ids); - } - - - $ilLog->debug("Read container_sorting for obj_id = " . $this->obj_id); - - $query = "SELECT * FROM container_sorting " . - "WHERE obj_id = " . $ilDB->quote($this->obj_id, 'integer'); - - $res = $ilDB->query($query); - - while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) { - if (!isset($mappings[$row->child_id]) || !$mappings[$row->child_id]) { - $ilLog->debug("No mapping found for child id:" . $row->child_id); - continue; - } - - - $new_parent_id = 0; - if ($row->parent_id) { - // see bug #20347 - // at least in the case of sessions and item groups parent_ids in container sorting are object IDs but $mappings store references - if (in_array($row->parent_type, ["sess", "itgr"])) { - $par_refs = ilObject::_getAllReferences($row->parent_id); - $par_ref_id = current($par_refs); // should be only one - $ilLog->debug("Got ref id: " . $par_ref_id . " for obj_id " . $row->parent_id . " map ref id: " . ($mappings[$par_ref_id] ?? "") . "."); - if (isset($mappings[$par_ref_id])) { - $new_parent_ref_id = $mappings[$par_ref_id]; - $new_parent_id = ilObject::_lookupObjectId($new_parent_ref_id); - } - } else { // not sure if this is still used for other cases that expect ref ids - $new_parent_id = $mappings[$row->parent_id]; - } - if ((int) $new_parent_id === 0) { - $ilLog->debug("No mapping found for parent id:" . $row->parent_id . ", child_id: " . $row->child_id); - continue; - } - } - - $query = "DELETE FROM container_sorting " . - "WHERE obj_id = " . $ilDB->quote($target_obj_id, 'integer') . " " . - "AND child_id = " . $ilDB->quote($mappings[$row->child_id], 'integer') . " " . - "AND parent_type = " . $ilDB->quote($row->parent_type, 'text') . ' ' . - "AND parent_id = " . $ilDB->quote((int) $new_parent_id, 'integer'); - $ilLog->debug($query); - $ilDB->manipulate($query); - - // Add new value - $query = "INSERT INTO container_sorting (obj_id,child_id,position,parent_type,parent_id) " . - "VALUES( " . - $ilDB->quote($target_obj_id, 'integer') . ", " . - $ilDB->quote($mappings[$row->child_id], 'integer') . ", " . - $ilDB->quote($row->position, 'integer') . ", " . - $ilDB->quote($row->parent_type, 'text') . ", " . - $ilDB->quote((int) $new_parent_id, 'integer') . - ")"; - $ilLog->debug($query); - $ilDB->manipulate($query); - } } + /** + * TODO move to a new Sorter + */ public function sortItems(array $a_items): array { if (!is_array($a_items)) { @@ -285,6 +194,7 @@ public function sortItems(array $a_items): array } /** + * TODO move to a new Sorter * sort subitems (items of sessions or learning objectives) */ public function sortSubItems( @@ -336,113 +246,15 @@ public function sortSubItems( */ public function savePost(array $a_type_positions): void { - if (!is_array($a_type_positions)) { - return; - } - $items = []; - foreach ($a_type_positions as $key => $position) { - if ($key === "blocks") { - $this->saveBlockPositions($position); - } elseif (!is_array($position)) { - $items[$key] = ((float) $position) * 100; - } else { - foreach ($position as $parent_id => $sub_items) { - $this->saveSubItems($key, $parent_id, $sub_items ?: []); - } - } - } - - if (!count($items)) { - $this->saveItems([]); - return; - } - - asort($items); - $new_indexed = []; - $position = 0; - foreach ($items as $key => $null) { - $new_indexed[$key] = ++$position; - } - - $this->saveItems($new_indexed); - } - - protected function saveItems(array $a_items): void - { - $ilDB = $this->db; - - foreach ($a_items as $child_id => $position) { - $ilDB->replace( - 'container_sorting', - [ - 'obj_id' => ['integer', $this->obj_id], - 'child_id' => ['integer', $child_id], - 'parent_id' => ['integer', 0] - ], - [ - 'parent_type' => ['text', ''], - 'position' => ['integer', $position] - ] - ); - } - } - - protected function saveSubItems( - string $a_parent_type, - int $a_parent_id, - array $a_items - ): void { - $ilDB = $this->db; - - foreach ($a_items as $child_id => $position) { - $ilDB->replace( - 'container_sorting', - [ - 'obj_id' => ['integer', $this->obj_id], - 'child_id' => ['integer', $child_id], - 'parent_id' => ['integer', $a_parent_id] - ], - [ - 'parent_type' => ['text', $a_parent_type], - 'position' => ['integer', $position] - ] - ); - } - } - - /** - * Save block custom positions (for current object id) - */ - protected function saveBlockPositions(array $a_values): void - { - $ilDB = $this->db; - asort($a_values); - $ilDB->replace( - 'container_sorting_bl', - [ - 'obj_id' => ['integer', $this->obj_id] - ], - [ - 'block_ids' => ['text', implode(";", array_keys($a_values))] - ] - ); + $this->sorting_domain->positions()->saveFromPost($this->obj_id, $a_type_positions); } /** + * Not in use anymore. * Read block custom positions (for current object id) */ public function getBlockPositions(): array { - $ilDB = $this->db; - - $set = $ilDB->query("SELECT block_ids" . - " FROM container_sorting_bl" . - " WHERE obj_id = " . $ilDB->quote($this->obj_id, "integer")); - $row = $ilDB->fetchAssoc($set); - if (isset($row["block_ids"])) { - return explode(";", $row["block_ids"]); - } - return []; } @@ -454,19 +266,22 @@ private function read(): void $sorting_settings = ilContainerSortingSettings::getInstanceByObjId($this->obj_id); $this->sorting_settings = $sorting_settings->loadEffectiveSettings(); - $query = "SELECT * FROM container_sorting " . - "WHERE obj_id = " . $this->db->quote($this->obj_id, 'integer') . " ORDER BY position"; - $res = $this->db->query($query); - while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) { - if ($row->parent_id) { - $this->sorting[$row->parent_type][$row->parent_id][$row->child_id] = $row->position; - } else { - $this->sorting['all'][$row->child_id] = $row->position; + + $groupings = $this->sorting_domain->positions()->getPositionsInObject($this->obj_id); + + foreach ($groupings as $grouping) { + foreach ($grouping->getPositions() as $position) { + if ($grouping->getParentID()) { + $this->sorting[$grouping->getParentType()][$grouping->getParentID()][$position->getChildID()] = $position->getPosition(); + } else { + $this->sorting['all'][$position->getChildID()] = $position->getPosition(); + } } } } /** + * TODO move to a new Sorter * Position and order sort order for new object without position in manual sorting type */ private function sortOrderDefault(array $items): array diff --git a/components/ILIAS/Container/Sorting/class.ilContainerSortingSettings.php b/components/ILIAS/Container/Sorting/class.ilContainerSortingSettings.php index f9f10cf8f94d..7c7a89090c86 100755 --- a/components/ILIAS/Container/Sorting/class.ilContainerSortingSettings.php +++ b/components/ILIAS/Container/Sorting/class.ilContainerSortingSettings.php @@ -16,12 +16,16 @@ * *********************************************************************/ +use ILIAS\Container\Sorting\Service\DomainService as SortingDomainService; + /** + * @deprecated Please use the sorting domain service from the Container services. Will be removed with ILIAS 13. * @author Stefan Meyer */ class ilContainerSortingSettings { - protected ilTree $tree; + protected SortingDomainService $sorting_domain; + /** @var array */ private static array $instances = []; protected int $obj_id; @@ -29,17 +33,14 @@ class ilContainerSortingSettings protected int $sort_direction = ilContainer::SORT_DIRECTION_ASC; protected int $new_items_position = ilContainer::SORT_NEW_ITEMS_POSITION_BOTTOM; protected int $new_items_order = ilContainer::SORT_NEW_ITEMS_ORDER_TITLE; - protected ilDBInterface $db; public function __construct(int $a_obj_id = 0) { global $DIC; - $this->tree = $DIC->repositoryTree(); - $ilDB = $DIC->database(); + $this->sorting_domain = $DIC->container()->internal()->domain()->sorting(); $this->obj_id = $a_obj_id; - $this->db = $ilDB; $this->read(); } @@ -54,94 +55,28 @@ public static function getInstanceByObjId(int $a_obj_id): self */ public function loadEffectiveSettings(): self { - if ($this->getSortMode() !== ilContainer::SORT_INHERIT) { - return $this; - } - - $effective_settings = $this->getInheritedSettings($this->obj_id); - $inherited = clone $this; - - if ($effective_settings->getSortMode() === ilContainer::SORT_INHERIT) { - $inherited->setSortMode(ilContainer::SORT_TITLE); - } else { - $inherited->setSortMode($effective_settings->getSortMode()); - $inherited->setSortNewItemsOrder($effective_settings->getSortNewItemsOrder()); - $inherited->setSortNewItemsPosition($effective_settings->getSortNewItemsPosition()); - } - return $inherited; - } - - - public function getInheritedSettings(int $a_container_obj_id): self - { - $tree = $this->tree; - - if (!$a_container_obj_id) { - $a_container_obj_id = $this->obj_id; - } - - $ref_ids = ilObject::_getAllReferences($a_container_obj_id); - $ref_id = current($ref_ids); - - if ($cont_ref_id = $tree->checkForParentType($ref_id, 'grp', true)) { - $parent_obj_id = ilObject::_lookupObjId($cont_ref_id); - $parent_settings = self::getInstanceByObjId($parent_obj_id); - - if ($parent_settings->getSortMode() === ilContainer::SORT_INHERIT) { - return $this->getInheritedSettings($parent_obj_id); - } - return $parent_settings; - } - - if ($cont_ref_id = $tree->checkForParentType($ref_id, 'crs', true)) { - $parent_obj_id = ilObject::_lookupObjId($cont_ref_id); - $parent_settings = self::getInstanceByObjId($parent_obj_id); - return $parent_settings; - } - // no parent settings found => return current settings - return $this; - } - - - public static function _readSortMode(int $a_obj_id): int - { - global $DIC; - - $ilDB = $DIC->database(); + $effective_settings = $this->sorting_domain->settings()->getEffectiveSettingsForObject($this->obj_id); - $query = "SELECT sort_mode FROM container_sorting_set " . - "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " "; - $res = $ilDB->query($query); + $effective = clone $this; + $effective->setSortMode($effective_settings->getSortMode()); + $effective->setSortDirection($effective_settings->getSortDirection()); + $effective->setSortNewItemsOrder($effective_settings->getSortNewItemsOrder()); + $effective->setSortNewItemsPosition($effective_settings->getSortNewItemsPosition()); - while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) { - return (int) $row->sort_mode; - } - return ilContainer::SORT_INHERIT; + return $effective; } public static function _lookupSortMode(int $a_obj_id): int { global $DIC; - $ilDB = $DIC->database(); - - // Try to read from table - $query = "SELECT sort_mode FROM container_sorting_set " . - "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " "; - $res = $ilDB->query($query); - - while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) { - if ((int) $row->sort_mode !== ilContainer::SORT_INHERIT) { - return (int) $row->sort_mode; - } - } - return self::lookupSortModeFromParentContainer($a_obj_id); + return $DIC->container()->internal()->domain()->sorting()->settings()->lookupSortModeForObject($a_obj_id); } - public static function lookupSortModeFromParentContainer(int $a_obj_id): int + public static function lookupEffectiveSortMode(int $a_obj_id): int { $settings = self::getInstanceByObjId($a_obj_id); - $inherited_settings = $settings->getInheritedSettings($a_obj_id); + $inherited_settings = $settings->loadEffectiveSettings(); return $inherited_settings->getSortMode(); } @@ -151,38 +86,20 @@ public static function _cloneSettings( ): void { global $DIC; - $ilDB = $DIC->database(); - - $query = "SELECT sort_mode,sort_direction,new_items_position,new_items_order " . - "FROM container_sorting_set " . - "WHERE obj_id = " . $ilDB->quote($a_old_id, 'integer') . " "; - $res = $ilDB->query($query); - while ($row = $ilDB->fetchAssoc($res)) { - $query = "DELETE FROM container_sorting_set " . - "WHERE obj_id = " . $ilDB->quote($a_new_id) . " "; - $ilDB->manipulate($query); - - $query = "INSERT INTO container_sorting_set " . - "(obj_id,sort_mode, sort_direction, new_items_position, new_items_order) " . - "VALUES( " . - $ilDB->quote($a_new_id, 'integer') . ", " . - $ilDB->quote($row["sort_mode"], 'integer') . ", " . - $ilDB->quote($row["sort_direction"], 'integer') . ', ' . - $ilDB->quote($row["new_items_position"], 'integer') . ', ' . - $ilDB->quote($row["new_items_order"], 'integer') . ' ' . - ")"; - $ilDB->manipulate($query); - } + $DIC->container()->internal()->domain()->sorting()->settings()->cloneSettings( + $a_old_id, + $a_new_id, + ); } public function getSortMode(): int { - return $this->sort_mode ?: 0; + return $this->sort_mode; } public function getSortDirection(): int { - return $this->sort_direction ?: ilContainer::SORT_DIRECTION_ASC; + return $this->sort_direction; } public function getSortNewItemsPosition(): int @@ -220,37 +137,29 @@ public function setSortNewItemsOrder(int $a_order): void public function update(): void { - $ilDB = $this->db; - - $query = "DELETE FROM container_sorting_set " . - "WHERE obj_id = " . $ilDB->quote($this->obj_id, 'integer'); - $ilDB->manipulate($query); - - $this->save(); + $this->sorting_domain->settings()->saveSettingsForObject( + $this->obj_id, + $this->getSortMode(), + $this->getSortDirection(), + $this->getSortNewItemsPosition(), + $this->getSortNewItemsOrder() + ); } public function save(): void { - $ilDB = $this->db; - - $query = "INSERT INTO container_sorting_set " . - "(obj_id,sort_mode, sort_direction, new_items_position, new_items_order) " . - "VALUES ( " . - $this->db->quote($this->obj_id, 'integer') . ", " . - $this->db->quote($this->sort_mode, 'integer') . ", " . - $this->db->quote($this->sort_direction, 'integer') . ', ' . - $this->db->quote($this->new_items_position, 'integer') . ', ' . - $this->db->quote($this->new_items_order, 'integer') . ' ' . - ")"; - $ilDB->manipulate($query); + $this->sorting_domain->settings()->saveSettingsForObject( + $this->obj_id, + $this->getSortMode(), + $this->getSortDirection(), + $this->getSortNewItemsPosition(), + $this->getSortNewItemsOrder() + ); } public function delete(): void { - $ilDB = $this->db; - - $query = 'DELETE FROM container_sorting_set WHERE obj_id = ' . $ilDB->quote($this->obj_id, 'integer'); - $ilDB->query($query); + $this->sorting_domain->settings()->deleteSettingsForObject($this->obj_id); } protected function read(): void @@ -259,17 +168,11 @@ protected function read(): void return; } - $query = "SELECT * FROM container_sorting_set " . - "WHERE obj_id = " . $this->db->quote($this->obj_id, 'integer') . " "; - - $res = $this->db->query($query); - while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) { - $this->sort_mode = (int) $row->sort_mode; - $this->sort_direction = (int) $row->sort_direction; - $this->new_items_position = (int) $row->new_items_position; - $this->new_items_order = (int) $row->new_items_order; - return; - } + $settings = $this->sorting_domain->settings()->getSettingsForObject($this->obj_id); + $this->sort_mode = $settings->getSortMode(); + $this->sort_direction = $settings->getSortDirection(); + $this->new_items_position = $settings->getSortNewItemsPosition(); + $this->new_items_order = $settings->getSortNewItemsOrder(); } /** @@ -279,26 +182,11 @@ public static function sortModeToString(int $a_sort_mode): string { global $DIC; - $lng = $DIC->language(); - - $lng->loadLanguageModule('crs'); - switch ($a_sort_mode) { - case ilContainer::SORT_ACTIVATION: - return $lng->txt('crs_sort_activation'); - - case ilContainer::SORT_MANUAL: - return $lng->txt('crs_sort_manual'); - - case ilContainer::SORT_TITLE: - return $lng->txt('crs_sort_title'); - - case ilContainer::SORT_CREATION: - return $lng->txt('sorting_creation_header'); - } - return ''; + return $DIC->container()->internal()->domain()->sorting()->settings()->sortModeToString($a_sort_mode); } /** + * TODO still used in SOAP export of course/group * sorting XML-export for all container objects */ public static function _exportContainerSortingSettings( @@ -360,6 +248,7 @@ public static function _exportContainerSortingSettings( } /** + * TODO still used in legacy and SOAP import of category/folder/course/group * sorting import for all container objects */ public static function _importContainerSortingSettings( diff --git a/components/ILIAS/Container/classes/class.ilContainerGUI.php b/components/ILIAS/Container/classes/class.ilContainerGUI.php index 0a7f7154ccc0..6edd20d19b9b 100755 --- a/components/ILIAS/Container/classes/class.ilContainerGUI.php +++ b/components/ILIAS/Container/classes/class.ilContainerGUI.php @@ -2285,7 +2285,7 @@ protected function initSortingForm( $sort_inherit->setTitle( $this->lng->txt('sort_inherit_prefix') . ' (' . ilContainerSortingSettings::sortModeToString( - ilContainerSortingSettings::lookupSortModeFromParentContainer( + ilContainerSortingSettings::lookupEffectiveSortMode( $this->object->getId() ) ) . ') ' diff --git a/components/ILIAS/Course/classes/class.ilCourseExporter.php b/components/ILIAS/Course/classes/class.ilCourseExporter.php index b1b67514bf90..f89063c013b2 100755 --- a/components/ILIAS/Course/classes/class.ilCourseExporter.php +++ b/components/ILIAS/Course/classes/class.ilCourseExporter.php @@ -178,12 +178,19 @@ public function getXmlRepresentation(string $a_entity, string $a_schema_version, public function getValidSchemaVersions(string $a_entity): array { return [ + "12.0" => [ + "namespace" => 'http://www.ilias.de/Modules/Course/crs/12', + "xsd_file" => 'ilias_crs_12_0.xsd', + "uses_dataset" => false, + "min" => "12.0", + "max" => "" + ], "11.0" => [ "namespace" => 'http://www.ilias.de/Modules/Course/crs/11', "xsd_file" => 'ilias_crs_11_0.xsd', "uses_dataset" => false, "min" => "11.0", - "max" => "" + "max" => "11.999" ], "10.0" => [ "namespace" => 'http://www.ilias.de/Modules/Course/crs/10', diff --git a/components/ILIAS/Course/classes/class.ilCourseXMLWriter.php b/components/ILIAS/Course/classes/class.ilCourseXMLWriter.php index d8a715295b82..847e860344aa 100755 --- a/components/ILIAS/Course/classes/class.ilCourseXMLWriter.php +++ b/components/ILIAS/Course/classes/class.ilCourseXMLWriter.php @@ -86,7 +86,6 @@ public function start(): void } elseif ($this->getMode() == self::MODE_EXPORT) { $this->__buildCourseStart(); $this->__buildSetting(); - ilContainerSortingSettings::_exportContainerSortingSettings($this, $this->course_obj->getId()); ilContainer::_exportContainerSettings($this, $this->course_obj->getId()); $this->__buildFooter(); } diff --git a/components/ILIAS/Export/xml/SchemaValidation/ilias_cat_12_0.xsd b/components/ILIAS/Export/xml/SchemaValidation/ilias_cat_12_0.xsd new file mode 100755 index 000000000000..ae524b931037 --- /dev/null +++ b/components/ILIAS/Export/xml/SchemaValidation/ilias_cat_12_0.xsd @@ -0,0 +1,200 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/ILIAS/Export/xml/SchemaValidation/ilias_crs_12_0.xsd b/components/ILIAS/Export/xml/SchemaValidation/ilias_crs_12_0.xsd new file mode 100644 index 000000000000..85854417e714 --- /dev/null +++ b/components/ILIAS/Export/xml/SchemaValidation/ilias_crs_12_0.xsd @@ -0,0 +1,169 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/ILIAS/Export/xml/SchemaValidation/ilias_exp_comp_12_0.xsd b/components/ILIAS/Export/xml/SchemaValidation/ilias_exp_comp_12_0.xsd new file mode 100644 index 000000000000..5b0a7eb772e4 --- /dev/null +++ b/components/ILIAS/Export/xml/SchemaValidation/ilias_exp_comp_12_0.xsd @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/components/ILIAS/Export/xml/SchemaValidation/ilias_fold_12_0.xsd b/components/ILIAS/Export/xml/SchemaValidation/ilias_fold_12_0.xsd new file mode 100755 index 000000000000..597156517376 --- /dev/null +++ b/components/ILIAS/Export/xml/SchemaValidation/ilias_fold_12_0.xsd @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + diff --git a/components/ILIAS/Export/xml/SchemaValidation/ilias_grp_12_0.xsd b/components/ILIAS/Export/xml/SchemaValidation/ilias_grp_12_0.xsd new file mode 100755 index 000000000000..16d6d32e1ca2 --- /dev/null +++ b/components/ILIAS/Export/xml/SchemaValidation/ilias_grp_12_0.xsd @@ -0,0 +1,161 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/ILIAS/Folder/classes/class.ilFolderExporter.php b/components/ILIAS/Folder/classes/class.ilFolderExporter.php index 3af5c595a54a..811d864ed68a 100755 --- a/components/ILIAS/Folder/classes/class.ilFolderExporter.php +++ b/components/ILIAS/Folder/classes/class.ilFolderExporter.php @@ -57,12 +57,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/Folder/fold/12", + "xsd_file" => "ilias_fold_12_0.xsd", + "uses_dataset" => false, + "min" => "12.0", + "max" => "" + ], "4.1.0" => [ "namespace" => "https://www.ilias.de/Modules/Folder/fold/4_1", "xsd_file" => "ilias_fold_4_1.xsd", "uses_dataset" => false, "min" => "4.1.0", - "max" => "" + "max" => "11.999" ] ]; } diff --git a/components/ILIAS/Folder/classes/class.ilFolderXmlWriter.php b/components/ILIAS/Folder/classes/class.ilFolderXmlWriter.php index 3326f7c8c344..e103d5035530 100755 --- a/components/ILIAS/Folder/classes/class.ilFolderXmlWriter.php +++ b/components/ILIAS/Folder/classes/class.ilFolderXmlWriter.php @@ -49,7 +49,6 @@ public function write(): void $this->xmlStartTag('Folder', ['Id' => $this->folder->getId()]); $this->xmlElement('Title', [], $this->folder->getTitle()); $this->xmlElement('Description', [], $this->folder->getDescription()); - ilContainerSortingSettings::_exportContainerSortingSettings($this, $this->obj_id); $this->xmlEndTag('Folder'); } diff --git a/components/ILIAS/Group/classes/class.ilGroupExporter.php b/components/ILIAS/Group/classes/class.ilGroupExporter.php index 8f5eb90e6ce4..c0524b96e154 100755 --- a/components/ILIAS/Group/classes/class.ilGroupExporter.php +++ b/components/ILIAS/Group/classes/class.ilGroupExporter.php @@ -133,12 +133,19 @@ protected function getActiveAdvMDRecords(int $a_id): array public function getValidSchemaVersions(string $a_entity): array { return [ + "12.0" => [ + "namespace" => 'http://www.ilias.de/Modules/Group/grp/12', + "xsd_file" => 'ilias_grp_12_0.xsd', + "uses_dataset" => false, + "min" => "12.0", + "max" => "" + ], "11.0" => [ "namespace" => 'http://www.ilias.de/Modules/Group/grp/11', "xsd_file" => 'ilias_grp_11_0.xsd', "uses_dataset" => false, "min" => "11.0", - "max" => "" + "max" => "11.999" ], "9.0" => [ "namespace" => 'http://www.ilias.de/Modules/Group/grp/9', diff --git a/components/ILIAS/Group/classes/class.ilGroupXMLWriter.php b/components/ILIAS/Group/classes/class.ilGroupXMLWriter.php index c057a72dbc17..d75f2ca66416 100755 --- a/components/ILIAS/Group/classes/class.ilGroupXMLWriter.php +++ b/components/ILIAS/Group/classes/class.ilGroupXMLWriter.php @@ -83,7 +83,6 @@ public function start(): void $this->__buildRegistration(); $this->__buildExtraSettings(); $this->__buildPeriod(); - ilContainerSortingSettings::_exportContainerSortingSettings($this, $this->group_obj->getId()); ilContainer::_exportContainerSettings($this, $this->group_obj->getId()); $this->__buildFooter(); }