ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
31 include_once 'class.ilMDBase.php';
32 
33 class ilMDTaxonPath extends ilMDBase
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/Migration/DBUpdate_426/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/Migration/DBUpdate_426/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/Migration/DBUpdate_426/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  }
89  function &getSourceLanguage()
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  if($this->db->autoExecute('il_meta_taxon_path',
102  $this->__getFields(),
103  DB_AUTOQUERY_INSERT))
104  {
105  $this->setMetaId($this->db->getLastInsertId());
106 
107  return $this->getMetaId();
108  }
109  return false;
110  }
111 
112  function update()
113  {
114  global $ilDB;
115 
116  if($this->getMetaId())
117  {
118  if($this->db->autoExecute('il_meta_taxon_path',
119  $this->__getFields(),
120  DB_AUTOQUERY_UPDATE,
121  "meta_taxon_path_id = ".$ilDB->quote($this->getMetaId())))
122  {
123  return true;
124  }
125  }
126  return false;
127  }
128 
129  function delete()
130  {
131  global $ilDB;
132 
133  if($this->getMetaId())
134  {
135  $query = "DELETE FROM il_meta_taxon_path ".
136  "WHERE meta_taxon_path_id = ".$ilDB->quote($this->getMetaId());
137 
138  $this->db->query($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' => $this->getRBACId(),
155  'obj_id' => $this->getObjId(),
156  'obj_type' => ilUtil::prepareDBString($this->getObjType()),
157  'parent_type' => $this->getParentType(),
158  'parent_id' => $this->getParentId(),
159  'source' => ilUtil::prepareDBString($this->getSource()),
160  'source_language' => ilUtil::prepareDBString($this->getSourceLanguageCode()));
161  }
162 
163  function read()
164  {
165  global $ilDB;
166 
167  include_once 'Services/Migration/DBUpdate_426/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());
173 
174  $res = $this->db->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(ilUtil::stripSlashes($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()),$this->getSource());
199 
200  // Taxon
201  foreach($this->getTaxonIds() as $id)
202  {
203  $tax =& $this->getTaxon($id);
204  $tax->toXML($writer);
205  }
206 
207  $writer->xmlEndTag('TaxonPath');
208  }
209 
210 
211 
212  // STATIC
213  function _getIds($a_rbac_id,$a_obj_id,$a_parent_id,$a_parent_type)
214  {
215  global $ilDB;
216 
217  $query = "SELECT meta_taxon_path_id FROM il_meta_taxon_path ".
218  "WHERE rbac_id = ".$ilDB->quote($a_rbac_id)." ".
219  "AND obj_id = ".$ilDB->quote($a_obj_id)." ".
220  "AND parent_id = ".$ilDB->quote($a_parent_id)." ".
221  "AND parent_type = ".$ilDB->quote($a_parent_type);
222 
223  $res = $ilDB->query($query);
224  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
225  {
226  $ids[] = $row->meta_taxon_path_id;
227  }
228  return $ids ? $ids : array();
229  }
230 }
231 ?>