ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilContainerSorting Class Reference
+ Collaboration diagram for ilContainerSorting:

Public Member Functions

 getSortMode ()
 get sort mode
 sortItems ($a_items)
 sort subitems
 sortSubItems ($a_parent_type, $a_parent_id, $a_items)
 sort subitems (items of sessions or learning objectives)
 isManualSortingEnabled ()
 is manual sorting enabled
 savePost ($a_type_positions)
 Save post.

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)

Protected Attributes

 $obj_id
 $db
 $manual_sort_enabled = false
 $sorting_mode = 0

Static Protected Attributes

static $instances = array()

Private Member Functions

 __construct ($a_obj_id)
 Constructor.
 read ()
 Read.

Detailed Description

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

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

Constructor & Destructor Documentation

ilContainerSorting::__construct (   $a_obj_id)
private

Constructor.

private

Parameters
intobj_id

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

References 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

get instance by obj_id

public

Parameters
intobj_id
Returns
object ilContainerSorting

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

Referenced by ilContainer\cloneDependencies(), cloneSorting(), ilContainer\getSubItems(), ilObjSessionGUI\infoScreen(), ilContainerContentGUI\renderItem(), ilContainerContentGUI\renderItemGroup(), ilContainerObjectiveGUI\renderObjective(), ilObjLinkResourceGUI\saveSorting(), ilContainerGUI\saveSortingObject(), ilShopRepositoryExplorer\sortNodes(), and ilRepositoryExplorer\sortNodes().

{
if(isset(self::$instances[$a_obj_id]))
{
return self::$instances[$a_obj_id];
}
return self::$instances[$a_obj_id] = new ilContainerSorting($a_obj_id);
}

+ Here is the caller graph for this function:

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

clone sorting

Returns

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

References $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::getSortMode ( )

get sort mode

public

Parameters
@return

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

References $sorting_mode.

Referenced by sortItems(), and sortSubItems().

{
}

+ Here is the caller graph for this function:

ilContainerSorting::isManualSortingEnabled ( )

is manual sorting enabled

public

Returns
bool

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

References $manual_sort_enabled.

{
}
static ilContainerSorting::lookupPositions (   $a_obj_id)
static

Get positions of subitems.

Parameters
int$a_obj_id
Returns

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

References $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 385 of file class.ilContainerSorting.php.

References $query, $res, $row, ilContainerSortingSettings\_isManualSortingEnabled(), ilContainerSortingSettings\_lookupSortMode(), and DB_FETCHMODE_OBJECT.

Referenced by __construct().

{
if(!$this->obj_id)
{
return true;
}
include_once('Services/Container/classes/class.ilContainerSortingSettings.php');
$this->manual_sort_enabled = ilContainerSortingSettings::_isManualSortingEnabled($this->obj_id);
$this->sorting_mode = ilContainerSortingSettings::_lookupSortMode($this->obj_id);
$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::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 326 of file class.ilContainerSorting.php.

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 290 of file class.ilContainerSorting.php.

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

{
global $ilLog;
if(!is_array($a_type_positions))
{
return false;
}
foreach($a_type_positions as $key => $position)
{
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 355 of file class.ilContainerSorting.php.

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 176 of file class.ilContainerSorting.php.

References $data, getSortMode(), ORDER_DEFAULT, ilContainer\SORT_ACTIVATION, ilContainer\SORT_TITLE, and ilUtil\sortArray().

{
$sorted = array();
if(!$this->manual_sort_enabled)
{
switch($this->getSortMode())
{
foreach((array) $a_items as $type => $data)
{
// $sorted[$type] = ilUtil::sortArray((array) $data,'title','asc',false);
$sorted[$type] = $data;
}
return $sorted ? $sorted : array();
foreach((array) $a_items as $type => $data)
{
$sorted[$type] = ilUtil::sortArray((array) $data,'start','asc',true);
}
return $sorted ? $sorted : array();
}
return $a_items;
}
if(!count($a_items))
{
return $a_items;
}
foreach((array) $a_items as $type => $data)
{
// 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;
}
}
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::sortSubItems (   $a_parent_type,
  $a_parent_id,
  $a_items 
)

sort subitems (items of sessions or learning objectives)

public

Parameters
@return

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

References getSortMode(), ORDER_DEFAULT, ilContainer\SORT_MANUAL, ilContainer\SORT_TITLE, and ilUtil\sortArray().

{
switch($this->getSortMode())
{
// Add position
$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;
}
return ilUtil::sortArray((array) $items,'position','asc',true);
default:
return ilUtil::sortArray((array) $a_items,'title','asc',true);
}
}

+ Here is the call graph for this function:

Field Documentation

ilContainerSorting::$db
protected

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

ilContainerSorting::$instances = array()
staticprotected

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

ilContainerSorting::$manual_sort_enabled = false
protected

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

Referenced by isManualSortingEnabled().

ilContainerSorting::$obj_id
protected

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

ilContainerSorting::$sorting_mode = 0
protected

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

Referenced by getSortMode().

const ilContainerSorting::ORDER_DEFAULT = 999999

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

Referenced by sortItems(), and sortSubItems().


The documentation for this class was generated from the following file: