ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
31include_once 'class.ilMDBase.php';
32
33class 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 global $ilDB;
79
80 $fields = $this->__getFields();
81 $fields['meta_taxon_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_taxon'));
82
83 if($this->db->insert('il_meta_taxon',$fields))
84 {
85 $this->setMetaId($next_id);
86 return $this->getMetaId();
87 }
88 return false;
89 }
90
91 function update()
92 {
93 global $ilDB;
94
95 if($this->getMetaId())
96 {
97 if($this->db->update('il_meta_taxon',
98 $this->__getFields(),
99 array("meta_taxon_id" => array('integer',$this->getMetaId()))))
100 {
101 return true;
102 }
103 }
104 return false;
105 }
106
107 function delete()
108 {
109 global $ilDB;
110
111 if($this->getMetaId())
112 {
113 $query = "DELETE FROM il_meta_taxon ".
114 "WHERE meta_taxon_id = ".$ilDB->quote($this->getMetaId() ,'integer');
115
116 $this->db->query($query);
117
118 return true;
119 }
120 return false;
121 }
122
123
124 function __getFields()
125 {
126 return array('rbac_id' => array('integer',$this->getRBACId()),
127 'obj_id' => array('integer',$this->getObjId()),
128 'obj_type' => array('text',$this->getObjType()),
129 'parent_type' => array('text',$this->getParentType()),
130 'parent_id' => array('integer',$this->getParentId()),
131 'taxon' => array('text',$this->getTaxon()),
132 'taxon_language' => array('text',$this->getTaxonLanguageCode()),
133 'taxon_id' => array('text',$this->getTaxonId()));
134 }
135
136 function read()
137 {
138 global $ilDB;
139
140 include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php';
141
142 if($this->getMetaId())
143 {
144 $query = "SELECT * FROM il_meta_taxon ".
145 "WHERE meta_taxon_id = ".$ilDB->quote($this->getMetaId() ,'integer');
146
147 $res = $this->db->query($query);
148 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
149 {
150 $this->setRBACId($row->rbac_id);
151 $this->setObjId($row->obj_id);
152 $this->setObjType($row->obj_type);
153 $this->setParentId($row->parent_id);
154 $this->setParentType($row->parent_type);
155 $this->setTaxon($row->taxon);
156 $this->taxon_language = new ilMDLanguageItem($row->taxon_language);
157 $this->setTaxonId($row->taxon_id);
158 }
159 }
160 return true;
161 }
162
163 /*
164 * XML Export of all meta data
165 * @param object (xml writer) see class.ilMD2XML.php
166 *
167 */
168 function toXML(&$writer)
169 {
170 $writer->xmlElement('Taxon',array('Language' => $this->getTaxonLanguageCode()
171 ? $this->getTaxonLanguageCode()
172 : 'en',
173 'Id' => $this->getTaxonId() ?
174 $this->getTaxonId() : ("ID".rand())),
175 $this->getTaxon());
176 }
177
178
179 // STATIC
180 function _getIds($a_rbac_id,$a_obj_id,$a_parent_id,$a_parent_type)
181 {
182 global $ilDB;
183
184 $query = "SELECT meta_taxon_id FROM il_meta_taxon ".
185 "WHERE rbac_id = ".$ilDB->quote($a_rbac_id ,'integer')." ".
186 "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ".
187 "AND parent_id = ".$ilDB->quote($a_parent_id ,'integer')." ".
188 "AND parent_type = ".$ilDB->quote($a_parent_type ,'text');
189
190
191 $res = $ilDB->query($query);
192 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
193 {
194 $ids[] = $row->meta_taxon_id;
195 }
196 return $ids ? $ids : array();
197 }
198}
199?>
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)
setTaxonId($a_taxon_id)
ilMDTaxon($a_rbac_id=0, $a_obj_id=0, $a_obj_type='')
toXML(&$writer)
setTaxon($a_taxon)
setTaxonLanguage(&$lng_obj)
_getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
& getTaxonLanguage()
global $ilDB