ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilMDIdentifier.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
30include_once 'class.ilMDBase.php';
31
33{
34
35 // SET/GET
36 public function setCatalog($a_catalog)
37 {
38 $this->catalog = $a_catalog;
39 }
40 public function getCatalog()
41 {
42 return $this->catalog;
43 }
44 public function setEntry($a_entry)
45 {
46 $this->entry = $a_entry;
47 }
48 public function getEntry()
49 {
50 return $this->entry;
51 }
52
53
54 public function save()
55 {
56 global $ilDB;
57
58 $fields = $this->__getFields();
59 $fields['meta_identifier_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_identifier'));
60
61 if ($this->db->insert('il_meta_identifier', $fields)) {
62 $this->setMetaId($next_id);
63 return $this->getMetaId();
64 }
65 return false;
66 }
67
68 public function update()
69 {
70 global $ilDB;
71
72 if ($this->getMetaId()) {
73 if ($this->db->update(
74 'il_meta_identifier',
75 $this->__getFields(),
76 array("meta_identifier_id" => array('integer',$this->getMetaId()))
77 )) {
78 return true;
79 }
80 }
81 return false;
82 }
83
84 public function delete()
85 {
86 global $ilDB;
87
88 if ($this->getMetaId()) {
89 $query = "DELETE FROM il_meta_identifier " .
90 "WHERE meta_identifier_id = " . $ilDB->quote($this->getMetaId(), 'integer');
91 $res = $ilDB->manipulate($query);
92 return true;
93 }
94 return false;
95 }
96
97
98 public function __getFields()
99 {
100 return array('rbac_id' => array('integer',$this->getRBACId()),
101 'obj_id' => array('integer',$this->getObjId()),
102 'obj_type' => array('text',$this->getObjType()),
103 'parent_type' => array('text',$this->getParentType()),
104 'parent_id' => array('integer',$this->getParentId()),
105 'catalog' => array('text',$this->getCatalog()),
106 'entry' => array('text',$this->getEntry()));
107 }
108
109 public function read()
110 {
111 global $ilDB;
112
113 if ($this->getMetaId()) {
114 $query = "SELECT * FROM il_meta_identifier " .
115 "WHERE meta_identifier_id = " . $ilDB->quote($this->getMetaId(), 'integer');
116
117 $res = $this->db->query($query);
118 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
119 $this->setRBACId($row->rbac_id);
120 $this->setObjId($row->obj_id);
121 $this->setObjType($row->obj_type);
122 $this->setParentId($row->parent_id);
123 $this->setParentType($row->parent_type);
124 $this->setCatalog($row->catalog);
125 $this->setEntry($row->entry);
126 }
127 }
128 return true;
129 }
130
131 /*
132 * XML Export of all meta data
133 * @param object (xml writer) see class.ilMD2XML.php
134 *
135 */
136 public function toXML(&$writer, $a_overwrite_id = false)
137 {
138 $entry_default = ($this->getObjId() == 0)
139 ? "il_" . IL_INST_ID . "_" . $this->getObjType() . "_" . $this->getRBACId()
140 : "il_" . IL_INST_ID . "_" . $this->getObjType() . "_" . $this->getObjId();
141
142 $entry = $this->getEntry() ? $this->getEntry() : $entry_default;
143 $catalog = $this->getCatalog();
144
145 if ($this->getExportMode() && $this->getCatalog() != "ILIAS_NID") {
146 $entry = $entry_default;
147 $catalog = "ILIAS";
148 }
149
150 if (strlen($catalog)) {
151 $writer->xmlElement('Identifier', array('Catalog' => $catalog,
152 'Entry' => $entry));
153 } else {
154 $writer->xmlElement('Identifier', array('Entry' => $entry));
155 }
156 }
157
158
159 // STATIC
160 public static function _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
161 {
162 global $ilDB;
163
164 $query = "SELECT meta_identifier_id FROM il_meta_identifier " .
165 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
166 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
167 "AND parent_id = " . $ilDB->quote($a_parent_id, 'integer') . " " .
168 "AND parent_type = " . $ilDB->quote($a_parent_type, 'text');
169
170 $res = $ilDB->query($query);
171 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
172 $ids[] = $row->meta_identifier_id;
173 }
174 return $ids ? $ids : array();
175 }
176
183 public static function _getEntriesForObj($a_rbac_id, $a_obj_id, $a_obj_type)
184 {
185 global $ilDB;
186
187 $query = "SELECT meta_identifier_id, catalog, entry FROM il_meta_identifier " .
188 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
189 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
190 "AND obj_type = " . $ilDB->quote($a_obj_type, 'text');
191
192 $res = $ilDB->query($query);
193 $entries = array();
194 while ($r = $ilDB->fetchAssoc($res)) {
195 $entries[$r["meta_identifier_id"]] =
196 array("catalog" => $r["catalog"],
197 "entry" => $r["entry"]);
198 }
199 return $entries;
200 }
201
208 public static function _getEntriesForRbacObj($a_rbac_id, $a_obj_type = "")
209 {
210 global $ilDB;
211
212 $query = "SELECT meta_identifier_id, catalog, entry, obj_id FROM il_meta_identifier " .
213 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer');
214
215 if ($a_obj_type != "") {
216 $query.=
217 " AND obj_type = " . $ilDB->quote($a_obj_type, 'text');
218 }
219
220 $res = $ilDB->query($query);
221 $entries = array();
222 while ($r = $ilDB->fetchAssoc($res)) {
223 $entries[$r["meta_identifier_id"]] =
224 array("catalog" => $r["catalog"],
225 "entry" => $r["entry"],
226 "obj_id" => $r["obj_id"]);
227 }
228 return $entries;
229 }
230
237 public static function existsIdInRbacObject($a_rbac_id, $a_obj_type, $a_catalog, $a_entry)
238 {
239 global $ilDB;
240
241 $query = "SELECT meta_identifier_id, obj_id FROM il_meta_identifier " .
242 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') .
243 " AND obj_type = " . $ilDB->quote($a_obj_type, 'text') .
244 " AND catalog = " . $ilDB->quote($a_catalog, 'text') .
245 " AND entry = " . $ilDB->quote($a_entry, 'text');
246 $s = $ilDB->query($query);
247 if ($r = $ilDB->fetchAssoc($s)) {
248 return true;
249 }
250 return false;
251 }
252
259 public static function readIdData($a_rbac_id, $a_obj_type, $a_catalog, $a_entry)
260 {
261 global $ilDB;
262
263 $query = "SELECT * FROM il_meta_identifier " .
264 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') .
265 " AND obj_type = " . $ilDB->quote($a_obj_type, 'text') .
266 " AND catalog = " . $ilDB->quote($a_catalog, 'text') .
267 " AND entry = " . $ilDB->quote($a_entry, 'text');
268 $s = $ilDB->query($query);
269 $data = array();
270 while ($r = $ilDB->fetchAssoc($s)) {
271 $data[] = $r;
272 }
273 return $data;
274 }
275}
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)
static _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
static _getEntriesForRbacObj($a_rbac_id, $a_obj_type="")
Get IDs for an rbac object.
static _getEntriesForObj($a_rbac_id, $a_obj_id, $a_obj_type)
Get IDs for an object.
toXML(&$writer, $a_overwrite_id=false)
static existsIdInRbacObject($a_rbac_id, $a_obj_type, $a_catalog, $a_entry)
Does id entry exist in rbac object?
static readIdData($a_rbac_id, $a_obj_type, $a_catalog, $a_entry)
Does id entry exist in rbac object?
$r
Definition: example_031.php:79
$query
$s
Definition: pwgen.php:45
foreach($_POST as $key=> $value) $res
global $ilDB