ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilMDClassification.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  // METHODS OF CLIENT OBJECTS (TaxonPath, Keyword)
36  public function &getTaxonPathIds()
37  {
38  include_once 'Services/MetaData/classes/class.ilMDTaxonPath.php';
39 
40  return ilMDTaxonPath::_getIds($this->getRBACId(), $this->getObjId(), $this->getMetaId(), 'meta_classification');
41  }
42  public function &getTaxonPath($a_taxon_path_id)
43  {
44  include_once 'Services/MetaData/classes/class.ilMDTaxonPath.php';
45 
46  if (!$a_taxon_path_id) {
47  return false;
48  }
49  $tax = new ilMDTaxonPath();
50  $tax->setMetaId($a_taxon_path_id);
51 
52  return $tax;
53  }
54  public function &addTaxonPath()
55  {
56  include_once 'Services/MetaData/classes/class.ilMDTaxonPath.php';
57 
58  $tax = new ilMDTaxonPath($this->getRBACId(), $this->getObjId(), $this->getObjType());
59  $tax->setParentId($this->getMetaId());
60  $tax->setParentType('meta_classification');
61 
62  return $tax;
63  }
64 
65  public function &getKeywordIds()
66  {
67  include_once 'Services/MetaData/classes/class.ilMDKeyword.php';
68 
69  return ilMDKeyword::_getIds($this->getRBACId(), $this->getObjId(), $this->getMetaId(), 'meta_classification');
70  }
71  public function &getKeyword($a_keyword_id)
72  {
73  include_once 'Services/MetaData/classes/class.ilMDKeyword.php';
74 
75  if (!$a_keyword_id) {
76  return false;
77  }
78  $key = new ilMDKeyword();
79  $key->setMetaId($a_keyword_id);
80 
81  return $key;
82  }
83  public function &addKeyword()
84  {
85  include_once 'Services/MetaData/classes/class.ilMDKeyword.php';
86 
87  $key = new ilMDKeyword($this->getRBACId(), $this->getObjId(), $this->getObjType());
88  $key->setParentId($this->getMetaId());
89  $key->setParentType('meta_classification');
90 
91  return $key;
92  }
93 
94  // SET/GET
95  public function setPurpose($a_purpose)
96  {
97  switch ($a_purpose) {
98  case 'Discipline':
99  case 'Idea':
100  case 'Prerequisite':
101  case 'EducationalObjective':
102  case 'AccessibilityRestrictions':
103  case 'EducationalLevel':
104  case 'SkillLevel':
105  case 'SecurityLevel':
106  case 'Competency':
107  $this->purpose = $a_purpose;
108  return true;
109 
110  default:
111  return false;
112  }
113  }
114  public function getPurpose()
115  {
116  return $this->purpose;
117  }
118  public function setDescription($a_description)
119  {
120  $this->description = $a_description;
121  }
122  public function getDescription()
123  {
124  return $this->description;
125  }
126  public function setDescriptionLanguage(&$lng_obj)
127  {
128  if (is_object($lng_obj)) {
129  $this->description_language = $lng_obj;
130  }
131  }
132  public function &getDescriptionLanguage()
133  {
134  return is_object($this->description_language) ? $this->description_language : false;
135  }
136  public function getDescriptionLanguageCode()
137  {
138  return is_object($this->description_language) ? $this->description_language->getLanguageCode() : false;
139  }
140 
141 
142  public function save()
143  {
144  global $DIC;
145 
146  $ilDB = $DIC['ilDB'];
147 
148  $fields = $this->__getFields();
149  $fields['meta_classification_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_classification'));
150 
151  if ($this->db->insert('il_meta_classification', $fields)) {
152  $this->setMetaId($next_id);
153  return $this->getMetaId();
154  }
155  return false;
156  }
157 
158  public function update()
159  {
160  global $DIC;
161 
162  $ilDB = $DIC['ilDB'];
163 
164  if ($this->getMetaId()) {
165  if ($this->db->update(
166  'il_meta_classification',
167  $this->__getFields(),
168  array("meta_classification_id" => array('integer',$this->getMetaId()))
169  )) {
170  return true;
171  }
172  }
173  return false;
174  }
175 
176  public function delete()
177  {
178  global $DIC;
179 
180  $ilDB = $DIC['ilDB'];
181 
182  if ($this->getMetaId()) {
183  $query = "DELETE FROM il_meta_classification " .
184  "WHERE meta_classification_id = " . $ilDB->quote($this->getMetaId(), 'integer');
185  $res = $ilDB->manipulate($query);
186 
187  foreach ($this->getTaxonPathIds() as $id) {
188  $tax = $this->getTaxonPath($id);
189  $tax->delete();
190  }
191  foreach ($this->getKeywordIds() as $id) {
192  $key = $this->getKeyword($id);
193  $key->delete();
194  }
195 
196  return true;
197  }
198  return false;
199  }
200 
201 
202  public function __getFields()
203  {
204  return array('rbac_id' => array('integer',$this->getRBACId()),
205  'obj_id' => array('integer',$this->getObjId()),
206  'obj_type' => array('text',$this->getObjType()),
207  'purpose' => array('text',$this->getPurpose()),
208  'description' => array('text',$this->getDescription()),
209  'description_language' => array('text',$this->getDescriptionLanguageCode()));
210  }
211 
212  public function read()
213  {
214  global $DIC;
215 
216  $ilDB = $DIC['ilDB'];
217 
218  include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php';
219 
220  if ($this->getMetaId()) {
221  $query = "SELECT * FROM il_meta_classification " .
222  "WHERE meta_classification_id = " . $ilDB->quote($this->getMetaId(), 'integer');
223 
224  $res = $this->db->query($query);
225  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
226  $this->setRBACId($row->rbac_id);
227  $this->setObjId($row->obj_id);
228  $this->setObjType($row->obj_type);
229  $this->setPurpose($row->purpose);
230  $this->setDescription($row->description);
231  $this->description_language = new ilMDLanguageItem($row->description_language);
232  }
233  }
234  return true;
235  }
236 
237  /*
238  * XML Export of all meta data
239  * @param object (xml writer) see class.ilMD2XML.php
240  *
241  */
242  public function toXML(&$writer)
243  {
244  $writer->xmlStartTag('Classification', array('Purpose' => $this->getPurpose()
245  ? $this->getPurpose()
246  : 'Idea'));
247 
248  // Taxon Path
249  $taxs = $this->getTaxonPathIds();
250  foreach ($taxs as $id) {
251  $tax = &$this->getTaxonPath($id);
252  $tax->toXML($writer);
253  }
254  if (!count($taxs)) {
255  include_once 'Services/MetaData/classes/class.ilMDTaxonPath.php';
256  $tax = new ilMDTaxonPath($this->getRBACId(), $this->getObjId());
257  $tax->toXML($writer);
258  }
259 
260  // Description
261  $writer->xmlElement(
262  'Description',
263  array('Language' => $this->getDescriptionLanguageCode()
264  ? $this->getDescriptionLanguageCode()
265  : 'en'),
266  $this->getDescription()
267  );
268 
269  // Keyword
270  $keys = $this->getKeywordIds();
271  foreach ($keys as $id) {
272  $key = &$this->getKeyword($id);
273  $key->toXML($writer);
274  }
275  if (!count($keys)) {
276  include_once 'Services/MetaData/classes/class.ilMDKeyword.php';
277  $key = new ilMDKeyword($this->getRBACId(), $this->getObjId());
278  $key->toXML($writer);
279  }
280  $writer->xmlEndTag('Classification');
281  }
282 
283 
284 
285  // STATIC
286  public static function _getIds($a_rbac_id, $a_obj_id)
287  {
288  global $DIC;
289 
290  $ilDB = $DIC['ilDB'];
291 
292  $query = "SELECT meta_classification_id FROM il_meta_classification " .
293  "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
294  "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer');
295 
296 
297  $res = $ilDB->query($query);
298  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
299  $ids[] = $row->meta_classification_id;
300  }
301  return $ids ? $ids : array();
302  }
303 }
setObjType($a_type)
global $DIC
Definition: saml.php:7
static _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
if(!array_key_exists('StateId', $_REQUEST)) $id
static _getIds($a_rbac_id, $a_obj_id)
$keys
setMetaId($a_meta_id, $a_read_data=true)
foreach($_POST as $key=> $value) $res
setObjId($a_id)
setRBACId($a_id)
$query
$row
static _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
global $ilDB
$key
Definition: croninfo.php:18
& getTaxonPath($a_taxon_path_id)