ILIAS  release_8 Revision v8.24
ilContainerSorting Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilContainerSorting:

Public Member Functions

 getSortingSettings ()
 
 cloneSorting (int $a_target_id, int $a_copy_id)
 
 sortItems (array $a_items)
 
 sortSubItems (string $a_parent_type, int $a_parent_id, array $a_items)
 sort subitems (items of sessions or learning objectives) More...
 
 savePost (array $a_type_positions)
 
 getBlockPositions ()
 Read block custom positions (for current object id) More...
 

Static Public Member Functions

static _getInstance (int $a_obj_id)
 
static lookupPositions (int $a_obj_id)
 

Protected Member Functions

 saveItems (array $a_items)
 
 saveSubItems (string $a_parent_type, int $a_parent_id, array $a_items)
 
 saveBlockPositions (array $a_values)
 Save block custom positions (for current object id) More...
 

Protected Attributes

const ORDER_DEFAULT = 999999
 
ilLogger $log
 
ilTree $tree
 
int $obj_id
 
ilDBInterface $db
 
ilContainerSortingSettings $sorting_settings = null
 
array $sorting = []
 

Static Protected Attributes

static array $instances = []
 

Private Member Functions

 __construct (int $a_obj_id)
 
 read ()
 
 sortOrderDefault (array $items)
 Position and order sort order for new object without position in manual sorting type. More...
 

Detailed Description

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

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 23 of file class.ilContainerSorting.php.

Constructor & Destructor Documentation

◆ __construct()

ilContainerSorting::__construct ( int  $a_obj_id)
private

Definition at line 36 of file class.ilContainerSorting.php.

37 {
38 global $DIC;
39
40 $this->log = $DIC["ilLog"];
41 $this->tree = $DIC->repositoryTree();
42 $ilDB = $DIC->database();
43
44 $this->db = $ilDB;
45 $this->obj_id = $a_obj_id;
46
47 $this->read();
48 }
global $DIC
Definition: feed.php:28

References $DIC, $ilDB, and read().

+ Here is the call graph for this function:

Member Function Documentation

◆ _getInstance()

static ilContainerSorting::_getInstance ( int  $a_obj_id)
static

◆ cloneSorting()

ilContainerSorting::cloneSorting ( int  $a_target_id,
int  $a_copy_id 
)

Definition at line 81 of file class.ilContainerSorting.php.

84 : void {
86
87 $ilLog = ilLoggerFactory::getLogger("cont");
88 $ilLog->debug("Cloning container sorting.");
89
90 $target_obj_id = ilObject::_lookupObjId($a_target_id);
91
92 $mappings = ilCopyWizardOptions::_getInstance($a_copy_id)->getMappings();
93
94
95 // copy blocks sorting
96 $set = $ilDB->queryF(
97 "SELECT * FROM container_sorting_bl " .
98 " WHERE obj_id = %s ",
99 ["integer"],
100 [$this->obj_id]
101 );
102 if (($rec = $ilDB->fetchAssoc($set)) && $rec["block_ids"] != "") {
103 $ilLog->debug("Got block sorting for obj_id = " . $this->obj_id . ": " . $rec["block_ids"]);
104 $new_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];
108 } else {
109 $new_block_ids[] = $block_id;
110 }
111 }
112 $new_ids = implode(";", $new_block_ids);
113
114 $ilDB->replace(
115 "container_sorting_bl",
116 ["obj_id" => ["integer", $target_obj_id]],
117 ["block_ids" => ["text", $new_ids]]
118 );
119
120 $ilLog->debug("Write block sorting for obj_id = " . $target_obj_id . ": " . $new_ids);
121 }
122
123
124 $ilLog->debug("Read container_sorting for obj_id = " . $this->obj_id);
125
126 $query = "SELECT * FROM container_sorting " .
127 "WHERE obj_id = " . $ilDB->quote($this->obj_id, 'integer');
128
129 $res = $ilDB->query($query);
130
131 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
132 if (!isset($mappings[$row->child_id]) || !$mappings[$row->child_id]) {
133 $ilLog->debug("No mapping found for child id:" . $row->child_id);
134 continue;
135 }
136
137
138 $new_parent_id = 0;
139 if ($row->parent_id) {
140 // see bug #20347
141 // at least in the case of sessions and item groups parent_ids in container sorting are object IDs but $mappings store references
142 if (in_array($row->parent_type, ["sess", "itgr"])) {
143 $par_refs = ilObject::_getAllReferences($row->parent_id);
144 $par_ref_id = current($par_refs); // should be only one
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];
148 $new_parent_id = ilObject::_lookupObjectId($new_parent_ref_id);
149 }
150 } else { // not sure if this is still used for other cases that expect ref ids
151 $new_parent_id = $mappings[$row->parent_id];
152 }
153 if ((int) $new_parent_id === 0) {
154 $ilLog->debug("No mapping found for parent id:" . $row->parent_id . ", child_id: " . $row->child_id);
155 continue;
156 }
157 }
158
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);
166
167 // Add new value
168 $query = "INSERT INTO container_sorting (obj_id,child_id,position,parent_type,parent_id) " .
169 "VALUES( " .
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') .
175 ")";
176 $ilLog->debug($query);
177 $ilDB->manipulate($query);
178 }
179 }
static _getInstance(int $a_copy_id)
static getLogger(string $a_component_id)
Get component logger.
static _lookupObjectId(int $ref_id)
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupObjId(int $ref_id)
$res
Definition: ltiservices.php:69
$query

