ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
ilContainerSorting Class Reference
+ Collaboration diagram for ilContainerSorting:

Public Member Functions

 getSortingSettings ()
 Get sorting settings. More...
 
 sortItems ($a_items)
 sort subitems More...
 
 sortSubItems ($a_parent_type, $a_parent_id, $a_items)
 sort subitems (items of sessions or learning objectives) More...
 
 savePost ($a_type_positions)
 Save post. More...
 
 getBlockPositions ()
 Read block custom positions (for current object id) More...
 

Static Public Member Functions

static _getInstance ($a_obj_id)
 get instance by obj_id More...
 
static lookupPositions ($a_obj_id)
 Get positions of subitems. More...
 
 cloneSorting ($a_target_id, $a_copy_id)
 clone sorting More...
 

Data Fields

const ORDER_DEFAULT = 999999
 

Protected Member Functions

 saveItems ($a_items)
 save items More...
 
 saveSubItems ($a_parent_type, $a_parent_id, $a_items)
 Save subitem ordering (sessions, learning objectives) More...
 
 saveBlockPositions (array $a_values)
 Save block custom positions (for current object id) More...
 

Protected Attributes

 $obj_id
 
 $db
 
 $sorting_settings = null
 

Static Protected Attributes

static $instances = array()
 

Private Member Functions

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

Detailed Description

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

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

Constructor & Destructor Documentation

◆ __construct()

ilContainerSorting::__construct (   $a_obj_id)
private

Constructor.

@access private

Parameters
intobj_id

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

53 {
54 global $ilDB;
55
56 $this->db = $ilDB;
57 $this->obj_id = $a_obj_id;
58
59 $this->read();
60 }
global $ilDB

References $ilDB, and read().

+ Here is the call graph for this function:

Member Function Documentation

◆ _getInstance()

static ilContainerSorting::_getInstance (   $a_obj_id)
static

◆ cloneSorting()

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

clone sorting

Returns

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

