ILIAS  release_7 Revision v7.30-3-g800a261c036
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
33class ilMDRequirement extends ilMDBase
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 if ($this->db->autoExecute(
122 'il_meta_requirement',
123 $this->__getFields(),
125 )) {
126 $this->setMetaId($this->db->getLastInsertId());
127
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->autoExecute(
139 'il_meta_requirement',
140 $this->__getFields(),
142 "meta_requirement_id = " . $ilDB->quote($this->getMetaId())
143 )) {
144 return true;
145 }
146 }
147 return false;
148 }
149
150 public function delete()
151 {
152 global $ilDB;
153
154 if ($this->getMetaId()) {
155 $query = "DELETE FROM il_meta_requirement " .
156 "WHERE meta_requirement_id = " . $ilDB->quote($this->getMetaId());
157
158 $this->db->query($query);
159
160 return true;
161 }
162 return false;
163 }
164
165
166 public function __getFields()
167 {
168 return array('rbac_id' => $this->getRBACId(),
169 'obj_id' => $this->getObjId(),
170 'obj_type' => ilUtil::prepareDBString($this->getObjType()),
171 'parent_type' => $this->getParentType(),
172 'parent_id' => $this->getParentId(),
173 'operating_system_name' => ilUtil::prepareDBString($this->getOperatingSystemName()),
174 'operating_system_minimum_version' => ilUtil::prepareDBString($this->getOperatingSystemMinimumVersion()),
175 'operating_system_maximum_version' => ilUtil::prepareDBString($this->getOperatingSystemMaximumVersion()),
176 'browser_name' => ilUtil::prepareDBString($this->getBrowserName()),
177 'browser_minimum_version' => ilUtil::prepareDBString($this->getBrowserMinimumVersion()),
178 'browser_maximum_version' => ilUtil::prepareDBString($this->getBrowserMaximumVersion()),
179 'or_composite_id' => $this->getOrCompositeId());
180 }
181
182 public function read()
183 {
184 global $ilDB;
185
186 include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDLanguageItem.php';
187
188 if ($this->getMetaId()) {
189 $query = "SELECT * FROM il_meta_requirement " .
190 "WHERE meta_requirement_id = " . $ilDB->quote($this->getMetaId());
191
192 $res = $this->db->query($query);
193 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
194 $this->setRBACId($row->rbac_id);
195 $this->setObjId($row->obj_id);
196 $this->setObjType($row->obj_type);
197 $this->setParentId($row->parent_id);
198 $this->setParentType($row->parent_type);
199 $this->setOperatingSystemName(ilUtil::stripSlashes($row->operating_system_name));
200 $this->setOperatingSystemMinimumVersion(ilUtil::stripSlashes($row->operating_system_minimum_version));
201 $this->setOperatingSystemMaximumVersion(ilUtil::stripSlashes($row->operating_system_maximum_version));
202 $this->setBrowserName(ilUtil::stripSlashes($row->browser_name));
203 $this->setBrowserMinimumVersion(ilUtil::stripSlashes($row->browser_minimum_version));
204 $this->setBrowserMaximumVersion(ilUtil::stripSlashes($row->browser_maximum_version));
205 $this->setOrCompositeId(ilUtil::stripSlashes($row->or_composite_id));
206 }
207 }
208 return true;
209 }
210
211 /*
212 * XML Export of all meta data
213 * @param object (xml writer) see class.ilMD2XML.php
214 *
215 */
216 public function toXML(&$writer)
217 {
218 $writer->xmlStartTag('Requirement');
219 $writer->xmlStartTag('Type');
220
221 if (strlen($this->getOperatingSystemName())) {
222 $writer->xmlElement('OperatingSystem', array('Name' => $this->getOperatingSystemName(),
223 'MinimumVersion' => $this->getOperatingSystemMinimumVersion(),
224 'MaximumVersion' => $this->getOperatingSystemMaximumVersion()));
225 } else {
226 $writer->xmlElement('Browser', array('Name' => $this->getBrowserName(),
227 'MinimumVersion' => $this->getBrowserMinimumVersion(),
228 'MaximumVersion' => $this->getBrowserMaximumVersion()));
229 }
230 $writer->xmlEndTag('Type');
231 $writer->xmlEndTag('Requirement');
232 }
233
234
235 // STATIC
236 public function _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type, $a_or_composite_id = 0)
237 {
238 global $ilDB;
239
240 $query = "SELECT meta_requirement_id FROM il_meta_requirement " .
241 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id) . " " .
242 "AND obj_id = " . $ilDB->quote($a_obj_id) . " " .
243 "AND parent_id = " . $ilDB->quote($a_parent_id) . " " .
244 "AND parent_type = " . $ilDB->quote($a_parent_type) . " " .
245 "AND or_composite_id = " . $ilDB->quote($a_or_composite_id);
246
247 $res = $ilDB->query($query);
248 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
249 $ids[] = $row->meta_requirement_id;
250 }
251 return $ids ? $ids : array();
252 }
253}
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)
setOperatingSystemMaximumVersion($a_val)
setOperatingSystemMinimumVersion($a_val)
_getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type, $a_or_composite_id=0)
static prepareDBString($a_str)
prepare a string for db writing (insert/update)
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
$query
foreach($_POST as $key=> $value) $res
global $ilDB