ILIAS  eassessment Revision 61809
 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  if($course_ref_id = $tree->checkForParentType($ref_id,'crs'))
120  {
121  $a_obj_id = ilObject::_lookupObjId($course_ref_id);
122  }
123 
124  $query = "SELECT * FROM container_sorting_set ".
125  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
126  $res = $ilDB->query($query);
127 
128  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
129  {
130  return $row->sort_mode;
131  }
133  }
134 
135 
143  public function _isManualSortingEnabled($a_obj_id)
144  {
145  return self::_lookupSortMode($a_obj_id) == ilContainer::SORT_MANUAL;
146  }
147 
157  public static function _cloneSettings($a_old_id,$a_new_id)
158  {
159  global $ilLog;
160  global $ilDB;
161 
162  $query = "SELECT sort_mode FROM container_sorting_set ".
163  "WHERE obj_id = ".$ilDB->quote($a_old_id ,'integer')." ";
164  $res = $ilDB->query($query);
165  while($row = $res->fetchRow())
166  {
167  $query = "DELETE FROM container_sorting_set ".
168  "WHERE obj_id = ".$ilDB->quote($a_new_id)." ";
169  $ilDB->manipulate($query);
170 
171  $query = "INSERT INTO container_sorting_set (obj_id,sort_mode) ".
172  "VALUES( ".
173  $ilDB->quote($a_new_id ,'integer').", ".
174  $ilDB->quote($row[0] ,'integer')." ".
175  ")";
176  $ilDB->manipulate($query);
177  }
178  return true;
179  }
180 
187  public function getSortMode()
188  {
189  return $this->sort_mode ? $this->sort_mode : 0;
190  }
191 
199  public function setSortMode($a_mode)
200  {
201  $this->sort_mode = (int) $a_mode;
202  }
203 
210  public function update()
211  {
212  global $ilDB;
213 
214  $query = "DELETE FROM container_sorting_set ".
215  "WHERE obj_id = ".$ilDB->quote($this->obj_id,'integer');
216  $res = $ilDB->manipulate($query);
217 
218  $this->save();
219  }
220 
227  public function save()
228  {
229  global $ilDB;
230 
231  $query = "INSERT INTO container_sorting_set (obj_id,sort_mode) ".
232  "VALUES ( ".
233  $this->db->quote($this->obj_id ,'integer').", ".
234  $this->db->quote($this->sort_mode ,'integer')." ".
235  ")";
236  $res = $ilDB->manipulate($query);
237  }
238 
243  public function delete()
244  {
245  global $ilDB;
246 
247  $query = 'DELETE FROM container_sorting_set WHERE obj_id = '.$ilDB->quote($this->obj_id,'integer');
248  $ilDB->query($query);
249  }
250 
258  private function read()
259  {
260  if(!$this->obj_id)
261  {
262  return true;
263  }
264 
265  $query = "SELECT * FROM container_sorting_set ".
266  "WHERE obj_id = ".$this->db->quote($this->obj_id ,'integer')." ";
267 
268  $res = $this->db->query($query);
269  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
270  {
271  $this->sort_mode = $row->sort_mode;
272  }
273  }
274 
280  public static function sortModeToString($a_sort_mode)
281  {
282  global $lng;
283 
284  $lng->loadLanguageModule('crs');
285  switch($a_sort_mode)
286  {
288  return $lng->txt('crs_sort_activation');
289 
291  return $lng->txt('crs_sort_manual');
292 
294  return $lng->txt('crs_sort_title');
295 
296  }
297  return '';
298  }
299 }
300 ?>