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