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