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
31include_once 'class.ilMDBase.php';
32
34{
35 // METHODS OF CHILD OBJECTS (Taxon)
36 public function &getTaxonIds()
37 {
38 include_once 'Services/MetaData/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/MetaData/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/MetaData/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 global $ilDB;
93
94 $fields = $this->__getFields();
95 $fields['meta_taxon_path_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_taxon_path'));
96
97 if ($this->db->insert('il_meta_taxon_path', $fields)) {
98 $this->setMetaId($next_id);
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->update(
110 'il_meta_taxon_path',
111 $this->__getFields(),
112 array("meta_taxon_path_id" => array('integer',$this->getMetaId()))
113 )) {
114 return true;
115 }
116 }
117 return false;
118 }
119
120 public function delete()
121 {
122 global $ilDB;
123
124 if ($this->getMetaId()) {
125 $query = "DELETE FROM il_meta_taxon_path " .
126 "WHERE meta_taxon_path_id = " . $ilDB->quote($this->getMetaId(), 'integer');
127 $res = $ilDB->manipulate($query);
128
129 foreach ($this->getTaxonIds() as $id) {
130 $tax = $this->getTaxon($id);
131 $tax->delete();
132 }
133
134 return true;
135 }
136 return false;
137 }
138
139
140 public function __getFields()
141 {
142 return array('rbac_id' => array('integer',$this->getRBACId()),
143 'obj_id' => array('integer',$this->getObjId()),
144 'obj_type' => array('text',$this->getObjType()),
145 'parent_type' => array('text',$this->getParentType()),
146 'parent_id' => array('integer',$this->getParentId()),
147 'source' => array('text',$this->getSource()),
148 'source_language' => array('text',$this->getSourceLanguageCode()));
149 }
150
151 public function read()
152 {
153 global $ilDB;
154
155 include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php';
156
157 if ($this->getMetaId()) {
158 $query = "SELECT * FROM il_meta_taxon_path " .
159 "WHERE meta_taxon_path_id = " . $ilDB->quote($this->getMetaId(), 'integer');
160
161 $res = $ilDB->query($query);
162 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
163 $this->setRBACId($row->rbac_id);
164 $this->setObjId($row->obj_id);
165 $this->setObjType($row->obj_type);
166 $this->setParentId($row->parent_id);
167 $this->setParentType($row->parent_type);
168 $this->setSource($row->source);
169 $this->source_language = new ilMDLanguageItem($row->source_language);
170 }
171 }
172 return true;
173 }
174
175 /*
176 * XML Export of all meta data
177 * @param object (xml writer) see class.ilMD2XML.php
178 *
179 */
180 public function toXML(&$writer)
181 {
182 $writer->xmlStartTag('TaxonPath');
183
184 $writer->xmlElement(
185 'Source',
186 array('Language' => $this->getSourceLanguageCode()
187 ? $this->getSourceLanguageCode()
188 : 'en'),
189 $this->getSource()
190 );
191
192 // Taxon
193 $taxs = $this->getTaxonIds();
194 foreach ($taxs as $id) {
195 $tax =&$this->getTaxon($id);
196 $tax->toXML($writer);
197 }
198 if (!count($taxs)) {
199 include_once 'Services/MetaData/classes/class.ilMDTaxon.php';
200 $tax = new ilMDTaxon($this->getRBACId(), $this->getObjId());
201 $tax->toXML($writer);
202 }
203
204 $writer->xmlEndTag('TaxonPath');
205 }
206
207
208
209 // STATIC
210 public static function _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
211 {
212 global $ilDB;
213
214 $query = "SELECT meta_taxon_path_id FROM il_meta_taxon_path " .
215 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
216 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
217 "AND parent_id = " . $ilDB->quote($a_parent_id, 'integer') . " " .
218 "AND parent_type = " . $ilDB->quote($a_parent_type, 'text');
219
220 $res = $ilDB->query($query);
221 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
222 $ids[] = $row->meta_taxon_path_id;
223 }
224 return $ids ? $ids : array();
225 }
226}
$source
Definition: linkback.php:22
An exception for terminatinating execution or to throw for unit testing.
setObjId($a_id)
setParentId($a_id)
setMetaId($a_meta_id, $a_read_data=true)
setObjType($a_type)
setRBACId($a_id)
setParentType($a_parent_type)
& getTaxon($a_taxon_id)
setSourceLanguage(&$lng_obj)
static _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
static _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
if(!array_key_exists('StateId', $_REQUEST)) $id
$query
foreach($_POST as $key=> $value) $res
global $ilDB