ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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
78
79 public static function _readSortMode($a_obj_id)
80 {
81 global $ilDB;
82
83 $query = "SELECT * FROM container_sorting_set ".
84 "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
85 $res = $ilDB->query($query);
86
87 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
88 {
89 return $row->sort_mode;
90 }
92 }
93
94
103 public static function _lookupSortMode($a_obj_id)
104 {
105 global $tree, $ilDB, $objDefinition;
106
107 // Try to read from table
108 $query = "SELECT * FROM container_sorting_set ".
109 "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
110 $res = $ilDB->query($query);
111
112 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
113 {
114 if($row->sort_mode != ilContainer::SORT_INHERIT)
115 {
116 return $row->sort_mode;
117 }
118 }
120 }
121
127 public static function lookupSortModeFromParentContainer($a_obj_id)
128 {
129 global $tree, $ilDB, $objDefinition;
130
131 if(!$objDefinition->isContainer(ilObject::_lookupType($a_obj_id)))
132 {
134 }
135
136 $ref_ids = ilObject::_getAllReferences($a_obj_id);
137 $ref_id = current($ref_ids);
138
139
140 if($cont_ref_id = $tree->checkForParentType($ref_id,'grp'))
141 {
142 $a_obj_id = ilObject::_lookupObjId($cont_ref_id);
143 $sort_mode = self::_readSortMode($a_obj_id);
145 {
146 return $sort_mode;
147 }
148 }
149 if($cont_ref_id = $tree->checkForParentType($ref_id,'crs'))
150 {
151 $a_obj_id = ilObject::_lookupObjId($cont_ref_id);
152 $sort_mode = self::_readSortMode($a_obj_id);
154 {
155 return $sort_mode;
156 }
157 }
159 }
160
170 public static function _cloneSettings($a_old_id,$a_new_id)
171 {
172 global $ilDB;
173
174 $query = "SELECT sort_mode,sort_direction,new_items_position,new_items_order ".
175 "FROM container_sorting_set ".
176 "WHERE obj_id = ".$ilDB->quote($a_old_id ,'integer')." ";
177 $res = $ilDB->query($query);
178 while($row = $ilDB->fetchAssoc($res))
179 {
180 $query = "DELETE FROM container_sorting_set ".
181 "WHERE obj_id = ".$ilDB->quote($a_new_id)." ";
182 $ilDB->manipulate($query);
183
184 $query = "INSERT INTO container_sorting_set ".
185 "(obj_id,sort_mode, sort_direction, new_items_position, new_items_order) ".
186 "VALUES( ".
187 $ilDB->quote($a_new_id ,'integer').", ".
188 $ilDB->quote($row["sort_mode"],'integer').", ".
189 $ilDB->quote($row["sort_direction"],'integer').', '.
190 $ilDB->quote($row["new_items_position"],'integer').', '.
191 $ilDB->quote($row["new_items_order"],'integer').' '.
192 ")";
193 $ilDB->manipulate($query);
194 }
195 return true;
196 }
197
204 public function getSortMode()
205 {
206 return $this->sort_mode ? $this->sort_mode : 0;
207 }
208
213 public function getSortDirection()
214 {
215 return $this->sort_direction ? $this->sort_direction : ilContainer::SORT_DIRECTION_ASC;
216 }
217
222 public function getSortNewItemsPosition()
223 {
225 }
226
231 public function getSortNewItemsOrder()
232 {
234 }
235
243 public function setSortMode($a_mode)
244 {
245 $this->sort_mode = (int) $a_mode;
246 }
247
252 public function setSortDirection($a_direction)
253 {
254 $this->sort_direction = (int) $a_direction;
255 }
256
261 public function setSortNewItemsPosition($a_position)
262 {
263 $this->new_items_position = (int)$a_position;
264 }
265
270 public function setSortNewItemsOrder($a_order)
271 {
272 $this->new_items_order = (int)$a_order;
273 }
274
281 public function update()
282 {
283 global $ilDB;
284
285 $query = "DELETE FROM container_sorting_set ".
286 "WHERE obj_id = ".$ilDB->quote($this->obj_id,'integer');
287 $res = $ilDB->manipulate($query);
288
289 $this->save();
290 }
291
298 public function save()
299 {
300 global $ilDB;
301
302 $query = "INSERT INTO container_sorting_set ".
303 "(obj_id,sort_mode, sort_direction, new_items_position, new_items_order) ".
304 "VALUES ( ".
305 $this->db->quote($this->obj_id ,'integer').", ".
306 $this->db->quote($this->sort_mode ,'integer').", ".
307 $this->db->quote($this->sort_direction,'integer').', '.
308 $this->db->quote($this->new_items_position,'integer').', '.
309 $this->db->quote($this->new_items_order,'integer').' '.
310 ")";
311 $res = $ilDB->manipulate($query);
312 }
313
318 public function delete()
319 {
320 global $ilDB;
321
322 $query = 'DELETE FROM container_sorting_set WHERE obj_id = '.$ilDB->quote($this->obj_id,'integer');
323 $ilDB->query($query);
324 }
325
333 protected function read()
334 {
335 if(!$this->obj_id)
336 {
337 return TRUE;
338 }
339
340 $query = "SELECT * FROM container_sorting_set ".
341 "WHERE obj_id = ".$this->db->quote($this->obj_id ,'integer')." ";
342
343 $res = $this->db->query($query);
344 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
345 {
346 $this->sort_mode = $row->sort_mode;
347 $this->sort_direction = $row->sort_direction;
348 $this->new_items_position = $row->new_items_position;
349 $this->new_items_order = $row->new_items_order;
350 return TRUE;
351 }
352 }
353
359 public static function sortModeToString($a_sort_mode)
360 {
361 global $lng;
362
363 $lng->loadLanguageModule('crs');
364 switch($a_sort_mode)
365 {
367 return $lng->txt('crs_sort_activation');
368
370 return $lng->txt('crs_sort_manual');
371
373 return $lng->txt('crs_sort_title');
374
376 return $lng->txt('sorting_creation_header');
377 }
378 return '';
379 }
380
388 {
390
391 $attr = array();
392 switch($settings->getSortMode())
393 {
395 switch($settings->getSortNewItemsOrder())
396 {
398 $order = 'Activation';
399 break;
401 $order = 'Creation';
402 break;
404 $order = 'Title';
405 break;
406 }
407
408 $attr = array(
409 'direction' => $settings->getSortDirection() == ilContainer::SORT_DIRECTION_ASC ? "ASC" : "DESC",
410 'position' => $settings->getSortNewItemsPosition() == ilContainer::SORT_NEW_ITEMS_POSITION_BOTTOM ? "Bottom" : "Top",
411 'order' => $order,
412 'type' => 'Manual'
413 );
414
415 break;
416
418 $attr = array(
419 'direction' => $settings->getSortDirection() == ilContainer::SORT_DIRECTION_ASC ? "ASC" : "DESC",
420 'type' => 'Creation'
421 );
422 break;
423
425 $attr = array(
426 'direction' => $settings->getSortDirection() == ilContainer::SORT_DIRECTION_ASC ? "ASC" : "DESC",
427 'type' => 'Title'
428 );
429 break;
431 $attr = array(
432 'direction' => $settings->getSortDirection() == ilContainer::SORT_DIRECTION_ASC ? "ASC" : "DESC",
433 'type' => 'Activation'
434 );
435 break;
437 $attr = array(
438 'type' => 'Inherit'
439 );
440 }
441 $xml->xmlElement('Sort', $attr);
442 }
443
450 public static function _importContainerSortingSettings($attibs, $obj_id)
451 {
453
454 switch($attibs['type'])
455 {
456 case 'Manual':
457 $settings->setSortMode(ilContainer::SORT_MANUAL);
458 break;
459 case 'Creation':
460 $settings->setSortMode(ilContainer::SORT_CREATION);
461 break;
462 case 'Title':
463 $settings->setSortMode(ilContainer::SORT_TITLE);
464 break;
465 case 'Activation':
466 $settings->setSortMode(ilContainer::SORT_ACTIVATION);
467 break;
468 }
469
470 switch($attibs['direction'])
471 {
472 case 'ASC':
473 $settings->setSortDirection(ilContainer::SORT_DIRECTION_ASC);
474 break;
475 case 'DESC':
476 $settings->setSortDirection(ilContainer::SORT_DIRECTION_DESC);
477 break;
478 }
479
480 switch($attibs['position'])
481 {
482 case "Top":
483 $settings->setSortNewItemsPosition(ilContainer::SORT_NEW_ITEMS_POSITION_TOP);
484 break;
485 case "Bottom":
486 $settings->setSortNewItemsPosition(ilContainer::SORT_NEW_ITEMS_POSITION_BOTTOM);
487 break;
488 }
489
490 switch($attibs['order'])
491 {
492 case 'Creation':
493 $settings->setSortNewItemsOrder(ilContainer::SORT_NEW_ITEMS_ORDER_CREATION);
494 break;
495 case 'Title':
496 $settings->setSortNewItemsOrder(ilContainer::SORT_NEW_ITEMS_ORDER_TITLE);
497 break;
498 case 'Activation':
499 $settings->setSortNewItemsOrder(ilContainer::SORT_NEW_ITEMS_ORDER_ACTIVATION);
500 }
501
502 $settings->update();
503 }
504}
505?>
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.
static sortModeToString($a_sort_mode)
get String representation of sort mode
static _importContainerSortingSettings($attibs, $obj_id)
sorting import for all container objects
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
static _lookupType($a_id, $a_reference=false)
lookup object type
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