ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilMD5295Requirement.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.ilMD5295Base.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 $DIC;
122
123 $ilDB = $DIC['ilDB'];
124
125 $fields = $this->__getFields();
126 $fields['meta_requirement_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_requirement'));
127
128 if ($this->db->insert('il_meta_requirement', $fields)) {
129 $this->setMetaId($next_id);
130 return $this->getMetaId();
131 }
132 return false;
133 }
134
135 public function update()
136 {
137 global $DIC;
138
139 $ilDB = $DIC['ilDB'];
140
141 if ($this->getMetaId()) {
142 if ($this->db->update(
143 'il_meta_requirement',
144 $this->__getFields(),
145 array("meta_requirement_id" => array('integer',$this->getMetaId()))
146 )) {
147 return true;
148 }
149 }
150 return false;
151 }
152
153 public function delete()
154 {
155 global $DIC;
156
157 $ilDB = $DIC['ilDB'];
158
159 if ($this->getMetaId()) {
160 $query = "DELETE FROM il_meta_requirement " .
161 "WHERE meta_requirement_id = " . $ilDB->quote($this->getMetaId(), 'integer');
162 $res = $ilDB->manipulate($query);
163 return true;
164 }
165 return false;
166 }
167
168
169 public function __getFields()
170 {
171 return array('rbac_id' => array('integer',$this->getRBACId()),
172 'obj_id' => array('integer',$this->getObjId()),
173 'obj_type' => array('text',$this->getObjType()),
174 'parent_type' => array('text',$this->getParentType()),
175 'parent_id' => array('integer',$this->getParentId()),
176 'operating_system_name' => array('text',$this->getOperatingSystemName()),
177 'os_min_version' => array('text',$this->getOperatingSystemMinimumVersion()),
178 'os_max_version' => array('text',$this->getOperatingSystemMaximumVersion()),
179 'browser_name' => array('text',$this->getBrowserName()),
180 'browser_minimum_version' => array('text',$this->getBrowserMinimumVersion()),
181 'browser_maximum_version' => array('text',$this->getBrowserMaximumVersion()),
182 'or_composite_id' => array('integer',$this->getOrCompositeId()));
183 }
184
185 public function read()
186 {
187 global $DIC;
188
189 $ilDB = $DIC['ilDB'];
190
191 include_once 'Services/Migration/DBUpdate_5295/classes/class.ilMD5295LanguageItem.php';
192
193 if ($this->getMetaId()) {
194 $query = "SELECT * FROM il_meta_requirement " .
195 "WHERE meta_requirement_id = " . $ilDB->quote($this->getMetaId(), 'integer');
196
197 $res = $this->db->query($query);
198 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
199 $this->setRBACId($row->rbac_id);
200 $this->setObjId($row->obj_id);
201 $this->setObjType($row->obj_type);
202 $this->setParentId($row->parent_id);
203 $this->setParentType($row->parent_type);
204 $this->setOperatingSystemName($row->operating_system_name);
205 $this->setOperatingSystemMinimumVersion($row->os_min_version);
206 $this->setOperatingSystemMaximumVersion($row->os_max_version);
207 $this->setBrowserName($row->browser_name);
208 $this->setBrowserMinimumVersion($row->browser_minimum_version);
209 $this->setBrowserMaximumVersion($row->browser_maximum_version);
210 $this->setOrCompositeId($row->or_composite_id);
211 }
212 }
213 return true;
214 }
215
216 /*
217 * XML Export of all meta data
218 * @param object (xml writer) see class.ilMD52952XML.php
219 *
220 */
221 public function toXML(&$writer)
222 {
223 $writer->xmlStartTag('Requirement');
224 $writer->xmlStartTag('Type');
225
226 if (strlen($this->getOperatingSystemName())) {
227 $writer->xmlElement('OperatingSystem', array('Name' => $this->getOperatingSystemName()
228 ? $this->getOperatingSystemName()
229 : 'None',
230 'MinimumVersion' => $this->getOperatingSystemMinimumVersion(),
231 'MaximumVersion' => $this->getOperatingSystemMaximumVersion()));
232 }
233 if (strlen($this->getBrowserName())) {
234 $writer->xmlElement('Browser', array('Name' => $this->getBrowserName()
235 ? $this->getBrowserName()
236 : 'Any',
237 'MinimumVersion' => $this->getBrowserMinimumVersion(),
238 'MaximumVersion' => $this->getBrowserMaximumVersion()));
239 }
240 $writer->xmlEndTag('Type');
241 $writer->xmlEndTag('Requirement');
242 }
243
244
245 // STATIC
246 public static function _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type, $a_or_composite_id = 0)
247 {
248 global $DIC;
249
250 $ilDB = $DIC['ilDB'];
251
252 $query = "SELECT meta_requirement_id FROM il_meta_requirement " .
253 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
254 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
255 "AND parent_id = " . $ilDB->quote($a_parent_id, 'integer') . " " .
256 "AND parent_type = " . $ilDB->quote($a_parent_type, 'text') . " " .
257 "AND or_composite_id = " . $ilDB->quote($a_or_composite_id, 'integer');
258
259 $res = $ilDB->query($query);
260 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
261 $ids[] = $row->meta_requirement_id;
262 }
263 return $ids ? $ids : array();
264 }
265}
An exception for terminatinating execution or to throw for unit testing.
setParentType($a_parent_type)
setMetaId($a_meta_id, $a_read_data=true)
static _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type, $a_or_composite_id=0)
setOrCompositeId($a_or_composite_id)
global $DIC
Definition: goto.php:24
$query
foreach($_POST as $key=> $value) $res
global $ilDB