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

Public Member Functions

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

Static Public Member Functions

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

Data Fields

const ORDER_DEFAULT = 999999
 

Protected Member Functions

 saveItems ($a_items)
 save items More...
 
 saveSubItems ($a_parent_type, $a_parent_id, $a_items)
 Save subitem ordering (sessions, learning objectives) More...
 

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. More...
 
 read ()
 Read. More...
 

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

◆ __construct()

ilContainerSorting::__construct (   $a_obj_id)
private

Constructor.

private

Parameters
intobj_id

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

References read().

52  {
53  global $ilDB;
54 
55  $this->db = $ilDB;
56  $this->obj_id = $a_obj_id;
57 
58  $this->read();
59  }
+ Here is the call graph for this function:

Member Function Documentation

◆ _getInstance()

static ilContainerSorting::_getInstance (   $a_obj_id)
static

◆ cloneSorting()

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, ilCopyWizardOptions\_getInstance(), ilObject\_lookupObjId(), and DB_FETCHMODE_OBJECT.

117  {
118  global $ilDB;
119  global $ilLog;
120 
121  $ilLog->write(__METHOD__.': Cloning container sorting.');
122 
123  $target_obj_id = ilObject::_lookupObjId($a_target_id);
124 
125  include_once('./Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
126  $mappings = ilCopyWizardOptions::_getInstance($a_copy_id)->getMappings();
127 
128  $query = "SELECT * FROM container_sorting ".
129  "WHERE obj_id = ".$ilDB->quote($this->obj_id, 'integer');
130 
131  $res = $ilDB->query($query);
132 
133  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
134  {
135  if(!isset($mappings[$row->child_id]) or !$mappings[$row->child_id])
136  {
137  #$ilLog->write(__METHOD__.': No mapping found for:'.$row->child_id);
138  continue;
139  }
140 
141  if($row->parent_id and (!isset($mappings[$row->parent_id]) or !$mappings[$row->parent_id]))
142  {
143  continue;
144  }
145 
146  $query = "DELETE FROM container_sorting ".
147  "WHERE obj_id = ".$ilDB->quote($target_obj_id,'integer')." ".
148  "AND child_id = ".$ilDB->quote($mappings[$row->child_id],'integer')." ".
149  "AND parent_type = ".$ilDB->quote($row->parent_type,'text').' '.
150  "AND parent_id = ".$ilDB->quote((int) $mappings[$row->parent_id],'integer');
151  $ilDB->manipulate($query);
152 
153  // Add new value
154  $query = "INSERT INTO container_sorting (obj_id,child_id,position,parent_type,parent_id) ".
155  "VALUES( ".
156  $ilDB->quote($target_obj_id ,'integer').", ".
157  $ilDB->quote($mappings[$row->child_id] ,'integer').", ".
158  $ilDB->quote($row->position,'integer').", ".
159  $ilDB->quote($row->parent_type,'text').", ".
160  $ilDB->quote((int) $mappings[$row->parent_id],'integer').
161  ")";
162  $ilDB->manipulate($query);
163  }
164  return true;
165  }
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
static _getInstance($a_copy_id)
Get instance of copy wizard options.
static _lookupObjId($a_id)
+ Here is the call graph for this function:

◆ getSortMode()

ilContainerSorting::getSortMode ( )

get sort mode

public

Parameters

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:

◆ isManualSortingEnabled()

ilContainerSorting::isManualSortingEnabled ( )

is manual sorting enabled

public

Returns
bool

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

References $manual_sort_enabled.

287  {
288  return (bool) $this->manual_sort_enabled;
289  }

◆ lookupPositions()

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

97  {
98  global $ilDB;
99 
100  $query = "SELECT * FROM container_sorting WHERE ".
101  "obj_id = ".$ilDB->quote($a_obj_id,'integer');
102  $res = $ilDB->query($query);
103  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
104  {
105  $sorted[$row->child_id] = $row->position;
106  }
107  return $sorted ? $sorted : array();
108  }
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
+ Here is the caller graph for this function:

◆ read()

ilContainerSorting::read ( )
private

Read.

private

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

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

Referenced by __construct().

394  {
395  if(!$this->obj_id)
396  {
397  return true;
398  }
399 
400  include_once('Services/Container/classes/class.ilContainerSortingSettings.php');
401  $this->manual_sort_enabled = ilContainerSortingSettings::_isManualSortingEnabled($this->obj_id);
402  $this->sorting_mode = ilContainerSortingSettings::_lookupSortMode($this->obj_id);
403 
404  $query = "SELECT * FROM container_sorting ".
405  "WHERE obj_id = ".$this->db->quote($this->obj_id ,'integer')." ORDER BY position";
406  $res = $this->db->query($query);
407  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
408  {
409  if($row->parent_id)
410  {
411  $this->sorting[$row->parent_type][$row->parent_id][$row->child_id] = $row->position;
412  }
413  else
414  {
415  $this->sorting['all'][$row->child_id] = $row->position;
416  }
417  }
418  return true;
419  }
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
_isManualSortingEnabled($a_obj_id)
is manual sorting enabled
static _lookupSortMode($a_obj_id)
lookup sort mode
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveItems()

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

Referenced by savePost().

335  {
336  global $ilDB;
337 
338  foreach($a_items as $child_id => $position)
339  {
340  $ilDB->replace(
341  'container_sorting',
342  array(
343  'obj_id' => array('integer',$this->obj_id),
344  'child_id' => array('integer',$child_id),
345  'parent_id' => array('integer',0)
346  ),
347  array(
348  'parent_type' => array('text',''),
349  'position' => array('integer',$position)
350  )
351  );
352  }
353  return true;
354  }
+ Here is the caller graph for this function:

◆ savePost()

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

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

299  {
300  global $ilLog;
301 
302  if(!is_array($a_type_positions))
303  {
304  return false;
305  }
306  foreach($a_type_positions as $key => $position)
307  {
308  if(!is_array($position))
309  {
310  $items[$key] = $position * 100;
311  }
312  else
313  {
314  $ilLog->write(__METHOD__.': Deprecated call');
315  foreach($position as $parent_id => $sub_items)
316  {
317  $this->saveSubItems($key,$parent_id,$sub_items ? $sub_items : array());
318  }
319  }
320  }
321  $this->saveItems($items ? $items : array());
322  }
saveItems($a_items)
save items
saveSubItems($a_parent_type, $a_parent_id, $a_items)
Save subitem ordering (sessions, learning objectives)
+ Here is the call graph for this function:

◆ saveSubItems()

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

Referenced by savePost().

364  {
365  global $ilDB;
366 
367  foreach($a_items as $child_id => $position)
368  {
369  $ilDB->replace(
370  'container_sorting',
371  array(
372  'obj_id' => array('integer',$this->obj_id),
373  'child_id' => array('integer',$child_id),
374  'parent_id' => array('integer',$a_parent_id)
375  ),
376  array(
377  'parent_type' => array('text',$a_parent_type),
378  'position' => array('integer',$position)
379  )
380  );
381  }
382  return true;
383 
384  }
+ Here is the caller graph for this function:

◆ sortItems()

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(), ilContainer\SORT_ACTIVATION, ilContainer\SORT_TITLE, and ilUtil\sortArray().

177  {
178  $sorted = array();
179  if(!$this->manual_sort_enabled)
180  {
181  switch($this->getSortMode())
182  {
184  foreach((array) $a_items as $type => $data)
185  {
186  // this line used until #4389 has been fixed (3.10.6)
187  // reanimated with 4.4.0
188  $sorted[$type] = ilUtil::sortArray((array) $data,'title','asc',false);
189 
190  // the next line tried to use db sorting and has replaced sortArray due to bug #4389
191  // but leads to bug #12165. PHP should be able to do a proper sorting, if the locale
192  // is set correctly, so we witch back to sortArray (with 4.4.0) and see what
193  // feedback we get
194  // (next line has been used from 3.10.6 to 4.3.x)
195 // $sorted[$type] = $data;
196  }
197  return $sorted ? $sorted : array();
198 
200  foreach((array) $a_items as $type => $data)
201  {
202  $sorted[$type] = ilUtil::sortArray((array) $data,'start','asc',true);
203  }
204  return $sorted ? $sorted : array();
205  }
206  return $a_items;
207  }
208  if(!count($a_items))
209  {
210  return $a_items;
211  }
212  foreach((array) $a_items as $type => $data)
213  {
214  // Add position
215  $items = array();
216  foreach((array) $data as $key => $item)
217  {
218  $items[$key] = $item;
219  if(is_array($this->sorting['all']) and isset($this->sorting['all'][$item['child']]))
220  {
221  $items[$key]['position'] = $this->sorting['all'][$item['child']];
222  }
223  else
224  {
225  $items[$key]['position'] = self::ORDER_DEFAULT;
226  }
227  }
228 
229  switch($type)
230  {
231  case '_all':
232  $sorted[$type] = ilUtil::sortArray((array) $items,'position','asc',true);
233  break;
234 
235  case '_non_sess':
236  $sorted[$type] = ilUtil::sortArray((array) $items,'position','asc',true);
237  break;
238 
239  default:
240  $sorted[$type] = ilUtil::sortArray((array) $items,'position','asc',true);
241  break;
242  }
243  }
244  return $sorted ? $sorted : array();
245  }
static sortArray($array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
+ Here is the call graph for this function:

◆ sortSubItems()

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

sort subitems (items of sessions or learning objectives)

public

Parameters

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

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

255  {
256  switch($this->getSortMode())
257  {
259  // Add position
260  $items = array();
261  foreach($a_items as $key => $item)
262  {
263  $items[$key] = $item;
264  $items[$key]['position'] = isset($this->sorting[$a_parent_type][$a_parent_id][$item['child']]) ?
265  $this->sorting[$a_parent_type][$a_parent_id][$item['child']] : self::ORDER_DEFAULT;
266  }
267  return ilUtil::sortArray((array) $items,'position','asc',true);
268 
269 
271  default:
272  return ilUtil::sortArray((array) $a_items,'title','asc',true);
273  }
274 
275  }
static sortArray($array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
+ Here is the call graph for this function:

Field Documentation

◆ $db

ilContainerSorting::$db
protected

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

◆ $instances

ilContainerSorting::$instances = array()
staticprotected

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

◆ $manual_sort_enabled

ilContainerSorting::$manual_sort_enabled = false
protected

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

Referenced by isManualSortingEnabled().

◆ $obj_id

ilContainerSorting::$obj_id
protected

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

◆ $sorting_mode

ilContainerSorting::$sorting_mode = 0
protected

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

Referenced by getSortMode().

◆ ORDER_DEFAULT

const ilContainerSorting::ORDER_DEFAULT = 999999

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


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