ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilMDRequirement.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 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 
31 include_once 'class.ilMDBase.php';
32 
34 {
35  function ilMDRequirement($a_rbac_id = 0,$a_obj_id = 0,$a_obj_type = '')
36  {
37  parent::ilMDBase($a_rbac_id,
38  $a_obj_id,
39  $a_obj_type);
40  }
41 
42  // SET/GET
43  function setOrCompositeId($a_or_composite_id)
44  {
45  $this->or_composite_id = (int) $a_or_composite_id;
46  }
47  function getOrCompositeId()
48  {
49  return (int) $this->or_composite_id;
50  }
51 
52 
53  function setOperatingSystemName($a_val)
54  {
55  switch($a_val)
56  {
57  case 'PC-DOS':
58  case 'MS-Windows':
59  case 'MacOS':
60  case 'Unix':
61  case 'Multi-OS':
62  case 'None':
63  $this->operating_system_name = $a_val;
64  return true;
65 
66  default:
67  return false;
68  }
69  }
71  {
72  return $this->operating_system_name;
73  }
75  {
76  $this->operating_system_minimum_version = $a_val;
77  }
79  {
80  return $this->operating_system_minimum_version;
81  }
83  {
84  $this->operating_system_maximum_version = $a_val;
85  }
87  {
88  return $this->operating_system_maximum_version;
89  }
90  function setBrowserName($a_val)
91  {
92  switch($a_val)
93  {
94  case 'Any':
95  case 'NetscapeCommunicator':
96  case 'MS-InternetExplorer':
97  case 'Opera':
98  case 'Amaya':
99  case 'Mozilla':
100  $this->browser_name = $a_val;
101  return true;
102 
103  default:
104  return false;
105  }
106  }
107  function getBrowserName()
108  {
109  return $this->browser_name;
110  }
111  function setBrowserMinimumVersion($a_val)
112  {
113  $this->browser_minimum_version = $a_val;
114  }
116  {
117  return $this->browser_minimum_version;
118  }
119  function setBrowserMaximumVersion($a_val)
120  {
121  $this->browser_maximum_version = $a_val;
122  }
124  {
125  return $this->browser_maximum_version;
126  }
127 
128  function save()
129  {
130  global $ilDB;
131 
132  $fields = $this->__getFields();
133  $fields['meta_requirement_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_requirement'));
134 
135  if($this->db->insert('il_meta_requirement',$fields))
136  {
137  $this->setMetaId($next_id);
138  return $this->getMetaId();
139  }
140  return false;
141  }
142 
143  function update()
144  {
145  global $ilDB;
146 
147  if($this->getMetaId())
148  {
149  if($this->db->update('il_meta_requirement',
150  $this->__getFields(),
151  array("meta_requirement_id" => array('integer',$this->getMetaId()))))
152  {
153  return true;
154  }
155  }
156  return false;
157  }
158 
159  function delete()
160  {
161  global $ilDB;
162 
163  if($this->getMetaId())
164  {
165  $query = "DELETE FROM il_meta_requirement ".
166  "WHERE meta_requirement_id = ".$ilDB->quote($this->getMetaId() ,'integer');
167  $res = $ilDB->manipulate($query);
168  return true;
169  }
170  return false;
171  }
172 
173 
174  function __getFields()
175  {
176  return array('rbac_id' => array('integer',$this->getRBACId()),
177  'obj_id' => array('integer',$this->getObjId()),
178  'obj_type' => array('text',$this->getObjType()),
179  'parent_type' => array('text',$this->getParentType()),
180  'parent_id' => array('integer',$this->getParentId()),
181  'operating_system_name' => array('text',$this->getOperatingSystemName()),
182  'os_min_version' => array('text',$this->getOperatingSystemMinimumVersion()),
183  'os_max_version' => array('text',$this->getOperatingSystemMaximumVersion()),
184  'browser_name' => array('text',$this->getBrowserName()),
185  'browser_minimum_version' => array('text',$this->getBrowserMinimumVersion()),
186  'browser_maximum_version' => array('text',$this->getBrowserMaximumVersion()),
187  'or_composite_id' => array('integer',$this->getOrCompositeId()));
188  }
189 
190  function read()
191  {
192  global $ilDB;
193 
194  include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php';
195 
196  if($this->getMetaId())
197  {
198  $query = "SELECT * FROM il_meta_requirement ".
199  "WHERE meta_requirement_id = ".$ilDB->quote($this->getMetaId() ,'integer');
200 
201  $res = $this->db->query($query);
202  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
203  {
204  $this->setRBACId($row->rbac_id);
205  $this->setObjId($row->obj_id);
206  $this->setObjType($row->obj_type);
207  $this->setParentId($row->parent_id);
208  $this->setParentType($row->parent_type);
209  $this->setOperatingSystemName($row->operating_system_name);
210  $this->setOperatingSystemMinimumVersion($row->os_min_version);
211  $this->setOperatingSystemMaximumVersion($row->os_max_version);
212  $this->setBrowserName($row->browser_name);
213  $this->setBrowserMinimumVersion($row->browser_minimum_version);
214  $this->setBrowserMaximumVersion($row->browser_maximum_version);
215  $this->setOrCompositeId($row->or_composite_id);
216  }
217  }
218  return true;
219  }
220 
221  /*
222  * XML Export of all meta data
223  * @param object (xml writer) see class.ilMD2XML.php
224  *
225  */
226  function toXML(&$writer)
227  {
228  $writer->xmlStartTag('Requirement');
229  $writer->xmlStartTag('Type');
230 
231  if(strlen($this->getOperatingSystemName()))
232  {
233  $writer->xmlElement('OperatingSystem',array('Name' => $this->getOperatingSystemName()
234  ? $this->getOperatingSystemName()
235  : 'None',
236  'MinimumVersion' => $this->getOperatingSystemMinimumVersion(),
237  'MaximumVersion' => $this->getOperatingSystemMaximumVersion()));
238  }
239  if(strlen($this->getBrowserName()))
240  {
241  $writer->xmlElement('Browser',array('Name' => $this->getBrowserName()
242  ? $this->getBrowserName()
243  : 'Any',
244  'MinimumVersion' => $this->getBrowserMinimumVersion(),
245  'MaximumVersion' => $this->getBrowserMaximumVersion()));
246  }
247  $writer->xmlEndTag('Type');
248  $writer->xmlEndTag('Requirement');
249 
250  }
251 
252 
253  // STATIC
254  function _getIds($a_rbac_id,$a_obj_id,$a_parent_id,$a_parent_type,$a_or_composite_id = 0)
255  {
256  global $ilDB;
257 
258  $query = "SELECT meta_requirement_id FROM il_meta_requirement ".
259  "WHERE rbac_id = ".$ilDB->quote($a_rbac_id ,'integer')." ".
260  "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ".
261  "AND parent_id = ".$ilDB->quote($a_parent_id ,'integer')." ".
262  "AND parent_type = ".$ilDB->quote($a_parent_type ,'text')." ".
263  "AND or_composite_id = ".$ilDB->quote($a_or_composite_id ,'integer');
264 
265  $res = $ilDB->query($query);
266  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
267  {
268  $ids[] = $row->meta_requirement_id;
269  }
270  return $ids ? $ids : array();
271  }
272 }
273 ?>