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