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