ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 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 function &getTaxon($a_taxon_id)
43 {
44 include_once 'Services/MetaData/classes/class.ilMDTaxon.php';
45
46 if(!$a_taxon_id)
47 {
48 return false;
49 }
50 $tax = new ilMDTaxon();
51 $tax->setMetaId($a_taxon_id);
52
53 return $tax;
54 }
55 function &addTaxon()
56 {
57 include_once 'Services/MetaData/classes/class.ilMDTaxon.php';
58
59 $tax = new ilMDTaxon($this->getRBACId(),$this->getObjId(),$this->getObjType());
60 $tax->setParentId($this->getMetaId());
61 $tax->setParentType('meta_taxon_path');
62
63 return $tax;
64 }
65
66 // SET/GET
67 function setSource($a_source)
68 {
69 $this->source = $a_source;
70 }
71 function getSource()
72 {
73 return $this->source;
74 }
75 function setSourceLanguage(&$lng_obj)
76 {
77 if(is_object($lng_obj))
78 {
79 $this->source_language = $lng_obj;
80 }
81 }
83 {
84 return is_object($this->source_language) ? $this->source_language : false;
85 }
87 {
88 return is_object($this->source_language) ? $this->source_language->getLanguageCode() : false;
89 }
90
91
92 function save()
93 {
94 global $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 {
101 $this->setMetaId($next_id);
102 return $this->getMetaId();
103 }
104 return false;
105 }
106
107 function update()
108 {
109 global $ilDB;
110
111 if($this->getMetaId())
112 {
113 if($this->db->update('il_meta_taxon_path',
114 $this->__getFields(),
115 array("meta_taxon_path_id" => array('integer',$this->getMetaId()))))
116 {
117 return true;
118 }
119 }
120 return false;
121 }
122
123 function delete()
124 {
125 global $ilDB;
126
127 if($this->getMetaId())
128 {
129 $query = "DELETE FROM il_meta_taxon_path ".
130 "WHERE meta_taxon_path_id = ".$ilDB->quote($this->getMetaId(), 'integer');
131 $res = $ilDB->manipulate($query);
132
133 foreach($this->getTaxonIds() as $id)
134 {
135 $tax = $this->getTaxon($id);
136 $tax->delete();
137 }
138
139 return true;
140 }
141 return false;
142 }
143
144
145 function __getFields()
146 {
147 return array('rbac_id' => array('integer',$this->getRBACId()),
148 'obj_id' => array('integer',$this->getObjId()),
149 'obj_type' => array('text',$this->getObjType()),
150 'parent_type' => array('text',$this->getParentType()),
151 'parent_id' => array('integer',$this->getParentId()),
152 'source' => array('text',$this->getSource()),
153 'source_language' => array('text',$this->getSourceLanguageCode()));
154 }
155
156 function read()
157 {
158 global $ilDB;
159
160 include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php';
161
162 if($this->getMetaId())
163 {
164 $query = "SELECT * FROM il_meta_taxon_path ".
165 "WHERE meta_taxon_path_id = ".$ilDB->quote($this->getMetaId() ,'integer');
166
167 $res = $ilDB->query($query);
168 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
169 {
170 $this->setRBACId($row->rbac_id);
171 $this->setObjId($row->obj_id);
172 $this->setObjType($row->obj_type);
173 $this->setParentId($row->parent_id);
174 $this->setParentType($row->parent_type);
175 $this->setSource($row->source);
176 $this->source_language = new ilMDLanguageItem($row->source_language);
177 }
178 }
179 return true;
180 }
181
182 /*
183 * XML Export of all meta data
184 * @param object (xml writer) see class.ilMD2XML.php
185 *
186 */
187 function toXML(&$writer)
188 {
189 $writer->xmlStartTag('TaxonPath');
190
191 $writer->xmlElement('Source',array('Language' => $this->getSourceLanguageCode()
192 ? $this->getSourceLanguageCode()
193 : 'en'),
194 $this->getSource());
195
196 // Taxon
197 $taxs = $this->getTaxonIds();
198 foreach($taxs as $id)
199 {
200 $tax =& $this->getTaxon($id);
201 $tax->toXML($writer);
202 }
203 if(!count($taxs))
204 {
205 include_once 'Services/MetaData/classes/class.ilMDTaxon.php';
206 $tax = new ilMDTaxon($this->getRBACId(),$this->getObjId());
207 $tax->toXML($writer);
208 }
209
210 $writer->xmlEndTag('TaxonPath');
211 }
212
213
214
215 // STATIC
216 static function _getIds($a_rbac_id,$a_obj_id,$a_parent_id,$a_parent_type)
217 {
218 global $ilDB;
219
220 $query = "SELECT meta_taxon_path_id FROM il_meta_taxon_path ".
221 "WHERE rbac_id = ".$ilDB->quote($a_rbac_id ,'integer')." ".
222 "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ".
223 "AND parent_id = ".$ilDB->quote($a_parent_id ,'integer')." ".
224 "AND parent_type = ".$ilDB->quote($a_parent_type ,'text');
225
226 $res = $ilDB->query($query);
227 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
228 {
229 $ids[] = $row->meta_taxon_path_id;
230 }
231 return $ids ? $ids : array();
232 }
233}
234?>
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 $ilDB