ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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: shib_login.php:26

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

+ Here is the call graph for this function:

Member Function Documentation

◆ _getInstance()

◆ 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

◆ getBlockPositions()

ilContainerSorting::getBlockPositions ( )

Read block custom positions (for current object id)

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

434 : array
435 {
437
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"]);
444 }
445
446 return [];
447 }

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, $res, ilDBConstants\FETCHMODE_OBJECT, and ILIAS\Repository\int().

Referenced by ilWebLinkItemsContainer\lookupManualPositions().

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

◆ read()

ilContainerSorting::read ( )
private

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

449 : void
450 {
451 if (!$this->obj_id) {
452 $this->sorting_settings = new ilContainerSortingSettings();
453 }
454
456 $this->sorting_settings = $sorting_settings->loadEffectiveSettings();
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);
460 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
461 if ($row->parent_id) {
462 $this->sorting[$row->parent_type][$row->parent_id][$row->child_id] = $row->position;
463 } else {
464 $this->sorting['all'][$row->child_id] = $row->position;
465 }
466 }
467 }
loadEffectiveSettings()
Load inherited settings.

References $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 416 of file class.ilContainerSorting.php.

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

References $ilDB.

◆ saveItems()

ilContainerSorting::saveItems ( array  $a_items)
protected

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

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

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 337 of file class.ilContainerSorting.php.

337 : void
338 {
339 if (!is_array($a_type_positions)) {
340 return;
341 }
342 $items = [];
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;
348 } else {
349 foreach ($position as $parent_id => $sub_items) {
350 $this->saveSubItems($key, $parent_id, $sub_items ?: []);
351 }
352 }
353 }
354
355 if (!count($items)) {
356 $this->saveItems([]);
357 return;
358 }
359
360 asort($items);
361 $new_indexed = [];
362 $position = 0;
363 foreach ($items as $key => $null) {
364 $new_indexed[$key] = ++$position;
365 }
366
367 $this->saveItems($new_indexed);
368 }
saveSubItems(string $a_parent_type, int $a_parent_id, array $a_items)
saveBlockPositions(array $a_values)
Save block custom positions (for current object id)

◆ saveSubItems()

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

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

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

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 case '_non_sess':
278 case '_all':
279 default:
280 $sorted[$type] = ilArrayUtil::sortArray($items, 'position', 'asc', true);
281 break;
282 }
283 }
284 return $sorted ?: [];
285 }
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

References $data, 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 472 of file class.ilContainerSorting.php.

472 : array
473 {
474 $no_position = [];
475
476 foreach ($items as $key => $item) {
477 if ($item["position"] == self::ORDER_DEFAULT) {
478 $no_position[] = [
479 "key" => $key,
480 "title" => $item["title"] ?? "",
481 "create_date" => $item["create_date"] ?? "",
482 "start" => $item["start"] ?? ""
483 ];
484 }
485 }
486
487 if (!count($no_position)) {
488 return $items;
489 }
490
491 switch ($this->getSortingSettings()->getSortNewItemsOrder()) {
493 $no_position = ilArrayUtil::sortArray(
494 $no_position,
495 'title',
496 ($this->getSortingSettings()->getSortDirection() === ilContainer::SORT_DIRECTION_ASC) ? 'asc' : 'desc',
497 true
498 );
499 break;
501 $no_position = ilArrayUtil::sortArray(
502 $no_position,
503 'create_date',
504 ($this->getSortingSettings()->getSortDirection() === ilContainer::SORT_DIRECTION_ASC) ? 'asc' : 'desc',
505 true
506 );
507 break;
509 $no_position = ilArrayUtil::sortArray(
510 $no_position,
511 'start',
512 ($this->getSortingSettings()->getSortDirection() === ilContainer::SORT_DIRECTION_ASC) ? 'asc' : 'desc',
513 true
514 );
515 }
516 $count = (
517 $this->getSortingSettings()->getSortNewItemsPosition() === ilContainer::SORT_NEW_ITEMS_POSITION_TOP
518 ? -900000 :
519 900000
520 );
521
522 foreach ($no_position as $values) {
523 $items[$values["key"]]["position"] = $count;
524 $count++;
525 }
526 return $items;
527 }
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 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 290 of file class.ilContainerSorting.php.

294 : array {
295 switch ($this->getSortingSettings()->getSortMode()) {
297 $items = [];
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;
301 }
302
303 $items = $this->sortOrderDefault($items);
304 return ilArrayUtil::sortArray($items, 'position', 'asc', true);
305
306
309 $a_items,
310 'start',
311 ($this->getSortingSettings()->getSortDirection() === ilContainer::SORT_DIRECTION_ASC) ? 'asc' : 'desc',
312 true
313 );
314
317 $a_items,
318 'create_date',
319 ($this->getSortingSettings()->getSortDirection() === ilContainer::SORT_DIRECTION_ASC) ? 'asc' : 'desc',
320 true
321 );
322
323 default:
326 $a_items,
327 'title',
328 ($this->getSortingSettings()->getSortDirection() === ilContainer::SORT_DIRECTION_ASC) ? 'asc' : 'desc',
329 false
330 );
331 }
332 }

References 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: