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
33class ilMDTaxonPath extends ilMDBase
34{
35 // METHODS OF CHILD OBJECTS (Taxon)
36 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 function &getTaxon($a_taxon_id)
43 {
44 include_once 'Services/Migration/DBUpdate_426/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/Migration/DBUpdate_426/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 if($this->db->autoExecute('il_meta_taxon_path',
95 $this->__getFields(),
97 {
98 $this->setMetaId($this->db->getLastInsertId());
99
100 return $this->getMetaId();
101 }
102 return false;
103 }
104
105 function update()
106 {
107 global $ilDB;
108
109 if($this->getMetaId())
110 {
111 if($this->db->autoExecute('il_meta_taxon_path',
112 $this->__getFields(),
114 "meta_taxon_path_id = ".$ilDB->quote($this->getMetaId())))
115 {
116 return true;
117 }
118 }
119 return false;
120 }
121
122 function delete()
123 {
124 global $ilDB;
125
126 if($this->getMetaId())
127 {
128 $query = "DELETE FROM il_meta_taxon_path ".
129 "WHERE meta_taxon_path_id = ".$ilDB->quote($this->getMetaId());
130
131 $this->db->query($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' => $this->getRBACId(),
148 'obj_id' => $this->getObjId(),
149 'obj_type' => ilUtil::prepareDBString($this->getObjType()),
150 'parent_type' => $this->getParentType(),
151 'parent_id' => $this->getParentId(),
152 'source' => ilUtil::prepareDBString($this->getSource()),
153 'source_language' => ilUtil::prepareDBString($this->getSourceLanguageCode()));
154 }
155
156 function read()
157 {
158 global $ilDB;
159
160 include_once 'Services/Migration/DBUpdate_426/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());
166
167 $res = $this->db->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(ilUtil::stripSlashes($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()),$this->getSource());
192
193 // Taxon
194 foreach($this->getTaxonIds() as $id)
195 {
196 $tax =& $this->getTaxon($id);
197 $tax->toXML($writer);
198 }
199
200 $writer->xmlEndTag('TaxonPath');
201 }
202
203
204
205 // STATIC
206 function _getIds($a_rbac_id,$a_obj_id,$a_parent_id,$a_parent_type)
207 {
208 global $ilDB;
209
210 $query = "SELECT meta_taxon_path_id FROM il_meta_taxon_path ".
211 "WHERE rbac_id = ".$ilDB->quote($a_rbac_id)." ".
212 "AND obj_id = ".$ilDB->quote($a_obj_id)." ".
213 "AND parent_id = ".$ilDB->quote($a_parent_id)." ".
214 "AND parent_type = ".$ilDB->quote($a_parent_type);
215
216 $res = $ilDB->query($query);
217 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
218 {
219 $ids[] = $row->meta_taxon_path_id;
220 }
221 return $ids ? $ids : array();
222 }
223}
224?>
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)
_getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
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)
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
global $ilDB