ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilContainerSortingSettings.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
24include_once './Services/Container/classes/class.ilContainer.php';
25
36{
37 private static $instances = array();
38
39 protected $obj_id;
44
45 protected $db;
46
54 public function __construct($a_obj_id = 0)
55 {
56 global $ilDB;
57
58 $this->obj_id = $a_obj_id;
59 $this->db = $ilDB;
60
61 $this->read();
62 }
63
69 public static function getInstanceByObjId($a_obj_id)
70 {
71 if(self::$instances[$a_obj_id])
72 {
73 return self::$instances[$a_obj_id];
74 }
75 return self::$instances[$a_obj_id] = new self($a_obj_id);
76 }
77
82 public function loadEffectiveSettings()
83 {
85 {
86 return $this;
87 }
88
89 $effective_settings = $this->getInheritedSettings($this->obj_id);
90 $inherited = clone $this;
91
92 if($effective_settings->getSortMode() == ilContainer::SORT_INHERIT)
93 {
94 $inherited->setSortMode(ilContainer::SORT_TITLE);
95 }
96 else
97 {
98 $inherited->setSortMode($effective_settings->getSortMode());
99 $inherited->setSortNewItemsOrder($effective_settings->getSortNewItemsOrder());
100 $inherited->setSortNewItemsPosition($effective_settings->getSortNewItemsPosition());
101 }
102 return $inherited;
103 }
104
105
111 public function getInheritedSettings($a_container_obj_id)
112 {
113 global $tree;
114
115 if(!$a_container_obj_id)
116 {
117 $a_container_obj_id = $this->obj_id;
118 }
119
120 $ref_ids = ilObject::_getAllReferences($a_container_obj_id);
121 $ref_id = current($ref_ids);
122
123 if($cont_ref_id = $tree->checkForParentType($ref_id,'grp',true))
124 {
125 $parent_obj_id = ilObject::_lookupObjId($cont_ref_id);
126 $parent_settings = self::getInstanceByObjId($parent_obj_id);
127
128 if($parent_settings->getSortMode() == ilContainer::SORT_INHERIT)
129 {
130 return $this->getInheritedSettings($parent_obj_id);
131 }
132 return $parent_settings;
133 }
134
135 if($cont_ref_id = $tree->checkForParentType($ref_id,'crs',true))
136 {
137 $parent_obj_id = ilObject::_lookupObjId($cont_ref_id);
138 $parent_settings = self::getInstanceByObjId($parent_obj_id);
139 return $parent_settings;
140 }
141 // no parent settings found => return current settings
142 return $this;
143 }
144
145
146 public static function _readSortMode($a_obj_id)
147 {
148 global $ilDB;
149
150 $query = "SELECT * FROM container_sorting_set ".
151 "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
152 $res = $ilDB->query($query);
153
154 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
155 {
156 return $row->sort_mode;
157 }
159 }
160
161
170 public static function _lookupSortMode($a_obj_id)
171 {
172 global $tree, $ilDB, $objDefinition;
173
174 // Try to read from table
175 $query = "SELECT * FROM container_sorting_set ".
176 "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
177 $res = $ilDB->query($query);
178
179 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
180 {
181 if($row->sort_mode != ilContainer::SORT_INHERIT)
182 {
183 return $row->sort_mode;
184 }
185 }
187 }
188
194 public static function lookupSortModeFromParentContainer($a_obj_id)
195 {
196 $settings = self::getInstanceByObjId($a_obj_id);
197 $inherited_settings = $settings->getInheritedSettings($a_obj_id);
198 return $inherited_settings->getSortMode();
199 }
200
210 public static function _cloneSettings($a_old_id,$a_new_id)
211 {
212 global $ilDB;
213
214 $query = "SELECT sort_mode,sort_direction,new_items_position,new_items_order ".
215 "FROM container_sorting_set ".
216 "WHERE obj_id = ".$ilDB->quote($a_old_id ,'integer')." ";
217 $res = $ilDB->query($query);
218 while($row = $ilDB->fetchAssoc($res))
219 {
220 $query = "DELETE FROM container_sorting_set ".
221 "WHERE obj_id = ".$ilDB->quote($a_new_id)." ";
222 $ilDB->manipulate($query);
223
224 $query = "INSERT INTO container_sorting_set ".
225 "(obj_id,sort_mode, sort_direction, new_items_position, new_items_order) ".
226 "VALUES( ".
227 $ilDB->quote($a_new_id ,'integer').", ".
228 $ilDB->quote($row["sort_mode"],'integer').", ".
229 $ilDB->quote($row["sort_direction"],'integer').', '.
230 $ilDB->quote($row["new_items_position"],'integer').', '.
231 $ilDB->quote($row["new_items_order"],'integer').' '.
232 ")";
233 $ilDB->manipulate($query);
234 }
235 return true;
236 }
237
244 public function getSortMode()
245 {
246 return $this->sort_mode ? $this->sort_mode : 0;
247 }
248
253 public function getSortDirection()
254 {
255 return $this->sort_direction ? $this->sort_direction : ilContainer::SORT_DIRECTION_ASC;
256 }
257
262 public function getSortNewItemsPosition()
263 {
265 }
266
271 public function getSortNewItemsOrder()
272 {
274 }
275
283 public function setSortMode($a_mode)
284 {
285 $this->sort_mode = (int) $a_mode;
286 }
287
292 public function setSortDirection($a_direction)
293 {
294 $this->sort_direction = (int) $a_direction;
295 }
296
301 public function setSortNewItemsPosition($a_position)
302 {
303 $this->new_items_position = (int)$a_position;
304 }
305
310 public function setSortNewItemsOrder($a_order)
311 {
312 $this->new_items_order = (int)$a_order;
313 }
314
321 public function update()
322 {
323 global $ilDB;
324
325 $query = "DELETE FROM container_sorting_set ".
326 "WHERE obj_id = ".$ilDB->quote($this->obj_id,'integer');
327 $res = $ilDB->manipulate($query);
328
329 $this->save();
330 }
331
338 public function save()
339 {
340 global $ilDB;
341
342 $query = "INSERT INTO container_sorting_set ".
343 "(obj_id,sort_mode, sort_direction, new_items_position, new_items_order) ".
344 "VALUES ( ".
345 $this->db->quote($this->obj_id ,'integer').", ".
346 $this->db->quote($this->sort_mode ,'integer').", ".
347 $this->db->quote($this->sort_direction,'integer').', '.
348 $this->db->quote($this->new_items_position,'integer').', '.
349 $this->db->quote($this->new_items_order,'integer').' '.
350 ")";
351 $res = $ilDB->manipulate($query);
352 }
353
358 public function delete()
359 {
360 global $ilDB;
361
362 $query = 'DELETE FROM container_sorting_set WHERE obj_id = '.$ilDB->quote($this->obj_id,'integer');
363 $ilDB->query($query);
364 }
365
373 protected function read()
374 {
375 if(!$this->obj_id)
376 {
377 return TRUE;
378 }
379
380 $query = "SELECT * FROM container_sorting_set ".
381 "WHERE obj_id = ".$this->db->quote($this->obj_id ,'integer')." ";
382
383 $res = $this->db->query($query);
384 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
385 {
386 $this->sort_mode = $row->sort_mode;
387 $this->sort_direction = $row->sort_direction;
388 $this->new_items_position = $row->new_items_position;
389 $this->new_items_order = $row->new_items_order;
390 return TRUE;
391 }
392 }
393
399 public static function sortModeToString($a_sort_mode)
400 {
401 global $lng;
402
403 $lng->loadLanguageModule('crs');
404 switch($a_sort_mode)
405 {
407 return $lng->txt('crs_sort_activation');
408
410 return $lng->txt('crs_sort_manual');
411
413 return $lng->txt('crs_sort_title');
414
416 return $lng->txt('sorting_creation_header');
417 }
418 return '';
419 }
420
428 {
430
431 $attr = array();
432 switch($settings->getSortMode())
433 {
435 switch($settings->getSortNewItemsOrder())
436 {
438 $order = 'Activation';
439 break;
441 $order = 'Creation';
442 break;
444 $order = 'Title';
445 break;
446 }
447
448 $attr = array(
449 'direction' => $settings->getSortDirection() == ilContainer::SORT_DIRECTION_ASC ? "ASC" : "DESC",
450 'position' => $settings->getSortNewItemsPosition() == ilContainer::SORT_NEW_ITEMS_POSITION_BOTTOM ? "Bottom" : "Top",
451 'order' => $order,
452 'type' => 'Manual'
453 );
454
455 break;
456
458 $attr = array(
459 'direction' => $settings->getSortDirection() == ilContainer::SORT_DIRECTION_ASC ? "ASC" : "DESC",
460 'type' => 'Creation'
461 );
462 break;
463
465 $attr = array(
466 'direction' => $settings->getSortDirection() == ilContainer::SORT_DIRECTION_ASC ? "ASC" : "DESC",
467 'type' => 'Title'
468 );
469 break;
471 $attr = array(
472 'direction' => $settings->getSortDirection() == ilContainer::SORT_DIRECTION_ASC ? "ASC" : "DESC",
473 'type' => 'Activation'
474 );
475 break;
477 $attr = array(
478 'type' => 'Inherit'
479 );
480 }
481 $xml->xmlElement('Sort', $attr);
482 }
483
490 public static function _importContainerSortingSettings($attibs, $obj_id)
491 {
493
494 switch($attibs['type'])
495 {
496 case 'Manual':
497 $settings->setSortMode(ilContainer::SORT_MANUAL);
498 break;
499 case 'Creation':
500 $settings->setSortMode(ilContainer::SORT_CREATION);
501 break;
502 case 'Title':
503 $settings->setSortMode(ilContainer::SORT_TITLE);
504 break;
505 case 'Activation':
506 $settings->setSortMode(ilContainer::SORT_ACTIVATION);
507 break;
508 }
509
510 switch($attibs['direction'])
511 {
512 case 'ASC':
513 $settings->setSortDirection(ilContainer::SORT_DIRECTION_ASC);
514 break;
515 case 'DESC':
516 $settings->setSortDirection(ilContainer::SORT_DIRECTION_DESC);
517 break;
518 }
519
520 switch($attibs['position'])
521 {
522 case "Top":
523 $settings->setSortNewItemsPosition(ilContainer::SORT_NEW_ITEMS_POSITION_TOP);
524 break;
525 case "Bottom":
526 $settings->setSortNewItemsPosition(ilContainer::SORT_NEW_ITEMS_POSITION_BOTTOM);
527 break;
528 }
529
530 switch($attibs['order'])
531 {
532 case 'Creation':
533 $settings->setSortNewItemsOrder(ilContainer::SORT_NEW_ITEMS_ORDER_CREATION);
534 break;
535 case 'Title':
536 $settings->setSortNewItemsOrder(ilContainer::SORT_NEW_ITEMS_ORDER_TITLE);
537 break;
538 case 'Activation':
539 $settings->setSortNewItemsOrder(ilContainer::SORT_NEW_ITEMS_ORDER_ACTIVATION);
540 }
541
542 $settings->update();
543 }
544}
545?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
static lookupSortModeFromParentContainer($a_obj_id)
Lookup sort mode from parent container.
static _exportContainerSortingSettings(ilXmlWriter $xml, $obj_id)
sorting XML-export for all container objects
setSortDirection($a_direction)
Set sort direction.
setSortNewItemsPosition($a_position)
SET new item position.
static _cloneSettings($a_old_id, $a_new_id)
Clone settings.
static getInstanceByObjId($a_obj_id)
Get singleton instance.
static _lookupSortMode($a_obj_id)
lookup sort mode
setSortNewItemsOrder($a_order)
SET new item order.
getInheritedSettings($a_container_obj_id)
Read inherited settings of course/group @global ilTree $tree.
static sortModeToString($a_sort_mode)
get String representation of sort mode
static _importContainerSortingSettings($attibs, $obj_id)
sorting import for all container objects
loadEffectiveSettings()
Load inherited settings.
const SORT_DIRECTION_DESC
const SORT_NEW_ITEMS_ORDER_ACTIVATION
const SORT_NEW_ITEMS_ORDER_TITLE
const SORT_NEW_ITEMS_ORDER_CREATION
const SORT_NEW_ITEMS_POSITION_BOTTOM
const SORT_NEW_ITEMS_POSITION_TOP
const SORT_DIRECTION_ASC
static _lookupObjId($a_id)
static _getAllReferences($a_id)
get all reference ids of object
XML writer class.
xmlElement($tag, $attrs=NULL, $data=Null, $encode=TRUE, $escape=TRUE)
Writes a basic element (no children, just textual content)
global $lng
Definition: privfeed.php:40
$ref_id
Definition: sahs_server.php:39
global $ilDB