◆ getBlockPositions()

ilContainerSorting::getBlockPositions ( )

Read block custom positions (for current object id)

Definition at line 435 of file class.ilContainerSorting.php.

435 : array
436 {
438
439 $set = $ilDB->query("SELECT block_ids" .
440 " FROM container_sorting_bl" .
441 " WHERE obj_id = " . $ilDB->quote($this->obj_id, "integer"));
442 $row = $ilDB->fetchAssoc($set);
443 if (isset($row["block_ids"])) {
444 return explode(";", $row["block_ids"]);
445 }
446
447 return [];
448 }

References $ilDB.

◆ getSortingSettings()

ilContainerSorting::getSortingSettings ( )

Definition at line 50 of file class.ilContainerSorting.php.

51 {
53 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilContainerSortingSettings $sorting_settings

References $sorting_settings.

◆ lookupPositions()

static ilContainerSorting::lookupPositions ( int  $a_obj_id)
static
Parameters
int$a_obj_id
Returns
array<int, int>

Definition at line 64 of file class.ilContainerSorting.php.

64 : array
65 {
66 global $DIC;
67
68 $ilDB = $DIC->database();
69 $sorted = [];
70
71 $query = "SELECT child_id, position FROM container_sorting WHERE " .
72 "obj_id = " . $ilDB->quote($a_obj_id, 'integer');
73 $res = $ilDB->query($query);
74 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
75 $sorted[(int) $row->child_id] = (int) $row->position;
76 }
77
78 return $sorted;
79 }

References $DIC, $ilDB, $query, $res, ilDBConstants\FETCHMODE_OBJECT, and ILIAS\Repository\int().

Referenced by ilWebLinkItemsContainer\sort().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read()

ilContainerSorting::read ( )
private

Definition at line 450 of file class.ilContainerSorting.php.

450 : void
451 {
452 if (!$this->obj_id) {
453 $this->sorting_settings = new ilContainerSortingSettings();
454 }
455
457 $this->sorting_settings = $sorting_settings->loadEffectiveSettings();
458 $query = "SELECT * FROM container_sorting " .
459 "WHERE obj_id = " . $this->db->quote($this->obj_id, 'integer') . " ORDER BY position";
460 $res = $this->db->query($query);
461 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
462 if ($row->parent_id) {
463 $this->sorting[$row->parent_type][$row->parent_id][$row->child_id] = $row->position;
464 } else {
465 $this->sorting['all'][$row->child_id] = $row->position;
466 }
467 }
468 }
loadEffectiveSettings()
Load inherited settings.

References $query, $res, ilDBConstants\FETCHMODE_OBJECT, ilContainerSortingSettings\getInstanceByObjId(), and ilContainerSortingSettings\loadEffectiveSettings().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveBlockPositions()

ilContainerSorting::saveBlockPositions ( array  $a_values)
protected

