24 include_once
'./Services/Container/classes/class.ilContainer.php';
25 include_once(
'Services/Container/classes/class.ilContainerSortingSettings.php');
57 $this->obj_id = $a_obj_id;
81 if(isset(self::$instances[$a_obj_id]))
83 return self::$instances[$a_obj_id];
97 $query =
"SELECT * FROM container_sorting WHERE ".
98 "obj_id = ".$ilDB->quote($a_obj_id,
'integer');
102 $sorted[
$row->child_id] =
$row->position;
104 return $sorted ? $sorted : array();
118 $ilLog->write(__METHOD__.
': Cloning container sorting.');
122 include_once(
'./Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
127 $set = $ilDB->queryF(
"SELECT * FROM container_sorting_bl ".
128 " WHERE obj_id = %s ",
132 if ($rec = $ilDB->fetchAssoc($set))
134 if ($rec[
"block_ids"] !=
"")
136 $ilLog->debug(
"Got block sorting for obj_id = ".$this->obj_id.
": ".$rec[
"block_ids"]);
137 $new_ids = implode(
";", array_map(
function ($block_id) use ($mappings) {
138 if (is_numeric($block_id))
140 $block_id = $mappings[$block_id];
143 }, explode(
";", $rec[
"block_ids"])));
145 $ilDB->insert(
"container_sorting_bl", array(
146 "obj_id" => array(
"integer", $target_obj_id),
147 "block_ids" => array(
"text", $new_ids)
150 $ilLog->debug(
"Write block sorting for obj_id = ".$target_obj_id.
": ".$new_ids);
155 $ilLog->debug(
"Read container_sorting for obj_id = ".$this->obj_id);
157 $query =
"SELECT * FROM container_sorting ".
158 "WHERE obj_id = ".$ilDB->quote($this->obj_id,
'integer');
164 if(!isset($mappings[
$row->child_id]) or !$mappings[
$row->child_id])
166 #$ilLog->write(__METHOD__.': No mapping found for:'.$row->child_id); 176 if (in_array(
$row->parent_type, array(
"sess",
"itgr")))
179 $par_ref_id = current($par_refs);
180 $ilLog->debug(
"Got ref id: ".$par_ref_id.
" for obj_id ".
$row->parent_id.
" map ref id: ".$mappings[$par_ref_id].
".");
181 if (isset($mappings[$par_ref_id]))
183 $new_parent_ref_id = $mappings[$par_ref_id];
189 $new_parent_id = $mappings[
$row->parent_id];
191 if ((
int) $new_parent_id == 0)
193 $ilLog->debug(
"No mapping found for parent id:" .
$row->parent_id .
", child_id: " .
$row->child_id);
198 $query =
"DELETE FROM container_sorting ".
199 "WHERE obj_id = ".$ilDB->quote($target_obj_id,
'integer').
" ".
200 "AND child_id = ".$ilDB->quote($mappings[
$row->child_id],
'integer').
" ".
201 "AND parent_type = ".$ilDB->quote(
$row->parent_type,
'text').
' '.
202 "AND parent_id = ".$ilDB->quote((
int) $new_parent_id,
'integer');
204 $ilDB->manipulate(
$query);
207 $query =
"INSERT INTO container_sorting (obj_id,child_id,position,parent_type,parent_id) ".
209 $ilDB->quote($target_obj_id ,
'integer').
", ".
210 $ilDB->quote($mappings[
$row->child_id] ,
'integer').
", ".
211 $ilDB->quote(
$row->position,
'integer').
", ".
212 $ilDB->quote(
$row->parent_type,
'text').
", ".
213 $ilDB->quote((
int) $new_parent_id,
'integer').
215 $ilDB->manipulate(
$query);
237 foreach((array) $a_items as $type =>
$data)
240 if($type ==
'sess_link')
242 $sorted[$type] =
$data;
262 return $sorted ? $sorted : array();
265 foreach((array) $a_items as $type =>
$data)
268 if($type ==
'sess_link')
270 $sorted[$type] =
$data;
282 return $sorted ? $sorted : array();
286 foreach((array) $a_items as $type =>
$data)
289 if($type ==
'sess_link')
291 $sorted[$type] =
$data;
302 return $sorted ? $sorted : array();
311 foreach((array) $a_items as $type =>
$data)
313 if($type ==
'sess_link')
315 $sorted[$type] =
$data;
321 foreach((array)
$data as $key => $item)
323 $items[$key] = $item;
324 if(is_array($this->sorting[
'all']) and isset($this->sorting[
'all'][$item[
'child']]))
326 $items[$key][
'position'] = $this->sorting[
'all'][$item[
'child']];
330 $items[$key][
'position'] = self::ORDER_DEFAULT;
351 return $sorted ? $sorted : array();
367 foreach($a_items as $key => $item)
369 $items[$key] = $item;
370 $items[$key][
'position'] = isset($this->sorting[$a_parent_type][$a_parent_id][$item[
'child']]) ?
371 $this->sorting[$a_parent_type][$a_parent_id][$item[
'child']] : self::ORDER_DEFAULT;
417 if(!is_array($a_type_positions))
421 foreach($a_type_positions as $key => $position)
427 else if(!is_array($position))
429 $items[$key] = $position * 100;
433 $ilLog->write(__METHOD__.
': Deprecated call');
434 foreach($position as $parent_id => $sub_items)
436 $this->
saveSubItems($key,$parent_id,$sub_items ? $sub_items : array());
440 $this->
saveItems($items ? $items : array());
457 foreach($a_items as $child_id => $position)
462 'obj_id' => array(
'integer',$this->obj_id),
463 'child_id' => array(
'integer',$child_id),
464 'parent_id' => array(
'integer',0)
467 'parent_type' => array(
'text',
''),
468 'position' => array(
'integer',$position)
486 foreach($a_items as $child_id => $position)
491 'obj_id' => array(
'integer',$this->obj_id),
492 'child_id' => array(
'integer',$child_id),
493 'parent_id' => array(
'integer',$a_parent_id)
496 'parent_type' => array(
'text',$a_parent_type),
497 'position' => array(
'integer',$position)
517 'container_sorting_bl',
519 'obj_id' => array(
'integer',$this->obj_id)
522 'block_ids' => array(
'text', implode(
";", array_keys($a_values)))
536 $set = $ilDB->query(
"SELECT block_ids".
537 " FROM container_sorting_bl".
538 " WHERE obj_id = ".$ilDB->quote($this->obj_id,
"integer"));
539 $row = $ilDB->fetchAssoc($set);
540 if(
$row[
"block_ids"])
542 return explode(
";",
$row[
"block_ids"]);
565 $query =
"SELECT * FROM container_sorting ".
566 "WHERE obj_id = ".$this->db->quote($this->obj_id ,
'integer').
" ORDER BY position";
572 $this->sorting[
$row->parent_type][
$row->parent_id][
$row->child_id] =
$row->position;
576 $this->sorting[
'all'][
$row->child_id] =
$row->position;
590 $no_position = array();
592 foreach($items as $key => $item)
594 if($item[
"position"] == self::ORDER_DEFAULT)
596 $no_position[]= array(
"key" => $key,
"title" => $item[
"title"],
"create_date" => $item[
"create_date"],
597 "start" => $item[
"start"]);
602 if(!count($no_position))
631 foreach($no_position as $values)
633 $items[$values[
"key"]][
"position"] = $count;
saveItems($a_items)
save items
const SORT_NEW_ITEMS_POSITION_TOP
saveBlockPositions(array $a_values)
Save block custom positions (for current object id)
sortOrderDefault($items)
Position and order sort order for new object without position in manual sorting type.
savePost($a_type_positions)
Save post.
getBlockPositions()
Read block custom positions (for current object id)
sortSubItems($a_parent_type, $a_parent_id, $a_items)
sort subitems (items of sessions or learning objectives)
static sortArray($array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
static _getAllReferences($a_id)
get all reference ids of object
const DB_FETCHMODE_OBJECT
static _lookupObjectId($a_ref_id)
lookup object id
getSortingSettings()
Get sorting settings.
sortItems($a_items)
sort subitems
__construct($a_obj_id)
Constructor.
static _getInstance($a_copy_id)
Get instance of copy wizard options.
saveSubItems($a_parent_type, $a_parent_id, $a_items)
Save subitem ordering (sessions, learning objectives)
const SORT_NEW_ITEMS_ORDER_CREATION
static _lookupObjId($a_id)
const SORT_NEW_ITEMS_ORDER_ACTIVATION
static getInstanceByObjId($a_obj_id)
Get singleton instance.
static _getInstance($a_obj_id)
get instance by obj_id
static lookupPositions($a_obj_id)
Get positions of subitems.
const SORT_NEW_ITEMS_ORDER_TITLE
cloneSorting($a_target_id, $a_copy_id)
clone sorting