ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilContainerSorting Class Reference
+ Collaboration diagram for ilContainerSorting:

Public Member Functions

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

Static Public Member Functions

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

Data Fields

const ORDER_DEFAULT = 999999

Protected Member Functions

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

Protected Attributes

 $obj_id
 $db
 $sorting_settings = null

Static Protected Attributes

static $instances = array()

Private Member Functions

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

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

ilContainerSorting::__construct (   $a_obj_id)
private

Constructor.

private

Parameters
intobj_id

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

References $ilDB, and read().

{
global $ilDB;
$this->db = $ilDB;
$this->obj_id = $a_obj_id;
$this->read();
}

+ Here is the call graph for this function:

Member Function Documentation

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

clone sorting

Returns

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

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

{
global $ilDB;
global $ilLog;
$ilLog->write(__METHOD__.': Cloning container sorting.');
$target_obj_id = ilObject::_lookupObjId($a_target_id);
include_once('./Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
$mappings = ilCopyWizardOptions::_getInstance($a_copy_id)->getMappings();
$query = "SELECT * FROM container_sorting ".
"WHERE obj_id = ".$ilDB->quote($this->obj_id, 'integer');
$res = $ilDB->query($query);
while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
{
if(!isset($mappings[$row->child_id]) or !$mappings[$row->child_id])
{
#$ilLog->write(__METHOD__.': No mapping found for:'.$row->child_id);
continue;
}
if($row->parent_id and (!isset($mappings[$row->parent_id]) or !$mappings[$row->parent_id]))
{
continue;
}
$query = "DELETE FROM container_sorting ".
"WHERE obj_id = ".$ilDB->quote($target_obj_id,'integer')." ".
"AND child_id = ".$ilDB->quote($mappings[$row->child_id],'integer')." ".
"AND parent_type = ".$ilDB->quote($row->parent_type,'text').' '.
"AND parent_id = ".$ilDB->quote((int) $mappings[$row->parent_id],'integer');
$ilDB->manipulate($query);
// Add new value
$query = "INSERT INTO container_sorting (obj_id,child_id,position,parent_type,parent_id) ".
"VALUES( ".
$ilDB->quote($target_obj_id ,'integer').", ".
$ilDB->quote($mappings[$row->child_id] ,'integer').", ".
$ilDB->quote($row->position,'integer').", ".
$ilDB->quote($row->parent_type,'text').", ".
$ilDB->quote((int) $mappings[$row->parent_id],'integer').
")";
$ilDB->manipulate($query);
}
return true;
}

+ Here is the call graph for this function:

ilContainerSorting::getBlockPositions ( )

Read block custom positions (for current object id)

Returns
array

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

References $ilDB, and $row.

{
global $ilDB;
$set = $ilDB->query("SELECT block_ids".
" FROM container_sorting_bl".
" WHERE obj_id = ".$ilDB->quote($this->obj_id, "integer"));
$row = $ilDB->fetchAssoc($set);
if($row["block_ids"])
{
return explode(";", $row["block_ids"]);
}
}
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:

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.

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

Referenced by ilLinkResourceItems\sortItems().

{
global $ilDB;
$query = "SELECT * FROM container_sorting WHERE ".
"obj_id = ".$ilDB->quote($a_obj_id,'integer');
$res = $ilDB->query($query);
while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
{
$sorted[$row->child_id] = $row->position;
}
return $sorted ? $sorted : array();
}

+ Here is the caller graph for this function:

ilContainerSorting::read ( )
private

Read.

private

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

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

Referenced by __construct().

{
global $tree;
if(!$this->obj_id)
{
$this->sorting_settings = new ilContainerSortingSettings();
return true;
}
$this->sorting_settings = ilContainerSortingSettings::getInstanceByObjId($this->obj_id);
if($this->getSortingSettings()->getSortMode() == ilContainer::SORT_INHERIT)
{
// lookup settings of parent course
$ref_ids = ilObject::_getAllReferences($this->obj_id);
$ref_id = end($ref_ids);
$crs_ref_id = $tree->checkForParentType($ref_id,'crs');
$crs_obj_id = ilObject::_lookupObjId($crs_ref_id);
$crs_settings = ilContainerSortingSettings::getInstanceByObjId($crs_obj_id);
$this->sorting_settings = clone $crs_settings;
}
$query = "SELECT * FROM container_sorting ".
"WHERE obj_id = ".$this->db->quote($this->obj_id ,'integer')." ORDER BY position";
$res = $this->db->query($query);
while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
{
if($row->parent_id)
{
$this->sorting[$row->parent_type][$row->parent_id][$row->child_id] = $row->position;
}
else
{
$this->sorting['all'][$row->child_id] = $row->position;
}
}
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

References $ilDB.

Referenced by savePost().

{
global $ilDB;
asort($a_values);
$ilDB->replace(
'container_sorting_bl',
array(
'obj_id' => array('integer',$this->obj_id)
),
array(
'block_ids' => array('text', implode(";", array_keys($a_values)))
)
);
}

+ Here is the caller graph for this function:

ilContainerSorting::saveItems (   $a_items)
protected

save items

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.

References $ilDB.

Referenced by savePost().

{
global $ilDB;
foreach($a_items as $child_id => $position)
{
$ilDB->replace(
'container_sorting',
array(
'obj_id' => array('integer',$this->obj_id),
'child_id' => array('integer',$child_id),
'parent_id' => array('integer',0)
),
array(
'parent_type' => array('text',''),
'position' => array('integer',$position)
)
);
}
return true;
}

+ Here is the caller graph for this function:

ilContainerSorting::savePost (   $a_type_positions)

Save post.

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.

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

{
global $ilLog;
if(!is_array($a_type_positions))
{
return false;
}
foreach($a_type_positions as $key => $position)
{
if($key == "blocks")
{
$this->saveBlockPositions($position);
}
else if(!is_array($position))
{
$items[$key] = $position * 100;
}
else
{
$ilLog->write(__METHOD__.': Deprecated call');
foreach($position as $parent_id => $sub_items)
{
$this->saveSubItems($key,$parent_id,$sub_items ? $sub_items : array());
}
}
}
$this->saveItems($items ? $items : array());
}

+ Here is the call graph for this function:

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.

References $ilDB.

Referenced by savePost().

{
global $ilDB;
foreach($a_items as $child_id => $position)
{
$ilDB->replace(
'container_sorting',
array(
'obj_id' => array('integer',$this->obj_id),
'child_id' => array('integer',$child_id),
'parent_id' => array('integer',$a_parent_id)
),
array(
'parent_type' => array('text',$a_parent_type),
'position' => array('integer',$position)
)
);
}
return true;
}

+ Here is the caller graph for this function:

ilContainerSorting::sortItems (   $a_items)

sort subitems

public

Parameters
arrayitem data
Returns
array sorted item data

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

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

{
$sorted = array();
if($this->getSortingSettings()->getSortMode() != ilContainer::SORT_MANUAL)
{
switch($this->getSortingSettings()->getSortMode())
{
foreach((array) $a_items as $type => $data)
{
// #16311 - sorting will remove keys (prev/next)
if($type == 'sess_link')
{
$sorted[$type] = $data;
continue;
}
// this line used until #4389 has been fixed (3.10.6)
// reanimated with 4.4.0
$sorted[$type] = ilUtil::sortArray(
(array) $data,
'title',
($this->getSortingSettings()->getSortDirection() == ilContainer::SORT_DIRECTION_ASC) ? 'asc' : 'desc',
FALSE
);
// the next line tried to use db sorting and has replaced sortArray due to bug #4389
// but leads to bug #12165. PHP should be able to do a proper sorting, if the locale
// is set correctly, so we witch back to sortArray (with 4.4.0) and see what
// feedback we get
// (next line has been used from 3.10.6 to 4.3.x)
// $sorted[$type] = $data;
}
return $sorted ? $sorted : array();
foreach((array) $a_items as $type => $data)
{
// #16311 - sorting will remove keys (prev/next)
if($type == 'sess_link')
{
$sorted[$type] = $data;
continue;
}
$sorted[$type] = ilUtil::sortArray(
(array) $data,
'start',
($this->getSortingSettings()->getSortDirection() == ilContainer::SORT_DIRECTION_ASC) ? 'asc' : 'desc',
TRUE
);
}
return $sorted ? $sorted : array();
foreach((array) $a_items as $type => $data)
{
// #16311 - sorting will remove keys (prev/next)
if($type == 'sess_link')
{
$sorted[$type] = $data;
continue;
}
$sorted[$type] = ilUtil::sortArray(
(array) $data,
'create_date',
($this->getSortingSettings()->getSortDirection() == ilContainer::SORT_DIRECTION_ASC) ? 'asc' : 'desc',
TRUE
);
}
return $sorted ? $sorted : array();
}
return $a_items;
}
if(!count($a_items))
{
return $a_items;
}
$sorted = array();
foreach((array) $a_items as $type => $data)
{
if($type == 'sess_link')
{
$sorted[$type] = $data;
continue;
}
// Add position
$items = array();
foreach((array) $data as $key => $item)
{
$items[$key] = $item;
if(is_array($this->sorting['all']) and isset($this->sorting['all'][$item['child']]))
{
$items[$key]['position'] = $this->sorting['all'][$item['child']];
}
else
{
$items[$key]['position'] = self::ORDER_DEFAULT;
}
}
$items = $this->sortOrderDefault($items);
switch($type)
{
case '_all':
$sorted[$type] = ilUtil::sortArray((array) $items,'position','asc',true);
break;
case '_non_sess':
$sorted[$type] = ilUtil::sortArray((array) $items,'position','asc',true);
break;
default:
$sorted[$type] = ilUtil::sortArray((array) $items,'position','asc',true);
break;
}
}
return $sorted ? $sorted : array();
}

+ Here is the call graph for this function:

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.

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().

{
$no_position = array();
foreach($items as $key => $item)
{
if($item["position"] == self::ORDER_DEFAULT)
{
$no_position[]= array("key" => $key, "title" => $item["title"], "create_date" => $item["create_date"],
"start" => $item["start"]);
}
}
if(!count($no_position))
{
return $items;
}
switch($this->getSortingSettings()->getSortNewItemsOrder())
{
$no_position = ilUtil::sortArray( (array) $no_position,
'title',
($this->getSortingSettings()->getSortDirection() == ilContainer::SORT_DIRECTION_ASC) ? 'asc' : 'desc',
TRUE);
break;
$no_position = ilUtil::sortArray((array) $no_position,
'create_date',
($this->getSortingSettings()->getSortDirection() == ilContainer::SORT_DIRECTION_ASC) ? 'asc' : 'desc',
TRUE);
break;
$no_position = ilUtil::sortArray((array) $no_position,
'start',
($this->getSortingSettings()->getSortDirection() == ilContainer::SORT_DIRECTION_ASC) ? 'asc' : 'desc',
TRUE);
}
$count = $this->getSortingSettings()->getSortNewItemsPosition()
foreach($no_position as $values)
{
$items[$values["key"]]["position"] = $count;
$count++;
}
return $items;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

sort subitems (items of sessions or learning objectives)

public

Parameters
@return

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

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

{
switch($this->getSortingSettings()->getSortMode())
{
$items = array();
foreach($a_items as $key => $item)
{
$items[$key] = $item;
$items[$key]['position'] = isset($this->sorting[$a_parent_type][$a_parent_id][$item['child']]) ?
$this->sorting[$a_parent_type][$a_parent_id][$item['child']] : self::ORDER_DEFAULT;
}
$items = $this->sortOrderDefault($items);
return ilUtil::sortArray((array) $items,'position','asc',TRUE);
(array) $a_items,
'start',
($this->getSortingSettings()->getSortDirection() == ilContainer::SORT_DIRECTION_ASC) ? 'asc' : 'desc',
TRUE
);
(array) $a_items,
'create_date',
($this->getSortingSettings()->getSortDirection() == ilContainer::SORT_DIRECTION_ASC) ? 'asc' : 'desc',
TRUE
);
default:
(array) $a_items,
'title',
($this->getSortingSettings()->getSortDirection() == ilContainer::SORT_DIRECTION_ASC) ? 'asc' : 'desc',
FALSE
);
}
}

+ Here is the call graph for this function:

Field Documentation

ilContainerSorting::$db
protected

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

ilContainerSorting::$instances = array()
staticprotected

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

ilContainerSorting::$obj_id
protected

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

ilContainerSorting::$sorting_settings = null
protected

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

Referenced by getSortingSettings().

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: