24 include_once
'./Services/Container/classes/class.ilContainer.php';
25 include_once(
'Services/Container/classes/class.ilContainerSortingSettings.php');
66 $this->log = $DIC[
"ilLog"];
67 $this->tree = $DIC->repositoryTree();
68 $ilDB = $DIC->database();
71 $this->obj_id = $a_obj_id;
95 if (isset(self::$instances[$a_obj_id])) {
96 return self::$instances[$a_obj_id];
110 $ilDB = $DIC->database();
112 $query =
"SELECT * FROM container_sorting WHERE " .
113 "obj_id = " .
$ilDB->quote($a_obj_id,
'integer');
116 $sorted[
$row->child_id] =
$row->position;
118 return $sorted ? $sorted :
array();
132 $ilLog->debug(
"Cloning container sorting.");
136 include_once(
'./Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
141 $set =
$ilDB->queryF(
142 "SELECT * FROM container_sorting_bl " .
143 " WHERE obj_id = %s ",
147 if ($rec =
$ilDB->fetchAssoc($set)) {
148 if ($rec[
"block_ids"] !=
"") {
149 $ilLog->debug(
"Got block sorting for obj_id = " . $this->obj_id .
": " . $rec[
"block_ids"]);
150 $new_ids = implode(
";", array_map(
function ($block_id) use ($mappings) {
151 if (is_numeric($block_id)) {
152 $block_id = $mappings[$block_id];
155 }, explode(
";", $rec[
"block_ids"])));
158 "obj_id" =>
array(
"integer", $target_obj_id),
159 "block_ids" =>
array(
"text", $new_ids)
162 $ilLog->debug(
"Write block sorting for obj_id = " . $target_obj_id .
": " . $new_ids);
167 $ilLog->debug(
"Read container_sorting for obj_id = " . $this->obj_id);
169 $query =
"SELECT * FROM container_sorting " .
170 "WHERE obj_id = " .
$ilDB->quote($this->obj_id,
'integer');
175 if (!isset($mappings[
$row->child_id]) or !$mappings[
$row->child_id]) {
176 $ilLog->debug(
"No mapping found for child id:" .
$row->child_id);
182 if (
$row->parent_id) {
185 if (in_array(
$row->parent_type,
array(
"sess",
"itgr"))) {
187 $par_ref_id = current($par_refs);
188 $ilLog->debug(
"Got ref id: " . $par_ref_id .
" for obj_id " .
$row->parent_id .
" map ref id: " . $mappings[$par_ref_id] .
".");
189 if (isset($mappings[$par_ref_id])) {
190 $new_parent_ref_id = $mappings[$par_ref_id];
194 $new_parent_id = $mappings[
$row->parent_id];
196 if ((
int) $new_parent_id == 0) {
197 $ilLog->debug(
"No mapping found for parent id:" .
$row->parent_id .
", child_id: " .
$row->child_id);
202 $query =
"DELETE FROM container_sorting " .
203 "WHERE obj_id = " .
$ilDB->quote($target_obj_id,
'integer') .
" " .
204 "AND child_id = " .
$ilDB->quote($mappings[
$row->child_id],
'integer') .
" " .
205 "AND parent_type = " .
$ilDB->quote(
$row->parent_type,
'text') .
' ' .
206 "AND parent_id = " .
$ilDB->quote((
int) $new_parent_id,
'integer');
211 $query =
"INSERT INTO container_sorting (obj_id,child_id,position,parent_type,parent_id) " .
213 $ilDB->quote($target_obj_id,
'integer') .
", " .
214 $ilDB->quote($mappings[
$row->child_id],
'integer') .
", " .
215 $ilDB->quote(
$row->position,
'integer') .
", " .
216 $ilDB->quote(
$row->parent_type,
'text') .
", " .
217 $ilDB->quote((
int) $new_parent_id,
'integer') .
242 if (
$type ==
'sess_link') {
263 return $sorted ? $sorted :
array();
268 if (
$type ==
'sess_link') {
280 return $sorted ? $sorted :
array();
286 if (
$type ==
'sess_link') {
298 return $sorted ? $sorted :
array();
302 if (!is_array($a_items) || !count($a_items)) {
307 if (
$type ==
'sess_link') {
315 $items[
$key] = $item;
316 if (is_array($this->sorting[
'all']) and isset($this->sorting[
'all'][$item[
'child']])) {
317 $items[
$key][
'position'] = $this->sorting[
'all'][$item[
'child']];
319 $items[
$key][
'position'] = self::ORDER_DEFAULT;
339 return $sorted ? $sorted :
array();
354 foreach ($a_items as
$key => $item) {
355 $items[
$key] = $item;
356 $items[
$key][
'position'] = isset($this->sorting[$a_parent_type][$a_parent_id][$item[
'child']]) ?
357 $this->sorting[$a_parent_type][$a_parent_id][$item[
'child']] : self::ORDER_DEFAULT;
400 if (!is_array($a_type_positions)) {
404 foreach ($a_type_positions as
$key => $position) {
405 if (
$key ==
"blocks") {
407 } elseif (!is_array($position)) {
408 $items[
$key] = $position * 100;
410 foreach ($position as $parent_id => $sub_items) {
416 if (!count($items)) {
423 foreach ($items as
$key => $null) {
424 $new_indexed[
$key] = ++$position;
444 foreach ($a_items as $child_id => $position) {
448 'obj_id' =>
array(
'integer',$this->obj_id),
449 'child_id' =>
array(
'integer',$child_id),
450 'parent_id' =>
array(
'integer',0)
453 'parent_type' =>
array(
'text',
''),
454 'position' =>
array(
'integer',$position)
468 protected function saveSubItems($a_parent_type, $a_parent_id, $a_items)
472 foreach ($a_items as $child_id => $position) {
476 'obj_id' =>
array(
'integer',$this->obj_id),
477 'child_id' =>
array(
'integer',$child_id),
478 'parent_id' =>
array(
'integer',$a_parent_id)
481 'parent_type' =>
array(
'text',$a_parent_type),
482 'position' =>
array(
'integer',$position)
500 'container_sorting_bl',
502 'obj_id' =>
array(
'integer',$this->obj_id)
505 'block_ids' =>
array(
'text', implode(
";", array_keys($a_values)))
519 $set =
$ilDB->query(
"SELECT block_ids" .
520 " FROM container_sorting_bl" .
521 " WHERE obj_id = " .
$ilDB->quote($this->obj_id,
"integer"));
523 if (
$row[
"block_ids"]) {
524 return explode(
";",
$row[
"block_ids"]);
539 if (!$this->obj_id) {
546 $query =
"SELECT * FROM container_sorting " .
547 "WHERE obj_id = " . $this->db->quote($this->obj_id,
'integer') .
" ORDER BY position";
550 if (
$row->parent_id) {
551 $this->sorting[
$row->parent_type][
$row->parent_id][
$row->child_id] =
$row->position;
553 $this->sorting[
'all'][
$row->child_id] =
$row->position;
567 $no_position =
array();
569 foreach ($items as
$key => $item) {
570 if ($item[
"position"] == self::ORDER_DEFAULT) {
571 $no_position[]=
array(
"key" =>
$key,
"title" => $item[
"title"],
"create_date" => $item[
"create_date"],
572 "start" => $item[
"start"]);
576 if (!count($no_position)) {
583 (
array) $no_position,
591 (
array) $no_position,
599 (
array) $no_position,
609 foreach ($no_position as $values) {
610 $items[$values[
"key"]][
"position"] = $count;
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
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 _getAllReferences($a_id)
get all reference ids of 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.
foreach($_POST as $key=> $value) $res
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)
Create styles array
The data for the language used.
const SORT_NEW_ITEMS_ORDER_ACTIVATION
static getLogger($a_component_id)
Get component logger.
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