ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilMDTaxonPath.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 ilMDTaxonPath extends ilMDBase
34 {
35  // METHODS OF CHILD OBJECTS (Taxon)
36  public function &getTaxonIds()
37  {
38  include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDTaxon.php';
39 
40  return ilMDTaxon::_getIds($this->getRBACId(), $this->getObjId(), $this->getMetaId(), 'meta_taxon_path');
41  }
42  public function &getTaxon($a_taxon_id)
43  {
44  include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDTaxon.php';
45 
46  if (!$a_taxon_id) {
47  return false;
48  }
49  $tax = new ilMDTaxon();
50  $tax->setMetaId($a_taxon_id);
51 
52  return $tax;
53  }
54  public function &addTaxon()
55  {
56  include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDTaxon.php';
57 
58  $tax = new ilMDTaxon($this->getRBACId(), $this->getObjId(), $this->getObjType());
59  $tax->setParentId($this->getMetaId());
60  $tax->setParentType('meta_taxon_path');
61 
62  return $tax;
63  }
64 
65  // SET/GET
66  public function setSource($a_source)
67  {
68  $this->source = $a_source;
69  }
70  public function getSource()
71  {
72  return $this->source;
73  }
74  public function setSourceLanguage(&$lng_obj)
75  {
76  if (is_object($lng_obj)) {
77  $this->source_language = $lng_obj;
78  }
79  }
80  public function &getSourceLanguage()
81  {
82  return is_object($this->source_language) ? $this->source_language : false;
83  }
84  public function getSourceLanguageCode()
85  {
86  return is_object($this->source_language) ? $this->source_language->getLanguageCode() : false;
87  }
88 
89 
90  public function save()
91  {
92  if ($this->db->autoExecute(
93  'il_meta_taxon_path',
94  $this->__getFields(),
96  )) {
97  $this->setMetaId($this->db->getLastInsertId());
98 
99  return $this->getMetaId();
100  }
101  return false;
102  }
103 
104  public function update()
105  {
106  global $ilDB;
107 
108  if ($this->getMetaId()) {
109  if ($this->db->autoExecute(
110  'il_meta_taxon_path',
111  $this->__getFields(),
113  "meta_taxon_path_id = " . $ilDB->quote($this->getMetaId())
114  )) {
115  return true;
116  }
117  }
118  return false;
119  }
120 
121  public function delete()
122  {
123  global $ilDB;
124 
125  if ($this->getMetaId()) {
126  $query = "DELETE FROM il_meta_taxon_path " .
127  "WHERE meta_taxon_path_id = " . $ilDB->quote($this->getMetaId());
128 
129  $this->db->query($query);
130 
131  foreach ($this->getTaxonIds() as $id) {
132  $tax = $this->getTaxon($id);
133  $tax->delete();
134  }
135 
136  return true;
137  }
138  return false;
139  }
140 
141 
142  public function __getFields()
143  {
144  return array('rbac_id' => $this->getRBACId(),
145  'obj_id' => $this->getObjId(),
146  'obj_type' => ilUtil::prepareDBString($this->getObjType()),
147  'parent_type' => $this->getParentType(),
148  'parent_id' => $this->getParentId(),
149  'source' => ilUtil::prepareDBString($this->getSource()),
150  'source_language' => ilUtil::prepareDBString($this->getSourceLanguageCode()));
151  }
152 
153  public function read()
154  {
155  global $ilDB;
156 
157  include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDLanguageItem.php';
158 
159  if ($this->getMetaId()) {
160  $query = "SELECT * FROM il_meta_taxon_path " .
161  "WHERE meta_taxon_path_id = " . $ilDB->quote($this->getMetaId());
162 
163  $res = $this->db->query($query);
164  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
165  $this->setRBACId($row->rbac_id);
166  $this->setObjId($row->obj_id);
167  $this->setObjType($row->obj_type);
168  $this->setParentId($row->parent_id);
169  $this->setParentType($row->parent_type);
170  $this->setSource(ilUtil::stripSlashes($row->source));
171  $this->source_language = new ilMDLanguageItem($row->source_language);
172  }
173  }
174  return true;
175  }
176 
177  /*
178  * XML Export of all meta data
179  * @param object (xml writer) see class.ilMD2XML.php
180  *
181  */
182  public function toXML(&$writer)
183  {
184  $writer->xmlStartTag('TaxonPath');
185 
186  $writer->xmlElement('Source', array('Language' => $this->getSourceLanguageCode()), $this->getSource());
187 
188  // Taxon
189  foreach ($this->getTaxonIds() as $id) {
190  $tax =&$this->getTaxon($id);
191  $tax->toXML($writer);
192  }
193 
194  $writer->xmlEndTag('TaxonPath');
195  }
196 
197 
198 
199  // STATIC
200  public function _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
201  {
202  global $ilDB;
203 
204  $query = "SELECT meta_taxon_path_id FROM il_meta_taxon_path " .
205  "WHERE rbac_id = " . $ilDB->quote($a_rbac_id) . " " .
206  "AND obj_id = " . $ilDB->quote($a_obj_id) . " " .
207  "AND parent_id = " . $ilDB->quote($a_parent_id) . " " .
208  "AND parent_type = " . $ilDB->quote($a_parent_type);
209 
210  $res = $ilDB->query($query);
211  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
212  $ids[] = $row->meta_taxon_path_id;
213  }
214  return $ids ? $ids : array();
215  }
216 }
setObjType($a_type)
if(!array_key_exists('StateId', $_REQUEST)) $id
& getTaxon($a_taxon_id)
setMetaId($a_meta_id, $a_read_data=true)
foreach($_POST as $key=> $value) $res
setObjId($a_id)
setRBACId($a_id)
$query
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
Create styles array
The data for the language used.
setParentId($a_id)
setSourceLanguage(&$lng_obj)
static _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
static prepareDBString($a_str)
prepare a string for db writing (insert/update)
global $ilDB
setParentType($a_parent_type)
$source
Definition: linkback.php:22
_getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)