114 {
115 global $ilDB;
116 global $ilLog;
117
118 $ilLog->write(__METHOD__.': Cloning container sorting.');
119
120 $target_obj_id = ilObject::_lookupObjId($a_target_id);
121
122 include_once('./Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
123 $mappings = ilCopyWizardOptions::_getInstance($a_copy_id)->getMappings();
124
125 $query = "SELECT * FROM container_sorting ".
126 "WHERE obj_id = ".$ilDB->quote($this->obj_id, 'integer');
127
128 $res = $ilDB->query($query);
129
130 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
131 {
132 if(!isset($mappings[$row->child_id]) or !$mappings[$row->child_id])
133 {
134 #$ilLog->write(__METHOD__.': No mapping found for:'.$row->child_id);
135 continue;
136 }
137
138 if($row->parent_id and (!isset($mappings[$row->parent_id]) or !$mappings[$row->parent_id]))
139 {
140 continue;
141 }
142
143 $query = "DELETE FROM container_sorting ".
144 "WHERE obj_id = ".$ilDB->quote($target_obj_id,'integer')." ".
145 "AND child_id = ".$ilDB->quote($mappings[$row->child_id],'integer')." ".
146 "AND parent_type = ".$ilDB->quote($row->parent_type,'text').' '.
147 "AND parent_id = ".$ilDB->quote((int) $mappings[$row->parent_id],'integer');
148 $ilDB->manipulate($query);
149
150 // Add new value
151 $query = "INSERT INTO container_sorting (obj_id,child_id,position,parent_type,parent_id) ".
152 "VALUES( ".
153 $ilDB->quote($target_obj_id ,'integer').", ".
154 $ilDB->quote($mappings[$row->child_id] ,'integer').", ".
155 $ilDB->quote($row->position,'integer').", ".
156 $ilDB->quote($row->parent_type,'text').", ".
157 $ilDB->quote((int) $mappings[$row->parent_id],'integer').
158 ")";
159 $ilDB->manipulate($query);
160 }
161 return true;
162 }
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
static _getInstance($a_copy_id)
Get instance of copy wizard options.
static _lookupObjId($a_id)

References $ilDB, $ilLog, $query, $res, $row, ilCopyWizardOptions\_getInstance(), ilObject\_lookupObjId(), and DB_FETCHMODE_OBJECT.

+ Here is the call graph for this function:

◆ getBlockPositions()

ilContainerSorting::getBlockPositions ( )

Read block custom positions (for current object id)

Returns
array

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

477 {
478 global $ilDB;
479
480 $set = $ilDB->query("SELECT block_ids".
481 " FROM container_sorting_bl".
482 " WHERE obj_id = ".$ilDB->quote($this->obj_id, "integer"));
483 $row = $ilDB->fetchAssoc($set);
484 if($row["block_ids"])
485 {
486 return explode(";", $row["block_ids"]);
487 }
488 }

References $ilDB, and $row.

◆ getSortingSettings()

ilContainerSorting::getSortingSettings ( )

Get sorting settings.

Returns
ilContainerSortingSettings

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

References $sorting_settings.

Referenced by read(), sortItems(), sortOrderDefault(), and sortSubItems().

+ Here is the caller graph for this function:

◆ lookupPositions()

static ilContainerSorting::lookupPositions (   $a_obj_id)
static

Get positions of subitems.

Parameters
int$a_obj_id
Returns

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

94 {
95 global $ilDB;
96
97 $query = "SELECT * FROM container_sorting WHERE ".
98 "obj_id = ".$ilDB->quote($a_obj_id,'integer');
99 $res = $ilDB->query($query);
100 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
101 {
102 $sorted[$row->child_id] = $row->position;
103 }
104 return $sorted ? $sorted : array();
105 }

References $ilDB, $query, $res, $row, and DB_FETCHMODE_OBJECT.

Referenced by ilLinkResourceItems\sortItems().

+ Here is the caller graph for this function:

◆ read()

ilContainerSorting::read ( )
private

Read.

@access private

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

498 {
499 global $tree;
500
501 if(!$this->obj_id)
502 {
503 $this->sorting_settings = new ilContainerSortingSettings();
504 return true;
505 }
506
507 $this->sorting_settings = ilContainerSortingSettings::getInstanceByObjId($this->obj_id);
508 if($this->getSortingSettings()->getSortMode() == ilContainer::SORT_INHERIT)
509 {
510 // lookup settings of parent course
511 $ref_ids = ilObject::_getAllReferences($this->obj_id);
512 $ref_id = end($ref_ids);
513 $crs_ref_id = $tree->checkForParentType($ref_id,'crs');
514 $crs_obj_id = ilObject::_lookupObjId($crs_ref_id);
515
516 $crs_settings = ilContainerSortingSettings::getInstanceByObjId($crs_obj_id);
517 $this->sorting_settings = clone $crs_settings;
518
519 }
520 $query = "SELECT * FROM container_sorting ".
521 "WHERE obj_id = ".$this->db->quote($this->obj_id ,'integer')." ORDER BY position";
522 $res = $this->db->query($query);
523 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
524 {
525 if($row->parent_id)
526 {
527 $this->sorting[$row->parent_type][$row->parent_id][$row->child_id] = $row->position;
528 }
529 else
530 {
531 $this->sorting['all'][$row->child_id] = $row->position;
532 }
533 }
534 return true;
535 }
static getInstanceByObjId($a_obj_id)
Get singleton instance.
getSortingSettings()
Get sorting settings.
static _getAllReferences($a_id)
get all reference ids of object
$ref_id
Definition: sahs_server.php:39

References $query, $ref_id, $res, $row, ilObject\_getAllReferences(), ilObject\_lookupObjId(), DB_FETCHMODE_OBJECT, ilContainerSortingSettings\getInstanceByObjId(), getSortingSettings(), and ilContainer\SORT_INHERIT.

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)

Parameters
array$a_values

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

