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