ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilMDTypicalAgeRange.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 function setTypicalAgeRange($a_typical_age_range)
37 {
38 $this->typical_age_range = $a_typical_age_range;
39 }
41 {
42 return $this->typical_age_range;
43 }
44 function setTypicalAgeRangeLanguage(&$lng_obj)
45 {
46 if(is_object($lng_obj))
47 {
48 $this->typical_age_range_language = $lng_obj;
49 }
50 }
52 {
53 return is_object($this->typical_age_range_language) ? $this->typical_age_range_language : false;
54 }
56 {
57 return is_object($this->typical_age_range_language) ? $this->typical_age_range_language->getLanguageCode() : false;
58 }
59
61 {
62 $this->typical_age_range_minimum = $a_min;
63 }
65 {
66 return $this->typical_age_range_minimum;
67 }
69 {
70 $this->typical_age_range_maximum = $a_max;
71 }
73 {
74 return $this->typical_age_range_maximum;
75 }
76
77
78 function save()
79 {
80 global $ilDB;
81
82 $fields = $this->__getFields();
83 $fields['meta_tar_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_tar'));
84
85 if($this->db->insert('il_meta_tar',$fields))
86 {
87 $this->setMetaId($next_id);
88 return $this->getMetaId();
89 }
90 return false;
91 }
92
93 function update()
94 {
95 global $ilDB;
96
98 if($this->getMetaId())
99 {
100 if($this->db->update('il_meta_tar',
101 $this->__getFields(),
102 array("meta_tar_id" => array('integer',$this->getMetaId()))))
103 {
104 return true;
105 }
106 }
107 return false;
108 }
109
110 function delete()
111 {
112 global $ilDB;
113
114 if($this->getMetaId())
115 {
116 $query = "DELETE FROM il_meta_tar ".
117 "WHERE meta_tar_id = ".$ilDB->quote($this->getMetaId() ,'integer');
118 $res = $ilDB->manipulate($query);
119 return true;
120 }
121 return false;
122 }
123
124
125 function __getFields()
126 {
127 return array('rbac_id' => array('integer',$this->getRBACId()),
128 'obj_id' => array('integer',$this->getObjId()),
129 'obj_type' => array('text',$this->getObjType()),
130 'parent_type' => array('text',$this->getParentType()),
131 'parent_id' => array('integer',$this->getParentId()),
132 'typical_age_range' => array('text',$this->getTypicalAgeRange()),
133 'tar_language' => array('text',$this->getTypicalAgeRangeLanguageCode()),
134 'tar_min' => array('text',$this->getTypicalAgeRangeMinimum()),
135 'tar_max' => array('text',$this->getTypicalAgeRangeMaximum()));
136 }
137
138 function read()
139 {
140 global $ilDB;
141
142 include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php';
143
144 if($this->getMetaId())
145 {
146 $query = "SELECT * FROM il_meta_tar ".
147 "WHERE meta_tar_id = ".$ilDB->quote($this->getMetaId() ,'integer');
148
149 $res = $ilDB->query($query);
150 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
151 {
152 $this->setRBACId($row->rbac_id);
153 $this->setObjId($row->obj_id);
154 $this->setObjType($row->obj_type);
155 $this->setParentId($row->parent_id);
156 $this->setParentType($row->parent_type);
157 $this->setTypicalAgeRange($row->typical_age_range);
158 $this->setTypicalAgeRangeLanguage(new ilMDLanguageItem($row->tar_language));
159 $this->setTypicalAgeRangeMinimum($row->tar_min);
160 $this->setTypicalAgeRangeMaximum($row->tar_max);
161 }
162 }
163 return true;
164 }
165
166 /*
167 * XML Export of all meta data
168 * @param object (xml writer) see class.ilMD2XML.php
169 *
170 */
171 function toXML(&$writer)
172 {
173 $writer->xmlElement('TypicalAgeRange',array('Language' => $this->getTypicalAgeRangeLanguageCode()
175 : 'en'),
176 $this->getTypicalAgeRange());
177 }
178
179
180 // STATIC
181 static function _getIds($a_rbac_id,$a_obj_id,$a_parent_id,$a_parent_type)
182 {
183 global $ilDB;
184
185 $query = "SELECT meta_tar_id FROM il_meta_tar ".
186 "WHERE rbac_id = ".$ilDB->quote($a_rbac_id ,'integer')." ".
187 "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ".
188 "AND parent_id = ".$ilDB->quote($a_parent_id ,'integer')." ".
189 "AND parent_type = ".$ilDB->quote($a_parent_type ,'text');
190
191 $res = $ilDB->query($query);
192 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
193 {
194 $ids[] = $row->meta_tar_id;
195 }
196 return $ids ? $ids : array();
197 }
198
199 // PRIVATE
201 {
202 if(preg_match("/\s*(\d*)\s*(-?)\s*(\d*)/",$this->getTypicalAgeRange(),$matches))
203 {
204 if(!$matches[2] and !$matches[3])
205 {
206 $min = $max = $matches[1];
207 }
208 elseif($matches[2] and !$matches[3])
209 {
210 $min = $matches[1];
211 $max = 99;
212 }
213 else
214 {
215 $min = $matches[1];
216 $max = $matches[3];
217 }
218 $this->setTypicalAgeRangeMaximum($max);
219 $this->setTypicalAgeRangeMinimum($min);
220
221 return true;
222 }
223
224 if(!$this->getTypicalAgeRange())
225 {
226 $this->setTypicalAgeRangeMinimum(-1);
227 $this->setTypicalAgeRangeMaximum(-1);
228 }
229 return true;
230 }
231
232}
233?>
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)
setTypicalAgeRange($a_typical_age_range)
static _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
global $ilDB