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 if ($this->db->autoExecute(
71 'il_meta_taxon',
72 $this->__getFields(),
74 )) {
75 $this->setMetaId($this->db->getLastInsertId());
76
77 return $this->getMetaId();
78 }
79 return false;
80 }
81
82 public function update()
83 {
84 global $ilDB;
85
86 if ($this->getMetaId()) {
87 if ($this->db->autoExecute(
88 'il_meta_taxon',
89 $this->__getFields(),
91 "meta_taxon_id = " . $ilDB->quote($this->getMetaId())
92 )) {
93 return true;
94 }
95 }
96 return false;
97 }
98
99 public function delete()
100 {
101 if ($this->getMetaId()) {
102 $query = "DELETE FROM il_meta_taxon " .
103 "WHERE meta_taxon_id = " . $ilDB->quote($this->getMetaId());
104
105 $this->db->query($query);
106
107 return true;
108 }
109 return false;
110 }
111
112
113 public function __getFields()
114 {
115 return array('rbac_id' => $this->getRBACId(),
116 'obj_id' => $this->getObjId(),
117 'obj_type' => ilUtil::prepareDBString($this->getObjType()),
118 'parent_type' => $this->getParentType(),
119 'parent_id' => $this->getParentId(),
120 'taxon' => ilUtil::prepareDBString($this->getTaxon()),
121 'taxon_language' => ilUtil::prepareDBString($this->getTaxonLanguageCode()),
122 'taxon_id' => ilUtil::prepareDBString($this->getTaxonId()));
123 }
124
125 public function read()
126 {
127 global $ilDB;
128
129 include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDLanguageItem.php';
130
131 if ($this->getMetaId()) {
132 $query = "SELECT * FROM il_meta_taxon " .
133 "WHERE meta_taxon_id = " . $ilDB->quote($this->getMetaId());
134
135 $res = $this->db->query($query);
136 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
137 $this->setRBACId($row->rbac_id);
138 $this->setObjId($row->obj_id);
139 $this->setObjType($row->obj_type);
140 $this->setParentId($row->parent_id);
141 $this->setParentType($row->parent_type);
142 $this->setTaxon(ilUtil::stripSlashes($row->taxon));
143 $this->taxon_language = new ilMDLanguageItem($row->taxon_language);
144 $this->setTaxonId(ilUtil::stripSlashes($row->taxon_id));
145 }
146 }
147 return true;
148 }
149
150 /*
151 * XML Export of all meta data
152 * @param object (xml writer) see class.ilMD2XML.php
153 *
154 */
155 public function toXML(&$writer)
156 {
157 $writer->xmlElement('Taxon', array('Language' => $this->getTaxonLanguageCode(),
158 'Id' => $this->getTaxonId()), $this->getTaxon());
159 }
160
161
162 // STATIC
163 public function _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
164 {
165 global $ilDB;
166
167 $query = "SELECT meta_taxon_id FROM il_meta_taxon " .
168 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id) . " " .
169 "AND obj_id = " . $ilDB->quote($a_obj_id) . " " .
170 "AND parent_id = " . $ilDB->quote($a_parent_id) . " " .
171 "AND parent_type = " . $ilDB->quote($a_parent_type);
172
173
174 $res = $ilDB->query($query);
175 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
176 $ids[] = $row->meta_taxon_id;
177 }
178 return $ids ? $ids : array();
179 }
180}
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)
setTaxon($a_taxon)
setTaxonLanguage(&$lng_obj)
_getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
& getTaxonLanguage()
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
$row
$query
foreach($_POST as $key=> $value) $res
global $ilDB