455 {
456 global $ilDB;
457
458 asort($a_values);
459
460 $ilDB->replace(
461 'container_sorting_bl',
462 array(
463 'obj_id' => array('integer',$this->obj_id)
464 ),
465 array(
466 'block_ids' => array('text', implode(";", array_keys($a_values)))
467 )
468 );
469 }

References $ilDB.

Referenced by savePost().

+ Here is the caller graph for this function:

◆ saveItems()

ilContainerSorting::saveItems (   $a_items)
protected

save items

@access protected

Parameters
stringparent_type only used for sessions and objectives in the moment. Otherwise empty
intparent id
arrayarray of items
Returns

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

398 {
399 global $ilDB;
400
401 foreach($a_items as $child_id => $position)
402 {
403 $ilDB->replace(
404 'container_sorting',
405 array(
406 'obj_id' => array('integer',$this->obj_id),
407 'child_id' => array('integer',$child_id),
408 'parent_id' => array('integer',0)
409 ),
410 array(
411 'parent_type' => array('text',''),
412 'position' => array('integer',$position)
413 )
414 );
415 }
416 return true;
417 }

References $ilDB.

Referenced by savePost().

+ Here is the caller graph for this function:

◆ savePost()

ilContainerSorting::savePost (   $a_type_positions)

Save post.

@access public

Parameters
arrayof positions e.g array(crs => array(1,2,3),'lres' => array(3,5,6))

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

358 {
359 global $ilLog;
360
361 if(!is_array($a_type_positions))
362 {
363 return false;
364 }
365 foreach($a_type_positions as $key => $position)
366 {
367 if($key == "blocks")
368 {
369 $this->saveBlockPositions($position);
370 }
371 else if(!is_array($position))
372 {
373 $items[$key] = $position * 100;
374 }
375 else
376 {
377 $ilLog->write(__METHOD__.': Deprecated call');
378 foreach($position as $parent_id => $sub_items)
379 {
380 $this->saveSubItems($key,$parent_id,$sub_items ? $sub_items : array());
381 }
382 }
383 }
384 $this->saveItems($items ? $items : array());
385 }
saveBlockPositions(array $a_values)
Save block custom positions (for current object id)
saveItems($a_items)
save items
saveSubItems($a_parent_type, $a_parent_id, $a_items)
Save subitem ordering (sessions, learning objectives)

References $ilLog, saveBlockPositions(), saveItems(), and saveSubItems().

+ Here is the call graph for this function:

◆ saveSubItems()

ilContainerSorting::saveSubItems (   $a_parent_type,
  $a_parent_id,
  $a_items 
)
protected

Save subitem ordering (sessions, learning objectives)

Parameters
string$a_parent_type
integer$a_parent_id
array$a_items
Returns

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

427 {
428 global $ilDB;
429
430 foreach($a_items as $child_id => $position)
431 {
432 $ilDB->replace(
433 'container_sorting',
434 array(
435 'obj_id' => array('integer',$this->obj_id),
436 'child_id' => array('integer',$child_id),
437 'parent_id' => array('integer',$a_parent_id)
438 ),
439 array(
440 'parent_type' => array('text',$a_parent_type),
441 'position' => array('integer',$position)
442 )
443 );
444 }
445 return true;
446
447 }

References $ilDB.

Referenced by savePost().

+ Here is the caller graph for this function:

◆ sortItems()

ilContainerSorting::sortItems (   $a_items)

sort subitems

@access public

Parameters
arrayitem data
Returns
array sorted item data

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

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

References $data, getSortingSettings(), ORDER_DEFAULT, ilContainer\SORT_ACTIVATION, ilContainer\SORT_CREATION, ilContainer\SORT_DIRECTION_ASC, ilContainer\SORT_MANUAL, ilContainer\SORT_TITLE, ilUtil\sortArray(), and sortOrderDefault().

+ Here is the call graph for this function:

◆ sortOrderDefault()

ilContainerSorting::sortOrderDefault (   $items)
private

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

Parameters
$items
Returns
array

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

544 {
545 $no_position = array();
546
547 foreach($items as $key => $item)
548 {
549 if($item["position"] == self::ORDER_DEFAULT)
550 {
551 $no_position[]= array("key" => $key, "title" => $item["title"], "create_date" => $item["create_date"],
552 "start" => $item["start"]);
553 }
554
555 }
556
557 if(!count($no_position))
558 {
559 return $items;
560 }
561
562 switch($this->getSortingSettings()->getSortNewItemsOrder())
563 {
565 $no_position = ilUtil::sortArray( (array) $no_position,
566 'title',
567 ($this->getSortingSettings()->getSortDirection() == ilContainer::SORT_DIRECTION_ASC) ? 'asc' : 'desc',
568 TRUE);
569 break;
571 $no_position = ilUtil::sortArray((array) $no_position,
572 'create_date',
573 ($this->getSortingSettings()->getSortDirection() == ilContainer::SORT_DIRECTION_ASC) ? 'asc' : 'desc',
574 TRUE);
575 break;
577 $no_position = ilUtil::sortArray((array) $no_position,
578 'start',
579 ($this->getSortingSettings()->getSortDirection() == ilContainer::SORT_DIRECTION_ASC) ? 'asc' : 'desc',
580 TRUE);
581
582 }
583 $count = $this->getSortingSettings()->getSortNewItemsPosition()
585
586 foreach($no_position as $values)
587 {
588 $items[$values["key"]]["position"] = $count;
589 $count++;
590 }
591 return $items;
592 }
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 getSortingSettings(), 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 ilUtil\sortArray().

Referenced by sortItems(), and sortSubItems().

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

◆ sortSubItems()

ilContainerSorting::sortSubItems (   $a_parent_type,
  $a_parent_id,
  $a_items 
)

sort subitems (items of sessions or learning objectives)

@access public

Parameters

return

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

306 {
307 switch($this->getSortingSettings()->getSortMode())
308 {
310 $items = array();
311 foreach($a_items as $key => $item)
312 {
313 $items[$key] = $item;
314 $items[$key]['position'] = isset($this->sorting[$a_parent_type][$a_parent_id][$item['child']]) ?
315 $this->sorting[$a_parent_type][$a_parent_id][$item['child']] : self::ORDER_DEFAULT;
316 }
317
318 $items = $this->sortOrderDefault($items);
319 return ilUtil::sortArray((array) $items,'position','asc',TRUE);
320
321
323 return ilUtil::sortArray(
324 (array) $a_items,
325 'start',
326 ($this->getSortingSettings()->getSortDirection() == ilContainer::SORT_DIRECTION_ASC) ? 'asc' : 'desc',
327 TRUE
328 );
329
331 return ilUtil::sortArray(
332 (array) $a_items,
333 'create_date',
334 ($this->getSortingSettings()->getSortDirection() == ilContainer::SORT_DIRECTION_ASC) ? 'asc' : 'desc',
335 TRUE
336 );
337
338 default:
340 return ilUtil::sortArray(
341 (array) $a_items,
342 'title',
343 ($this->getSortingSettings()->getSortDirection() == ilContainer::SORT_DIRECTION_ASC) ? 'asc' : 'desc',
344 FALSE
345 );
346 }
347
348 }

References getSortingSettings(), ORDER_DEFAULT, ilContainer\SORT_ACTIVATION, ilContainer\SORT_CREATION, ilContainer\SORT_DIRECTION_ASC, ilContainer\SORT_MANUAL, ilContainer\SORT_TITLE, ilUtil\sortArray(), and sortOrderDefault().

+ Here is the call graph for this function:

Field Documentation

◆ $db

ilContainerSorting::$db
protected

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

◆ $instances

ilContainerSorting::$instances = array()
staticprotected

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

◆ $obj_id

ilContainerSorting::$obj_id
protected

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

◆ $sorting_settings

ilContainerSorting::$sorting_settings = null
protected

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

Referenced by getSortingSettings().

◆ ORDER_DEFAULT

const ilContainerSorting::ORDER_DEFAULT = 999999

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

Referenced by sortItems(), and sortSubItems().


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