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 "container_sorting_bl",
159 array(
"obj_id" => array(
"integer", $target_obj_id)),
160 array(
"block_ids" => array(
"text", $new_ids))
163 $ilLog->debug(
"Write block sorting for obj_id = " . $target_obj_id .
": " . $new_ids);
168 $ilLog->debug(
"Read container_sorting for obj_id = " . $this->obj_id);
170 $query =
"SELECT * FROM container_sorting " .
171 "WHERE obj_id = " .
$ilDB->quote($this->obj_id,
'integer');
176 if (!isset($mappings[$row->child_id]) or !$mappings[$row->child_id]) {
177 $ilLog->debug(
"No mapping found for child id:" . $row->child_id);
183 if ($row->parent_id) {
186 if (in_array($row->parent_type, array(
"sess",
"itgr"))) {
188 $par_ref_id = current($par_refs);
189 $ilLog->debug(
"Got ref id: " . $par_ref_id .
" for obj_id " . $row->parent_id .
" map ref id: " . $mappings[$par_ref_id] .
".");
190 if (isset($mappings[$par_ref_id])) {
191 $new_parent_ref_id = $mappings[$par_ref_id];
195 $new_parent_id = $mappings[$row->parent_id];
197 if ((
int) $new_parent_id == 0) {
198 $ilLog->debug(
"No mapping found for parent id:" . $row->parent_id .
", child_id: " . $row->child_id);
203 $query =
"DELETE FROM container_sorting " .
204 "WHERE obj_id = " .
$ilDB->quote($target_obj_id,
'integer') .
" " .
205 "AND child_id = " .
$ilDB->quote($mappings[$row->child_id],
'integer') .
" " .
206 "AND parent_type = " .
$ilDB->quote($row->parent_type,
'text') .
' ' .
207 "AND parent_id = " .
$ilDB->quote((
int) $new_parent_id,
'integer');
212 $query =
"INSERT INTO container_sorting (obj_id,child_id,position,parent_type,parent_id) " .
214 $ilDB->quote($target_obj_id,
'integer') .
", " .
215 $ilDB->quote($mappings[$row->child_id],
'integer') .
", " .
216 $ilDB->quote($row->position,
'integer') .
", " .
217 $ilDB->quote($row->parent_type,
'text') .
", " .
218 $ilDB->quote((
int) $new_parent_id,
'integer') .
237 if (!is_array($a_items)) {
245 foreach ((array) $a_items as
$type =>
$data) {
247 if (
$type ==
'sess_link') {
268 return $sorted ? $sorted : array();
271 foreach ((array) $a_items as
$type =>
$data) {
273 if (
$type ==
'sess_link') {
285 return $sorted ? $sorted : array();
289 foreach ((array) $a_items as
$type =>
$data) {
291 if (
$type ==
'sess_link') {
303 return $sorted ? $sorted : array();
307 if (!is_array($a_items) || !count($a_items)) {
311 foreach ((array) $a_items as
$type =>
$data) {
312 if (
$type ==
'sess_link') {
319 foreach ((array)
$data as $key => $item) {
320 $items[$key] = $item;
321 if (is_array($this->sorting[
'all']) and isset($this->sorting[
'all'][$item[
'child']])) {
322 $items[$key][
'position'] = $this->sorting[
'all'][$item[
'child']];
324 $items[$key][
'position'] = self::ORDER_DEFAULT;
344 return $sorted ? $sorted : array();
359 foreach ($a_items as $key => $item) {
360 $items[$key] = $item;
361 $items[$key][
'position'] = isset($this->sorting[$a_parent_type][$a_parent_id][$item[
'child']]) ?
362 $this->sorting[$a_parent_type][$a_parent_id][$item[
'child']] : self::ORDER_DEFAULT;
405 if (!is_array($a_type_positions)) {
409 foreach ($a_type_positions as $key => $position) {
410 if ($key ==
"blocks") {
412 } elseif (!is_array($position)) {
413 $items[$key] = ((float) $position) * 100;
415 foreach ($position as $parent_id => $sub_items) {
416 $this->
saveSubItems($key, $parent_id, $sub_items ? $sub_items : array());
421 if (!count($items)) {
428 foreach ($items as $key => $null) {
429 $new_indexed[$key] = ++$position;
449 foreach ($a_items as $child_id => $position) {
453 'obj_id' => array(
'integer',$this->obj_id),
454 'child_id' => array(
'integer',$child_id),
455 'parent_id' => array(
'integer',0)
458 'parent_type' => array(
'text',
''),
459 'position' => array(
'integer',$position)
473 protected function saveSubItems($a_parent_type, $a_parent_id, $a_items)
477 foreach ($a_items as $child_id => $position) {
481 'obj_id' => array(
'integer',$this->obj_id),
482 'child_id' => array(
'integer',$child_id),
483 'parent_id' => array(
'integer',$a_parent_id)
486 'parent_type' => array(
'text',$a_parent_type),
487 'position' => array(
'integer',$position)
504 'container_sorting_bl',
506 'obj_id' => array(
'integer',$this->obj_id)
509 'block_ids' => array(
'text', implode(
";", array_keys($a_values)))
523 $set =
$ilDB->query(
"SELECT block_ids" .
524 " FROM container_sorting_bl" .
525 " WHERE obj_id = " .
$ilDB->quote($this->obj_id,
"integer"));
526 $row =
$ilDB->fetchAssoc($set);
527 if ($row[
"block_ids"]) {
528 return explode(
";", $row[
"block_ids"]);
543 if (!$this->obj_id) {
550 $query =
"SELECT * FROM container_sorting " .
551 "WHERE obj_id = " . $this->db->quote($this->obj_id,
'integer') .
" ORDER BY position";
554 if ($row->parent_id) {
555 $this->sorting[$row->parent_type][$row->parent_id][$row->child_id] = $row->position;
557 $this->sorting[
'all'][$row->child_id] = $row->position;
571 $no_position = array();
573 foreach ($items as $key => $item) {
574 if ($item[
"position"] == self::ORDER_DEFAULT) {
575 $no_position[] = array(
"key" => $key,
"title" => $item[
"title"],
"create_date" => $item[
"create_date"],
576 "start" => $item[
"start"]);
580 if (!count($no_position)) {
587 (array) $no_position,
595 (array) $no_position,
603 (array) $no_position,
613 foreach ($no_position as $values) {
614 $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)
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