ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilMDTaxon.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 
33 class ilMDTaxon extends ilMDBase
34 {
35  // SET/GET
36  public function setTaxon($a_taxon)
37  {
38  $this->taxon = $a_taxon;
39  }
40  public function getTaxon()
41  {
42  return $this->taxon;
43  }
44  public function setTaxonLanguage(&$lng_obj)
45  {
46  if (is_object($lng_obj)) {
47  $this->taxon_language = $lng_obj;
48  }
49  }
50  public function &getTaxonLanguage()
51  {
52  return is_object($this->taxon_language) ? $this->taxon_language : false;
53  }
54  public function getTaxonLanguageCode()
55  {
56  return is_object($this->taxon_language) ? $this->taxon_language->getLanguageCode() : false;
57  }
58  public function setTaxonId($a_taxon_id)
59  {
60  $this->taxon_id = $a_taxon_id;
61  }
62  public function getTaxonId()
63  {
64  return $this->taxon_id;
65  }
66 
67 
68  public function save()
69  {
70  global $ilDB;
71 
72  $fields = $this->__getFields();
73  $fields['meta_taxon_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_taxon'));
74 
75  if ($this->db->insert('il_meta_taxon', $fields)) {
76  $this->setMetaId($next_id);
77  return $this->getMetaId();
78  }
79  return false;
80  }
81 
82  public function update()
83  {
84  global $ilDB;
85 
86  if ($this->getMetaId()) {
87  if ($this->db->update(
88  'il_meta_taxon',
89  $this->__getFields(),
90  array("meta_taxon_id" => array('integer',$this->getMetaId()))
91  )) {
92  return true;
93  }
94  }
95  return false;
96  }
97 
98  public function delete()
99  {
100  global $ilDB;
101 
102  if ($this->getMetaId()) {
103  $query = "DELETE FROM il_meta_taxon " .
104  "WHERE meta_taxon_id = " . $ilDB->quote($this->getMetaId(), 'integer');
105 
106  $this->db->query($query);
107 
108  return true;
109  }
110  return false;
111  }
112 
113 
114  public function __getFields()
115  {
116  return array('rbac_id' => array('integer',$this->getRBACId()),
117  'obj_id' => array('integer',$this->getObjId()),
118  'obj_type' => array('text',$this->getObjType()),
119  'parent_type' => array('text',$this->getParentType()),
120  'parent_id' => array('integer',$this->getParentId()),
121  'taxon' => array('text',$this->getTaxon()),
122  'taxon_language' => array('text',$this->getTaxonLanguageCode()),
123  'taxon_id' => array('text',$this->getTaxonId()));
124  }
125 
126  public function read()
127  {
128  global $ilDB;
129 
130  include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php';
131 
132  if ($this->getMetaId()) {
133  $query = "SELECT * FROM il_meta_taxon " .
134  "WHERE meta_taxon_id = " . $ilDB->quote($this->getMetaId(), 'integer');
135 
136  $res = $this->db->query($query);
137  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
138  $this->setRBACId($row->rbac_id);
139  $this->setObjId($row->obj_id);
140  $this->setObjType($row->obj_type);
141  $this->setParentId($row->parent_id);
142  $this->setParentType($row->parent_type);
143  $this->setTaxon($row->taxon);
144  $this->taxon_language = new ilMDLanguageItem($row->taxon_language);
145  $this->setTaxonId($row->taxon_id);
146  }
147  }
148  return true;
149  }
150 
151  /*
152  * XML Export of all meta data
153  * @param object (xml writer) see class.ilMD2XML.php
154  *
155  */
156  public function toXML(&$writer)
157  {
158  $random = new \ilRandom();
159  $writer->xmlElement(
160  'Taxon',
161  array('Language' => $this->getTaxonLanguageCode()
162  ? $this->getTaxonLanguageCode()
163  : 'en',
164  'Id' => $this->getTaxonId() ?
165  $this->getTaxonId() : ("ID" . $random->int())),
166  $this->getTaxon()
167  );
168  }
169 
170 
171  // STATIC
172  public static function _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
173  {
174  global $ilDB;
175 
176  $query = "SELECT meta_taxon_id FROM il_meta_taxon " .
177  "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
178  "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
179  "AND parent_id = " . $ilDB->quote($a_parent_id, 'integer') . " " .
180  "AND parent_type = " . $ilDB->quote($a_parent_type, 'text');
181 
182 
183  $res = $ilDB->query($query);
184  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
185  $ids[] = $row->meta_taxon_id;
186  }
187  return $ids ? $ids : array();
188  }
189 }
setObjType($a_type)
setTaxonLanguage(&$lng_obj)
setTaxon($a_taxon)
setTaxonId($a_taxon_id)
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.
setParentId($a_id)
toXML(&$writer)
static _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
global $ilDB
setParentType($a_parent_type)
& getTaxonLanguage()