ILIAS  release_7 Revision v7.30-3-g800a261c036
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 $DIC;
93
94 $ilDB = $DIC['ilDB'];
95
96 $fields = $this->__getFields();
97 $fields['meta_taxon_path_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_taxon_path'));
98
99 if ($this->db->insert('il_meta_taxon_path', $fields)) {
100 $this->setMetaId($next_id);
101 return $this->getMetaId();
102 }
103 return false;
104 }
105
106 public function update()
107 {
108 global $DIC;
109
110 $ilDB = $DIC['ilDB'];
111
112 if ($this->getMetaId()) {
113 if ($this->db->update(
114 'il_meta_taxon_path',
115 $this->__getFields(),
116 array("meta_taxon_path_id" => array('integer',$this->getMetaId()))
117 )) {
118 return true;
119 }
120 }
121 return false;
122 }
123
124 public function delete()
125 {
126 global $DIC;
127
128 $ilDB = $DIC['ilDB'];
129
130 if ($this->getMetaId()) {
131 $query = "DELETE FROM il_meta_taxon_path " .
132 "WHERE meta_taxon_path_id = " . $ilDB->quote($this->getMetaId(), 'integer');
133 $res = $ilDB->manipulate($query);
134
135 foreach ($this->getTaxonIds() as $id) {
136 $tax = $this->getTaxon($id);
137 $tax->delete();
138 }
139
140 return true;
141 }
142 return false;
143 }
144
145
146 public function __getFields()
147 {
148 return array('rbac_id' => array('integer',$this->getRBACId()),
149 'obj_id' => array('integer',$this->getObjId()),
150 'obj_type' => array('text',$this->getObjType()),
151 'parent_type' => array('text',$this->getParentType()),
152 'parent_id' => array('integer',$this->getParentId()),
153 'source' => array('text',$this->getSource()),
154 'source_language' => array('text',$this->getSourceLanguageCode()));
155 }
156
157 public function read()
158 {
159 global $DIC;
160
161 $ilDB = $DIC['ilDB'];
162
163 include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php';
164
165 if ($this->getMetaId()) {
166 $query = "SELECT * FROM il_meta_taxon_path " .
167 "WHERE meta_taxon_path_id = " . $ilDB->quote($this->getMetaId(), 'integer');
168
169 $res = $ilDB->query($query);
170 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
171 $this->setRBACId($row->rbac_id);
172 $this->setObjId($row->obj_id);
173 $this->setObjType($row->obj_type);
174 $this->setParentId($row->parent_id);
175 $this->setParentType($row->parent_type);
176 $this->setSource($row->source);
177 $this->source_language = new ilMDLanguageItem($row->source_language);
178 }
179 }
180 return true;
181 }
182
183 /*
184 * XML Export of all meta data
185 * @param object (xml writer) see class.ilMD2XML.php
186 *
187 */
188 public function toXML(&$writer)
189 {
190 $writer->xmlStartTag('TaxonPath');
191
192 $writer->xmlElement(
193 'Source',
194 array('Language' => $this->getSourceLanguageCode()
195 ? $this->getSourceLanguageCode()
196 : 'en'),
197 $this->getSource()
198 );
199
200 // Taxon
201 $taxs = $this->getTaxonIds();
202 foreach ($taxs as $id) {
203 $tax = &$this->getTaxon($id);
204 $tax->toXML($writer);
205 }
206 if (!count($taxs)) {
207 include_once 'Services/MetaData/classes/class.ilMDTaxon.php';
208 $tax = new ilMDTaxon($this->getRBACId(), $this->getObjId());
209 $tax->toXML($writer);
210 }
211
212 $writer->xmlEndTag('TaxonPath');
213 }
214
215
216
217 // STATIC
218 public static function _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
219 {
220 global $DIC;
221
222 $ilDB = $DIC['ilDB'];
223
224 $query = "SELECT meta_taxon_path_id FROM il_meta_taxon_path " .
225 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
226 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
227 "AND parent_id = " . $ilDB->quote($a_parent_id, 'integer') . " " .
228 "AND parent_type = " . $ilDB->quote($a_parent_type, 'text');
229
230 $res = $ilDB->query($query);
231 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
232 $ids[] = $row->meta_taxon_path_id;
233 }
234 return $ids ? $ids : array();
235 }
236}
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)
global $DIC
Definition: goto.php:24
$source
Definition: metadata.php:76
$query
foreach($_POST as $key=> $value) $res
global $ilDB