Save block custom positions (for current object id)

Definition at line 417 of file class.ilContainerSorting.php.

417 : void
418 {
420 asort($a_values);
421 $ilDB->replace(
422 'container_sorting_bl',
423 [
424 'obj_id' => ['integer', $this->obj_id]
425 ],
426 [
427 'block_ids' => ['text', implode(";", array_keys($a_values))]
428 ]
429 );
430 }

References $ilDB.

◆ saveItems()

ilContainerSorting::saveItems ( array  $a_items)
protected

Definition at line 371 of file class.ilContainerSorting.php.

371 : void
372 {
374
375 foreach ($a_items as $child_id => $position) {
376 $ilDB->replace(
377 'container_sorting',
378 [
379 'obj_id' => ['integer', $this->obj_id],
380 'child_id' => ['integer', $child_id],
381 'parent_id' => ['integer', 0]
382 ],
383 [
384 'parent_type' => ['text', ''],
385 'position' => ['integer', $position]
386 ]
387 );
388 }
389 }

References $ilDB.

◆ savePost()

ilContainerSorting::savePost ( array  $a_type_positions)
Parameters
array$a_type_positionspositions e.g array(crs => array(1,2,3),'lres' => array(3,5,6))

Definition at line 338 of file class.ilContainerSorting.php.

338 : void
339 {
340 if (!is_array($a_type_positions)) {
341 return;
342 }
343 $items = [];
344 foreach ($a_type_positions as $key => $position) {
345 if ($key === "blocks") {
346 $this->saveBlockPositions($position);
347 } elseif (!is_array($position)) {
348 $items[$key] = ((float) $position) * 100;
349 } else {
350 foreach ($position as $parent_id => $sub_items) {
351 $this->saveSubItems($key, $parent_id, $sub_items ?: []);
352 }
353 }
354 }
355
356 if (!count($items)) {
357 $this->saveItems([]);
358 return;
359 }
360
361 asort($items);
362 $new_indexed = [];
363 $position = 0;
364 foreach ($items as $key => $null) {
365 $new_indexed[$key] = ++$position;
366 }
367
368 $this->saveItems($new_indexed);
369 }
saveSubItems(string $a_parent_type, int $a_parent_id, array $a_items)
saveBlockPositions(array $a_values)
Save block custom positions (for current object id)
string $key
Consumer key/client ID value.
Definition: System.php:193

References ILIAS\LTI\ToolProvider\$key.

◆ saveSubItems()

ilContainerSorting::saveSubItems ( string  $a_parent_type,
int  $a_parent_id,
array  $a_items 
)
protected

Definition at line 391 of file class.ilContainerSorting.php.

395 : void {
397
398 foreach ($a_items as $child_id => $position) {
399 $ilDB->replace(
400 'container_sorting',
401 [
402 'obj_id' => ['integer', $this->obj_id],
403 'child_id' => ['integer', $child_id],
404 'parent_id' => ['integer', $a_parent_id]
405 ],
406 [
407 'parent_type' => ['text', $a_parent_type],
408 'position' => ['integer', $position]
409 ]
410 );
411 }
412 }

References $ilDB.

◆ sortItems()

ilContainerSorting::sortItems ( array  $a_items)

Definition at line 181 of file class.ilContainerSorting.php.

