24include_once 
'./Services/Container/classes/class.ilContainer.php';
 
   25include_once(
'Services/Container/classes/class.ilContainerSortingSettings.php');
 
   66        $this->log = 
$DIC[
"ilLog"];
 
   67        $this->tree = 
$DIC->repositoryTree();
 
   71        $this->obj_id = $a_obj_id;
 
   95        if (isset(self::$instances[$a_obj_id])) {
 
   96            return self::$instances[$a_obj_id];
 
  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"])));
 
  157                $ilDB->replace(
"container_sorting_bl",
 
  158                    array(
"obj_id" => array(
"integer", $target_obj_id)),
 
  159                    array(
"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') .
 
  236        if (!is_array($a_items)) {
 
  244                    foreach ((array) $a_items as 
$type => 
$data) {
 
  246                        if (
$type == 
'sess_link') {
 
  267                    return $sorted ? $sorted : array();
 
  270                    foreach ((array) $a_items as 
$type => 
$data) {
 
  272                        if (
$type == 
'sess_link') {
 
  284                    return $sorted ? $sorted : array();
 
  288                    foreach ((array) $a_items as 
$type => 
$data) {
 
  290                        if (
$type == 
'sess_link') {
 
  302                    return $sorted ? $sorted : array();
 
  306        if (!is_array($a_items) || !count($a_items)) {
 
  310        foreach ((array) $a_items as 
$type => 
$data) {
 
  311            if (
$type == 
'sess_link') {
 
  318            foreach ((array) 
$data as $key => $item) {
 
  319                $items[$key] = $item;
 
  320                if (is_array($this->sorting[
'all']) and isset($this->sorting[
'all'][$item[
'child']])) {
 
  321                    $items[$key][
'position'] = $this->sorting[
'all'][$item[
'child']];
 
  343        return $sorted ? $sorted : array();
 
  358                foreach ($a_items as $key => $item) {
 
  359                    $items[$key] = $item;
 
  360                    $items[$key][
'position'] = isset($this->sorting[$a_parent_type][$a_parent_id][$item[
'child']]) ?
 
  404        if (!is_array($a_type_positions)) {
 
  408        foreach ($a_type_positions as $key => $position) {
 
  409            if ($key == 
"blocks") {
 
  411            } elseif (!is_array($position)) {
 
  412                $items[$key] = ((float) $position) * 100;
 
  414                foreach ($position as $parent_id => $sub_items) {
 
  415                    $this->
saveSubItems($key, $parent_id, $sub_items ? $sub_items : array());
 
  420        if (!count($items)) {
 
  427        foreach ($items as $key => $null) {
 
  428            $new_indexed[$key] = ++$position;
 
  448        foreach ($a_items as $child_id => $position) {
 
  452                    'obj_id' => array(
'integer',$this->obj_id),
 
  453                    'child_id' => array(
'integer',$child_id),
 
  454                    'parent_id' => array(
'integer',0)
 
  457                    'parent_type' => array(
'text',
''),
 
  458                    'position' => array(
'integer',$position)
 
  472    protected function saveSubItems($a_parent_type, $a_parent_id, $a_items)
 
  476        foreach ($a_items as $child_id => $position) {
 
  480                    'obj_id' => array(
'integer',$this->obj_id),
 
  481                    'child_id' => array(
'integer',$child_id),
 
  482                    'parent_id' => array(
'integer',$a_parent_id)
 
  485                    'parent_type' => array(
'text',$a_parent_type),
 
  486                    'position' => array(
'integer',$position)
 
  503            'container_sorting_bl',
 
  505                'obj_id' => array(
'integer',$this->obj_id)
 
  508                'block_ids' => array(
'text', implode(
";", array_keys($a_values)))
 
  522        $set = 
$ilDB->query(
"SELECT block_ids" .
 
  523            " FROM container_sorting_bl" .
 
  524            " WHERE obj_id = " . 
$ilDB->quote($this->obj_id, 
"integer"));
 
  525        $row = 
$ilDB->fetchAssoc($set);
 
  526        if ($row[
"block_ids"]) {
 
  527            return explode(
";", $row[
"block_ids"]);
 
  542        if (!$this->obj_id) {
 
  549        $query = 
"SELECT * FROM container_sorting " .
 
  550            "WHERE obj_id = " . $this->db->quote($this->obj_id, 
'integer') . 
" ORDER BY position";
 
  553            if ($row->parent_id) {
 
  554                $this->sorting[$row->parent_type][$row->parent_id][$row->child_id] = $row->position;
 
  556                $this->sorting[
'all'][$row->child_id] = $row->position;
 
  570        $no_position = array();
 
  572        foreach ($items as $key => $item) {
 
  573            if ($item[
"position"] == self::ORDER_DEFAULT) {
 
  574                $no_position[] = array(
"key" => $key, 
"title" => $item[
"title"], 
"create_date" => $item[
"create_date"],
 
  575                    "start" => $item[
"start"]);
 
  579        if (!count($no_position)) {
 
  586                    (array) $no_position,
 
  594                    (array) $no_position,
 
  602                    (array) $no_position,
 
  612        foreach ($no_position as $values) {
 
  613            $items[$values[
"key"]][
"position"] = $count;
 
An exception for terminatinating execution or to throw for unit testing.
static getInstanceByObjId($a_obj_id)
Get singleton instance.
cloneSorting($a_target_id, $a_copy_id)
clone sorting
sortItems($a_items)
sort subitems
getBlockPositions()
Read block custom positions (for current object id)
__construct($a_obj_id)
Constructor.
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.
saveItems($a_items)
save items
saveSubItems($a_parent_type, $a_parent_id, $a_items)
Save subitem ordering (sessions, learning objectives)
static lookupPositions($a_obj_id)
Get positions of subitems.
static _getInstance($a_obj_id)
get instance by obj_id
savePost($a_type_positions)
Save post.
sortSubItems($a_parent_type, $a_parent_id, $a_items)
sort subitems (items of sessions or learning objectives)
getSortingSettings()
Get sorting settings.
const SORT_NEW_ITEMS_ORDER_ACTIVATION
const SORT_NEW_ITEMS_ORDER_TITLE
const SORT_NEW_ITEMS_ORDER_CREATION
const SORT_NEW_ITEMS_POSITION_TOP
static _getInstance($a_copy_id)
Get instance of copy wizard options.
static getLogger($a_component_id)
Get component logger.
static _lookupObjId($a_id)
static _lookupObjectId($a_ref_id)
lookup object id
static _getAllReferences($a_id)
get all reference ids of object
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
foreach($_POST as $key=> $value) $res