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