181 : array
182 {
183 if (!is_array($a_items)) {
184 return [];
185 }
186
187 $sorted = [];
188 if ($this->getSortingSettings()->getSortMode() !== ilContainer::SORT_MANUAL) {
189 switch ($this->getSortingSettings()->getSortMode()) {
191 foreach ($a_items as $type => $data) {
192 // #16311 - sorting will remove keys (prev/next)
193 if ($type === 'sess_link') {
194 $sorted[$type] = $data;
195 continue;
196 }
197
198 // this line used until #4389 has been fixed (3.10.6)
199 // reanimated with 4.4.0
200 $sorted[$type] = ilArrayUtil::sortArray(
201 (array) $data,
202 'title',
203 ($this->getSortingSettings()->getSortDirection() === ilContainer::SORT_DIRECTION_ASC) ? 'asc' : 'desc',
204 false
205 );
206
207 // the next line tried to use db sorting and has replaced sortArray due to bug #4389
208 // but leads to bug #12165. PHP should be able to do a proper sorting, if the locale
209 // is set correctly, so we witch back to sortArray (with 4.4.0) and see what
210 // feedback we get
211 // (next line has been used from 3.10.6 to 4.3.x)
212// $sorted[$type] = $data;
213 }
214 return $sorted ?: [];
215
217 foreach ($a_items as $type => $data) {
218 // #16311 - sorting will remove keys (prev/next)
219 if ($type === 'sess_link') {
220 $sorted[$type] = $data;
221 continue;
222 }
223
224 $sorted[$type] = ilArrayUtil::sortArray(
225 (array) $data,
226 'start',
227 ($this->getSortingSettings()->getSortDirection() === ilContainer::SORT_DIRECTION_ASC) ? 'asc' : 'desc',
228 true
229 );
230 }
231 return $sorted ?: [];
232
233
235 foreach ($a_items as $type => $data) {
236 // #16311 - sorting will remove keys (prev/next)
237 if ($type === 'sess_link') {
238 $sorted[$type] = $data;
239 continue;
240 }
241
242 $sorted[$type] = ilArrayUtil::sortArray(
243 (array) $data,
244 'create_date',
245 ($this->getSortingSettings()->getSortDirection() == ilContainer::SORT_DIRECTION_ASC) ? 'asc' : 'desc',
246 true
247 );
248 }
249 return $sorted ?: [];
250 }
251 return $a_items;
252 }
253 if (!is_array($a_items) || !count($a_items)) {
254 return $a_items;
255 }
256 $sorted = [];
257 foreach ($a_items as $type => $data) {
258 if ($type === 'sess_link') {
259 $sorted[$type] = $data;
260 continue;
261 }
262
263 // Add position
264 $items = [];
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']];
269 } else {
270 $items[$key]['position'] = self::ORDER_DEFAULT;
271 }
272 }
273
274 $items = $this->sortOrderDefault($items);
275
276 switch ($type) {
277
278 case '_non_sess':
279 case '_all':
280 default:
281 $sorted[$type] = ilArrayUtil::sortArray($items, 'position', 'asc', true);
282 break;
283 }
284 }
285 return $sorted ?: [];
286 }
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
sortOrderDefault(array $items)
Position and order sort order for new object without position in manual sorting type.
const SORT_DIRECTION_ASC
$type

References $data, ILIAS\LTI\ToolProvider\$key, $type, ilContainer\SORT_ACTIVATION, ilContainer\SORT_CREATION, ilContainer\SORT_DIRECTION_ASC, ilContainer\SORT_MANUAL, ilContainer\SORT_TITLE, and ilArrayUtil\sortArray().

+ Here is the call graph for this function:

◆ sortOrderDefault()

ilContainerSorting::sortOrderDefault ( array  $items)
private

Position and order sort order for new object without position in manual sorting type.

Definition at line 473 of file class.ilContainerSorting.php.

473 : array
474 {
475 $no_position = [];
476
477 foreach ($items as $key => $item) {
478 if ($item["position"] == self::ORDER_DEFAULT) {
479 $no_position[] = [
480 "key" => $key,
481 "title" => $item["title"] ?? "",
482 "create_date" => $item["create_date"] ?? "",
483 "start" => $item["start"] ?? ""
484 ];
485 }
486 }
487
488 if (!count($no_position)) {
489 return $items;
490 }
491
492 switch ($this->getSortingSettings()->getSortNewItemsOrder()) {
494 $no_position = ilArrayUtil::sortArray(
495 $no_position,
496 'title',
497 ($this->getSortingSettings()->getSortDirection() === ilContainer::SORT_DIRECTION_ASC) ? 'asc' : 'desc',
498 true
499 );
500 break;
502 $no_position = ilArrayUtil::sortArray(
503 $no_position,
504 'create_date',
505 ($this->getSortingSettings()->getSortDirection() === ilContainer::SORT_DIRECTION_ASC) ? 'asc' : 'desc',
506 true
507 );
508 break;
510 $no_position = ilArrayUtil::sortArray(
511 $no_position,
512 'start',
513 ($this->getSortingSettings()->getSortDirection() === ilContainer::SORT_DIRECTION_ASC) ? 'asc' : 'desc',
514 true
515 );
516
517 }
518 $count = (
519 $this->getSortingSettings()->getSortNewItemsPosition() === ilContainer::SORT_NEW_ITEMS_POSITION_TOP
520 ? -900000 :
521 900000
522 );
523
524 foreach ($no_position as $values) {
525 $items[$values["key"]]["position"] = $count;
526 $count++;
527 }
528 return $items;
529 }
const SORT_NEW_ITEMS_ORDER_ACTIVATION
const SORT_NEW_ITEMS_ORDER_TITLE
const SORT_NEW_ITEMS_ORDER_CREATION
const SORT_NEW_ITEMS_POSITION_TOP

