40 $this->log =
$DIC[
"ilLog"];
41 $this->tree =
$DIC->repositoryTree();
45 $this->obj_id = $a_obj_id;
57 return self::$instances[$a_obj_id] ?? (self::$instances[$a_obj_id] =
new ilContainerSorting($a_obj_id));
71 $query =
"SELECT child_id, position FROM container_sorting WHERE " .
72 "obj_id = " .
$ilDB->quote($a_obj_id,
'integer');
75 $sorted[(
int) $row->child_id] = (
int) $row->position;
88 $ilLog->debug(
"Cloning container sorting.");
97 "SELECT * FROM container_sorting_bl " .
98 " WHERE obj_id = %s ",
102 if (($rec =
$ilDB->fetchAssoc($set)) && $rec[
"block_ids"] !=
"") {
103 $ilLog->debug(
"Got block sorting for obj_id = " . $this->obj_id .
": " . $rec[
"block_ids"]);
105 foreach (explode(
";", $rec[
"block_ids"]) as $block_id) {
106 if (is_numeric($block_id) && isset($mappings[$block_id])) {
107 $new_block_ids[] = $mappings[$block_id];
109 $new_block_ids[] = $block_id;
112 $new_ids = implode(
";", $new_block_ids);
115 "container_sorting_bl",
116 [
"obj_id" => [
"integer", $target_obj_id]],
117 [
"block_ids" => [
"text", $new_ids]]
120 $ilLog->debug(
"Write block sorting for obj_id = " . $target_obj_id .
": " . $new_ids);
124 $ilLog->debug(
"Read container_sorting for obj_id = " . $this->obj_id);
126 $query =
"SELECT * FROM container_sorting " .
127 "WHERE obj_id = " .
$ilDB->quote($this->obj_id,
'integer');
132 if (!isset($mappings[$row->child_id]) || !$mappings[$row->child_id]) {
133 $ilLog->debug(
"No mapping found for child id:" . $row->child_id);
139 if ($row->parent_id) {
142 if (in_array($row->parent_type, [
"sess",
"itgr"])) {
144 $par_ref_id = current($par_refs);
145 $ilLog->debug(
"Got ref id: " . $par_ref_id .
" for obj_id " . $row->parent_id .
" map ref id: " . ($mappings[$par_ref_id] ??
"") .
".");
146 if (isset($mappings[$par_ref_id])) {
147 $new_parent_ref_id = $mappings[$par_ref_id];
151 $new_parent_id = $mappings[$row->parent_id];
153 if ((
int) $new_parent_id === 0) {
154 $ilLog->debug(
"No mapping found for parent id:" . $row->parent_id .
", child_id: " . $row->child_id);
159 $query =
"DELETE FROM container_sorting " .
160 "WHERE obj_id = " .
$ilDB->quote($target_obj_id,
'integer') .
" " .
161 "AND child_id = " .
$ilDB->quote($mappings[$row->child_id],
'integer') .
" " .
162 "AND parent_type = " .
$ilDB->quote($row->parent_type,
'text') .
' ' .
163 "AND parent_id = " .
$ilDB->quote((
int) $new_parent_id,
'integer');
164 $ilLog->debug($query);
165 $ilDB->manipulate($query);
168 $query =
"INSERT INTO container_sorting (obj_id,child_id,position,parent_type,parent_id) " .
170 $ilDB->quote($target_obj_id,
'integer') .
", " .
171 $ilDB->quote($mappings[$row->child_id],
'integer') .
", " .
172 $ilDB->quote($row->position,
'integer') .
", " .
173 $ilDB->quote($row->parent_type,
'text') .
", " .
174 $ilDB->quote((
int) $new_parent_id,
'integer') .
176 $ilLog->debug($query);
177 $ilDB->manipulate($query);
183 if (!is_array($a_items)) {
189 switch ($this->getSortingSettings()->getSortMode()) {
191 foreach ($a_items as $type =>
$data) {
193 if ($type ===
'sess_link') {
194 $sorted[$type] =
$data;
214 return $sorted ?: [];
217 foreach ($a_items as $type =>
$data) {
219 if ($type ===
'sess_link') {
220 $sorted[$type] =
$data;
231 return $sorted ?: [];
235 foreach ($a_items as $type =>
$data) {
237 if ($type ===
'sess_link') {
238 $sorted[$type] =
$data;
249 return $sorted ?: [];
253 if (!is_array($a_items) || !count($a_items)) {
257 foreach ($a_items as $type =>
$data) {
258 if ($type ===
'sess_link') {
259 $sorted[$type] =
$data;
265 foreach ((array)
$data as $key => $item) {
266 $items[$key] = $item;
267 if (isset($item[
'child'], $this->sorting[
'all'][$item[
'child']])) {
268 $items[$key][
'position'] = $this->sorting[
'all'][$item[
'child']];
270 $items[$key][
'position'] = self::ORDER_DEFAULT;
274 $items = $this->sortOrderDefault($items);
284 return $sorted ?: [];
291 string $a_parent_type,
295 switch ($this->getSortingSettings()->getSortMode()) {
298 foreach ($a_items as $key => $item) {
299 $items[$key] = $item;
300 $items[$key][
'position'] = $this->sorting[$a_parent_type][$a_parent_id][$item[
'child']] ?? self::ORDER_DEFAULT;
303 $items = $this->sortOrderDefault($items);
337 public function savePost(array $a_type_positions): void
339 if (!is_array($a_type_positions)) {
343 foreach ($a_type_positions as $key => $position) {
344 if ($key ===
"blocks") {
345 $this->saveBlockPositions($position);
346 } elseif (!is_array($position)) {
347 $items[$key] = ((float) $position) * 100;
349 foreach ($position as $parent_id => $sub_items) {
350 $this->saveSubItems($key, $parent_id, $sub_items ?: []);
355 if (!count($items)) {
356 $this->saveItems([]);
363 foreach ($items as $key => $null) {
364 $new_indexed[$key] = ++$position;
367 $this->saveItems($new_indexed);
374 foreach ($a_items as $child_id => $position) {
378 'obj_id' => [
'integer', $this->obj_id],
379 'child_id' => [
'integer', $child_id],
380 'parent_id' => [
'integer', 0]
383 'parent_type' => [
'text',
''],
384 'position' => [
'integer', $position]
391 string $a_parent_type,
397 foreach ($a_items as $child_id => $position) {
401 'obj_id' => [
'integer', $this->obj_id],
402 'child_id' => [
'integer', $child_id],
403 'parent_id' => [
'integer', $a_parent_id]
406 'parent_type' => [
'text', $a_parent_type],
407 'position' => [
'integer', $position]
421 'container_sorting_bl',
423 'obj_id' => [
'integer', $this->obj_id]
426 'block_ids' => [
'text', implode(
";", array_keys($a_values))]
438 $set =
$ilDB->query(
"SELECT block_ids" .
439 " FROM container_sorting_bl" .
440 " WHERE obj_id = " .
$ilDB->quote($this->obj_id,
"integer"));
441 $row =
$ilDB->fetchAssoc($set);
442 if (isset($row[
"block_ids"])) {
443 return explode(
";", $row[
"block_ids"]);
451 if (!$this->obj_id) {
457 $query =
"SELECT * FROM container_sorting " .
458 "WHERE obj_id = " . $this->db->quote($this->obj_id,
'integer') .
" ORDER BY position";
459 $res = $this->db->query($query);
461 if ($row->parent_id) {
462 $this->sorting[$row->parent_type][$row->parent_id][$row->child_id] = $row->position;
464 $this->sorting[
'all'][$row->child_id] = $row->position;
476 foreach ($items as $key => $item) {
477 if ($item[
"position"] == self::ORDER_DEFAULT) {
480 "title" => $item[
"title"] ??
"",
481 "create_date" => $item[
"create_date"] ??
"",
482 "start" => $item[
"start"] ??
""
487 if (!count($no_position)) {
491 switch ($this->getSortingSettings()->getSortNewItemsOrder()) {
522 foreach ($no_position as $values) {
523 $items[$values[
"key"]][
"position"] = $count;
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstanceByObjId(int $a_obj_id)
loadEffectiveSettings()
Load inherited settings.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
saveSubItems(string $a_parent_type, int $a_parent_id, array $a_items)
__construct(int $a_obj_id)
getBlockPositions()
Read block custom positions (for current object id)
static _getInstance(int $a_obj_id)
saveBlockPositions(array $a_values)
Save block custom positions (for current object id)
static lookupPositions(int $a_obj_id)
sortItems(array $a_items)
savePost(array $a_type_positions)
ilContainerSortingSettings $sorting_settings
cloneSorting(int $a_target_id, int $a_copy_id)
saveItems(array $a_items)
sortSubItems(string $a_parent_type, int $a_parent_id, array $a_items)
sort subitems (items of sessions or learning objectives)
sortOrderDefault(array $items)
Position and order sort order for new object without position in manual sorting type.
const SORT_NEW_ITEMS_ORDER_ACTIVATION
const SORT_NEW_ITEMS_ORDER_TITLE
const SORT_NEW_ITEMS_ORDER_CREATION
const SORT_NEW_ITEMS_POSITION_TOP
static _getInstance(int $a_copy_id)
static getLogger(string $a_component_id)
Get component logger.
Component logger with individual log levels by component id.
static _lookupObjectId(int $ref_id)
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupObjId(int $ref_id)
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...