ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilMDTaxon.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 ilMDTaxon extends ilMDBase
34 {
35  function ilMDTaxon($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  // SET/GET
43  function setTaxon($a_taxon)
44  {
45  $this->taxon = $a_taxon;
46  }
47  function getTaxon()
48  {
49  return $this->taxon;
50  }
51  function setTaxonLanguage(&$lng_obj)
52  {
53  if(is_object($lng_obj))
54  {
55  $this->taxon_language = $lng_obj;
56  }
57  }
58  function &getTaxonLanguage()
59  {
60  return is_object($this->taxon_language) ? $this->taxon_language : false;
61  }
63  {
64  return is_object($this->taxon_language) ? $this->taxon_language->getLanguageCode() : false;
65  }
66  function setTaxonId($a_taxon_id)
67  {
68  $this->taxon_id = $a_taxon_id;
69  }
70  function getTaxonId()
71  {
72  return $this->taxon_id;
73  }
74 
75 
76  function save()
77  {
78  if($this->db->autoExecute('il_meta_taxon',
79  $this->__getFields(),
80  DB_AUTOQUERY_INSERT))
81  {
82  $this->setMetaId($this->db->getLastInsertId());
83 
84  return $this->getMetaId();
85  }
86  return false;
87  }
88 
89  function update()
90  {
91  global $ilDB;
92 
93  if($this->getMetaId())
94  {
95  if($this->db->autoExecute('il_meta_taxon',
96  $this->__getFields(),
97  DB_AUTOQUERY_UPDATE,
98  "meta_taxon_id = ".$ilDB->quote($this->getMetaId())))
99  {
100  return true;
101  }
102  }
103  return false;
104  }
105 
106  function delete()
107  {
108  if($this->getMetaId())
109  {
110  $query = "DELETE FROM il_meta_taxon ".
111  "WHERE meta_taxon_id = ".$ilDB->quote($this->getMetaId());
112 
113  $this->db->query($query);
114 
115  return true;
116  }
117  return false;
118  }
119 
120 
121  function __getFields()
122  {
123  return array('rbac_id' => $this->getRBACId(),
124  'obj_id' => $this->getObjId(),
125  'obj_type' => ilUtil::prepareDBString($this->getObjType()),
126  'parent_type' => $this->getParentType(),
127  'parent_id' => $this->getParentId(),
128  'taxon' => ilUtil::prepareDBString($this->getTaxon()),
129  'taxon_language' => ilUtil::prepareDBString($this->getTaxonLanguageCode()),
130  'taxon_id' => ilUtil::prepareDBString($this->getTaxonId()));
131  }
132 
133  function read()
134  {
135  global $ilDB;
136 
137  include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDLanguageItem.php';
138 
139  if($this->getMetaId())
140  {
141  $query = "SELECT * FROM il_meta_taxon ".
142  "WHERE meta_taxon_id = ".$ilDB->quote($this->getMetaId());
143 
144  $res = $this->db->query($query);
145  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
146  {
147  $this->setRBACId($row->rbac_id);
148  $this->setObjId($row->obj_id);
149  $this->setObjType($row->obj_type);
150  $this->setParentId($row->parent_id);
151  $this->setParentType($row->parent_type);
152  $this->setTaxon(ilUtil::stripSlashes($row->taxon));
153  $this->taxon_language = new ilMDLanguageItem($row->taxon_language);
154  $this->setTaxonId(ilUtil::stripSlashes($row->taxon_id));
155  }
156  }
157  return true;
158  }
159 
160  /*
161  * XML Export of all meta data
162  * @param object (xml writer) see class.ilMD2XML.php
163  *
164  */
165  function toXML(&$writer)
166  {
167  $writer->xmlElement('Taxon',array('Language' => $this->getTaxonLanguageCode(),
168  'Id' => $this->getTaxonId()),$this->getTaxon());
169  }
170 
171 
172  // STATIC
173  function _getIds($a_rbac_id,$a_obj_id,$a_parent_id,$a_parent_type)
174  {
175  global $ilDB;
176 
177  $query = "SELECT meta_taxon_id FROM il_meta_taxon ".
178  "WHERE rbac_id = ".$ilDB->quote($a_rbac_id)." ".
179  "AND obj_id = ".$ilDB->quote($a_obj_id)." ".
180  "AND parent_id = ".$ilDB->quote($a_parent_id)." ".
181  "AND parent_type = ".$ilDB->quote($a_parent_type);
182 
183 
184  $res = $ilDB->query($query);
185  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
186  {
187  $ids[] = $row->meta_taxon_id;
188  }
189  return $ids ? $ids : array();
190  }
191 }
192 ?>