References ILIAS\LTI\ToolProvider\$key, ilContainer\SORT_DIRECTION_ASC, ilContainer\SORT_NEW_ITEMS_ORDER_ACTIVATION, ilContainer\SORT_NEW_ITEMS_ORDER_CREATION, ilContainer\SORT_NEW_ITEMS_ORDER_TITLE, ilContainer\SORT_NEW_ITEMS_POSITION_TOP, and ilArrayUtil\sortArray().

+ Here is the call graph for this function:

◆ sortSubItems()

ilContainerSorting::sortSubItems ( string  $a_parent_type,
int  $a_parent_id,
array  $a_items 
)

sort subitems (items of sessions or learning objectives)

Definition at line 291 of file class.ilContainerSorting.php.

295 : array {
296 switch ($this->getSortingSettings()->getSortMode()) {
298 $items = [];
299 foreach ($a_items as $key => $item) {
300 $items[$key] = $item;
301 $items[$key]['position'] = $this->sorting[$a_parent_type][$a_parent_id][$item['child']] ?? self::ORDER_DEFAULT;
302 }
303
304 $items = $this->sortOrderDefault($items);
305 return ilArrayUtil::sortArray($items, 'position', 'asc', true);
306
307
310 $a_items,
311 'start',
312 ($this->getSortingSettings()->getSortDirection() === ilContainer::SORT_DIRECTION_ASC) ? 'asc' : 'desc',
313 true
314 );
315
318 $a_items,
319 'create_date',
320 ($this->getSortingSettings()->getSortDirection() === ilContainer::SORT_DIRECTION_ASC) ? 'asc' : 'desc',
321 true
322 );
323
324 default:
327 $a_items,
328 'title',
329 ($this->getSortingSettings()->getSortDirection() === ilContainer::SORT_DIRECTION_ASC) ? 'asc' : 'desc',
330 false
331 );
332 }
333 }

References ILIAS\LTI\ToolProvider\$key, ilContainer\SORT_ACTIVATION, ilContainer\SORT_CREATION, ilContainer\SORT_DIRECTION_ASC, ilContainer\SORT_MANUAL, ilContainer\SORT_TITLE, and ilArrayUtil\sortArray().

+ Here is the call graph for this function:

Field Documentation

◆ $db

ilDBInterface ilContainerSorting::$db
protected

Definition at line 32 of file class.ilContainerSorting.php.

◆ $instances

array ilContainerSorting::$instances = []
staticprotected

Definition at line 30 of file class.ilContainerSorting.php.

◆ $log

ilLogger ilContainerSorting::$log
protected

Definition at line 27 of file class.ilContainerSorting.php.

◆ $obj_id

int ilContainerSorting::$obj_id
protected

Definition at line 31 of file class.ilContainerSorting.php.

◆ $sorting

array ilContainerSorting::$sorting = []
protected

Definition at line 34 of file class.ilContainerSorting.php.

◆ $sorting_settings

ilContainerSortingSettings ilContainerSorting::$sorting_settings = null
protected

Definition at line 33 of file class.ilContainerSorting.php.

Referenced by getSortingSettings().

◆ $tree

ilTree ilContainerSorting::$tree
protected

Definition at line 28 of file class.ilContainerSorting.php.

◆ ORDER_DEFAULT

const ilContainerSorting::ORDER_DEFAULT = 999999
protected

Definition at line 25 of file class.ilContainerSorting.php.


The documentation for this class was generated from the following file: