ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
24 include_once './Services/Container/classes/class.ilContainer.php';
25 
36 {
37  protected $obj_id;
38  protected $sort_mode;
39 
40  protected $db;
41 
49  public function __construct($a_obj_id)
50  {
51  global $ilDB;
52 
53  $this->obj_id = $a_obj_id;
54  $this->db = $ilDB;
55 
56  $this->read();
57  }
58 
59  public static function _readSortMode($a_obj_id)
60  {
61  global $ilDB;
62 
63  $query = "SELECT * FROM container_sorting_set ".
64  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
65  $res = $ilDB->query($query);
66 
67  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
68  {
69  return $row->sort_mode;
70  }
72  }
73 
74 
83  public static function _lookupSortMode($a_obj_id)
84  {
85  global $tree, $ilDB, $objDefinition;
86 
87  // Try to read from table
88  $query = "SELECT * FROM container_sorting_set ".
89  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
90  $res = $ilDB->query($query);
91 
92  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
93  {
94  if($row->sort_mode != ilContainer::SORT_INHERIT)
95  {
96  return $row->sort_mode;
97  }
98  }
100  }
101 
107  public static function lookupSortModeFromParentContainer($a_obj_id)
108  {
109  global $tree, $ilDB, $objDefinition;
110 
111  if(!$objDefinition->isContainer(ilObject::_lookupType($a_obj_id)))
112  {
114  }
115 
116  $ref_ids = ilObject::_getAllReferences($a_obj_id);
117  $ref_id = current($ref_ids);
118 
119 
120  if($cont_ref_id = $tree->checkForParentType($ref_id,'grp'))
121  {
122  $a_obj_id = ilObject::_lookupObjId($cont_ref_id);
123  $sort_mode = self::_readSortMode($a_obj_id);
125  {
126  return $sort_mode;
127  }
128  }
129  if($cont_ref_id = $tree->checkForParentType($ref_id,'crs'))
130  {
131  $a_obj_id = ilObject::_lookupObjId($cont_ref_id);
132  $sort_mode = self::_readSortMode($a_obj_id);
134  {
135  return $sort_mode;
136  }
137  }
139  }
140 
141 
149  public function _isManualSortingEnabled($a_obj_id)
150  {
151  return self::_lookupSortMode($a_obj_id) == ilContainer::SORT_MANUAL;
152  }
153 
163  public static function _cloneSettings($a_old_id,$a_new_id)
164  {
165  global $ilLog;
166  global $ilDB;
167 
168  $query = "SELECT sort_mode FROM container_sorting_set ".
169  "WHERE obj_id = ".$ilDB->quote($a_old_id ,'integer')." ";
170  $res = $ilDB->query($query);
171  while($row = $res->fetchRow())
172  {
173  $query = "DELETE FROM container_sorting_set ".
174  "WHERE obj_id = ".$ilDB->quote($a_new_id)." ";
175  $ilDB->manipulate($query);
176 
177  $query = "INSERT INTO container_sorting_set (obj_id,sort_mode) ".
178  "VALUES( ".
179  $ilDB->quote($a_new_id ,'integer').", ".
180  $ilDB->quote($row[0] ,'integer')." ".
181  ")";
182  $ilDB->manipulate($query);
183  }
184  return true;
185  }
186 
193  public function getSortMode()
194  {
195  return $this->sort_mode ? $this->sort_mode : 0;
196  }
197 
205  public function setSortMode($a_mode)
206  {
207  $this->sort_mode = (int) $a_mode;
208  }
209 
216  public function update()
217  {
218  global $ilDB;
219 
220  $query = "DELETE FROM container_sorting_set ".
221  "WHERE obj_id = ".$ilDB->quote($this->obj_id,'integer');
222  $res = $ilDB->manipulate($query);
223 
224  $this->save();
225  }
226 
233  public function save()
234  {
235  global $ilDB;
236 
237  $query = "INSERT INTO container_sorting_set (obj_id,sort_mode) ".
238  "VALUES ( ".
239  $this->db->quote($this->obj_id ,'integer').", ".
240  $this->db->quote($this->sort_mode ,'integer')." ".
241  ")";
242  $res = $ilDB->manipulate($query);
243  }
244 
249  public function delete()
250  {
251  global $ilDB;
252 
253  $query = 'DELETE FROM container_sorting_set WHERE obj_id = '.$ilDB->quote($this->obj_id,'integer');
254  $ilDB->query($query);
255  }
256 
264  protected function read()
265  {
266  if(!$this->obj_id)
267  {
268  return TRUE;
269  }
270 
271  $query = "SELECT * FROM container_sorting_set ".
272  "WHERE obj_id = ".$this->db->quote($this->obj_id ,'integer')." ";
273 
274  $res = $this->db->query($query);
275  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
276  {
277  $this->sort_mode = $row->sort_mode;
278  return TRUE;
279  }
280  }
281 
287  public static function sortModeToString($a_sort_mode)
288  {
289  global $lng;
290 
291  $lng->loadLanguageModule('crs');
292  switch($a_sort_mode)
293  {
295  return $lng->txt('crs_sort_activation');
296 
298  return $lng->txt('crs_sort_manual');
299 
301  return $lng->txt('crs_sort_title');
302 
303  }
304  return '';
305  }
306 }
307 ?>