ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $ilDB;
145 
146  $fields = $this->__getFields();
147  $fields['meta_classification_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_classification'));
148 
149  if ($this->db->insert('il_meta_classification', $fields)) {
150  $this->setMetaId($next_id);
151  return $this->getMetaId();
152  }
153  return false;
154  }
155 
156  public function update()
157  {
158  global $ilDB;
159 
160  if ($this->getMetaId()) {
161  if ($this->db->update(
162  'il_meta_classification',
163  $this->__getFields(),
164  array("meta_classification_id" => array('integer',$this->getMetaId()))
165  )) {
166  return true;
167  }
168  }
169  return false;
170  }
171 
172  public function delete()
173  {
174  global $ilDB;
175 
176  if ($this->getMetaId()) {
177  $query = "DELETE FROM il_meta_classification " .
178  "WHERE meta_classification_id = " . $ilDB->quote($this->getMetaId(), 'integer');
179  $res = $ilDB->manipulate($query);
180 
181  foreach ($this->getTaxonPathIds() as $id) {
182  $tax = $this->getTaxonPath($id);
183  $tax->delete();
184  }
185  foreach ($this->getKeywordIds() as $id) {
186  $key = $this->getKeyword($id);
187  $key->delete();
188  }
189 
190  return true;
191  }
192  return false;
193  }
194 
195 
196  public function __getFields()
197  {
198  return array('rbac_id' => array('integer',$this->getRBACId()),
199  'obj_id' => array('integer',$this->getObjId()),
200  'obj_type' => array('text',$this->getObjType()),
201  'purpose' => array('text',$this->getPurpose()),
202  'description' => array('text',$this->getDescription()),
203  'description_language' => array('text',$this->getDescriptionLanguageCode()));
204  }
205 
206  public function read()
207  {
208  global $ilDB;
209 
210  include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php';
211 
212  if ($this->getMetaId()) {
213  $query = "SELECT * FROM il_meta_classification " .
214  "WHERE meta_classification_id = " . $ilDB->quote($this->getMetaId(), 'integer');
215 
216  $res = $this->db->query($query);
217  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
218  $this->setRBACId($row->rbac_id);
219  $this->setObjId($row->obj_id);
220  $this->setObjType($row->obj_type);
221  $this->setPurpose($row->purpose);
222  $this->setDescription($row->description);
223  $this->description_language = new ilMDLanguageItem($row->description_language);
224  }
225  }
226  return true;
227  }
228 
229  /*
230  * XML Export of all meta data
231  * @param object (xml writer) see class.ilMD2XML.php
232  *
233  */
234  public function toXML(&$writer)
235  {
236  $writer->xmlStartTag('Classification', array('Purpose' => $this->getPurpose()
237  ? $this->getPurpose()
238  : 'Idea'));
239 
240  // Taxon Path
241  $taxs = $this->getTaxonPathIds();
242  foreach ($taxs as $id) {
243  $tax =&$this->getTaxonPath($id);
244  $tax->toXML($writer);
245  }
246  if (!count($taxs)) {
247  include_once 'Services/MetaData/classes/class.ilMDTaxonPath.php';
248  $tax = new ilMDTaxonPath($this->getRBACId(), $this->getObjId());
249  $tax->toXML($writer);
250  }
251 
252  // Description
253  $writer->xmlElement(
254  'Description',
255  array('Language' => $this->getDescriptionLanguageCode()
256  ? $this->getDescriptionLanguageCode()
257  : 'en'),
258  $this->getDescription()
259  );
260 
261  // Keyword
262  $keys = $this->getKeywordIds();
263  foreach ($keys as $id) {
264  $key =&$this->getKeyword($id);
265  $key->toXML($writer);
266  }
267  if (!count($keys)) {
268  include_once 'Services/MetaData/classes/class.ilMDKeyword.php';
269  $key = new ilMDKeyword($this->getRBACId(), $this->getObjId());
270  $key->toXML($writer);
271  }
272  $writer->xmlEndTag('Classification');
273  }
274 
275 
276 
277  // STATIC
278  public static function _getIds($a_rbac_id, $a_obj_id)
279  {
280  global $ilDB;
281 
282  $query = "SELECT meta_classification_id FROM il_meta_classification " .
283  "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
284  "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer');
285 
286 
287  $res = $ilDB->query($query);
288  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
289  $ids[] = $row->meta_classification_id;
290  }
291  return $ids ? $ids : array();
292  }
293 }
setObjType($a_type)
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
Create styles array
The data for the language used.
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)