ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilMD5295Identifier.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.ilMD5295Base.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 $DIC;
57
58 $ilDB = $DIC['ilDB'];
59
60 $fields = $this->__getFields();
61 $fields['meta_identifier_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_identifier'));
62
63 if ($this->db->insert('il_meta_identifier', $fields)) {
64 $this->setMetaId($next_id);
65 return $this->getMetaId();
66 }
67 return false;
68 }
69
70 public function update()
71 {
72 global $DIC;
73
74 $ilDB = $DIC['ilDB'];
75
76 if ($this->getMetaId()) {
77 if ($this->db->update(
78 'il_meta_identifier',
79 $this->__getFields(),
80 array("meta_identifier_id" => array('integer',$this->getMetaId()))
81 )) {
82 return true;
83 }
84 }
85 return false;
86 }
87
88 public function delete()
89 {
90 global $DIC;
91
92 $ilDB = $DIC['ilDB'];
93
94 if ($this->getMetaId()) {
95 $query = "DELETE FROM il_meta_identifier " .
96 "WHERE meta_identifier_id = " . $ilDB->quote($this->getMetaId(), 'integer');
97 $res = $ilDB->manipulate($query);
98 return true;
99 }
100 return false;
101 }
102
103
104 public function __getFields()
105 {
106 return array('rbac_id' => array('integer',$this->getRBACId()),
107 'obj_id' => array('integer',$this->getObjId()),
108 'obj_type' => array('text',$this->getObjType()),
109 'parent_type' => array('text',$this->getParentType()),
110 'parent_id' => array('integer',$this->getParentId()),
111 'catalog' => array('text',$this->getCatalog()),
112 'entry' => array('text',$this->getEntry()));
113 }
114
115 public function read()
116 {
117 global $DIC;
118
119 $ilDB = $DIC['ilDB'];
120
121 if ($this->getMetaId()) {
122 $query = "SELECT * FROM il_meta_identifier " .
123 "WHERE meta_identifier_id = " . $ilDB->quote($this->getMetaId(), 'integer');
124
125 $res = $this->db->query($query);
126 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
127 $this->setRBACId($row->rbac_id);
128 $this->setObjId($row->obj_id);
129 $this->setObjType($row->obj_type);
130 $this->setParentId($row->parent_id);
131 $this->setParentType($row->parent_type);
132 $this->setCatalog($row->catalog);
133 $this->setEntry($row->entry);
134 }
135 }
136 return true;
137 }
138
139 /*
140 * XML Export of all meta data
141 * @param object (xml writer) see class.ilMD52952XML.php
142 *
143 */
144 public function toXML(&$writer, $a_overwrite_id = false)
145 {
146 $entry_default = ($this->getObjId() == 0)
147 ? "il_" . IL_INST_ID . "_" . $this->getObjType() . "_" . $this->getRBACId()
148 : "il_" . IL_INST_ID . "_" . $this->getObjType() . "_" . $this->getObjId();
149
150 $entry = $this->getEntry() ? $this->getEntry() : $entry_default;
151 $catalog = $this->getCatalog();
152
153 if ($this->getExportMode() && $this->getCatalog() != "ILIAS_NID") {
154 $entry = $entry_default;
155 $catalog = "ILIAS";
156 }
157
158 if (strlen($catalog)) {
159 $writer->xmlElement('Identifier', array('Catalog' => $catalog,
160 'Entry' => $entry));
161 } else {
162 $writer->xmlElement('Identifier', array('Entry' => $entry));
163 }
164 }
165
166
167 // STATIC
168 public static function _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
169 {
170 global $DIC;
171
172 $ilDB = $DIC['ilDB'];
173
174 $query = "SELECT meta_identifier_id FROM il_meta_identifier " .
175 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
176 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
177 "AND parent_id = " . $ilDB->quote($a_parent_id, 'integer') . " " .
178 "AND parent_type = " . $ilDB->quote($a_parent_type, 'text');
179
180 $res = $ilDB->query($query);
181 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
182 $ids[] = $row->meta_identifier_id;
183 }
184 return $ids ? $ids : array();
185 }
186
193 public static function _getEntriesForObj($a_rbac_id, $a_obj_id, $a_obj_type)
194 {
195 global $DIC;
196
197 $ilDB = $DIC['ilDB'];
198
199 $query = "SELECT meta_identifier_id, catalog, entry FROM il_meta_identifier " .
200 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
201 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
202 "AND obj_type = " . $ilDB->quote($a_obj_type, 'text');
203
204 $res = $ilDB->query($query);
205 $entries = array();
206 while ($r = $ilDB->fetchAssoc($res)) {
207 $entries[$r["meta_identifier_id"]] =
208 array("catalog" => $r["catalog"],
209 "entry" => $r["entry"]);
210 }
211 return $entries;
212 }
213
220 public static function _getEntriesForRbacObj($a_rbac_id, $a_obj_type = "")
221 {
222 global $DIC;
223
224 $ilDB = $DIC['ilDB'];
225
226 $query = "SELECT meta_identifier_id, catalog, entry, obj_id FROM il_meta_identifier " .
227 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer');
228
229 if ($a_obj_type != "") {
230 $query .=
231 " AND obj_type = " . $ilDB->quote($a_obj_type, 'text');
232 }
233
234 $res = $ilDB->query($query);
235 $entries = array();
236 while ($r = $ilDB->fetchAssoc($res)) {
237 $entries[$r["meta_identifier_id"]] =
238 array("catalog" => $r["catalog"],
239 "entry" => $r["entry"],
240 "obj_id" => $r["obj_id"]);
241 }
242 return $entries;
243 }
244
251 public static function existsIdInRbacObject($a_rbac_id, $a_obj_type, $a_catalog, $a_entry)
252 {
253 global $DIC;
254
255 $ilDB = $DIC['ilDB'];
256
257 $query = "SELECT meta_identifier_id, obj_id FROM il_meta_identifier " .
258 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') .
259 " AND obj_type = " . $ilDB->quote($a_obj_type, 'text') .
260 " AND catalog = " . $ilDB->quote($a_catalog, 'text') .
261 " AND entry = " . $ilDB->quote($a_entry, 'text');
262 $s = $ilDB->query($query);
263 if ($r = $ilDB->fetchAssoc($s)) {
264 return true;
265 }
266 return false;
267 }
268
275 public static function readIdData($a_rbac_id, $a_obj_type, $a_catalog, $a_entry)
276 {
277 global $DIC;
278
279 $ilDB = $DIC['ilDB'];
280
281 $query = "SELECT * FROM il_meta_identifier " .
282 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') .
283 " AND obj_type = " . $ilDB->quote($a_obj_type, 'text') .
284 " AND catalog = " . $ilDB->quote($a_catalog, 'text') .
285 " AND entry = " . $ilDB->quote($a_entry, 'text');
286 $s = $ilDB->query($query);
287 $data = array();
288 while ($r = $ilDB->fetchAssoc($s)) {
289 $data[] = $r;
290 }
291 return $data;
292 }
293}
An exception for terminatinating execution or to throw for unit testing.
setParentType($a_parent_type)
setMetaId($a_meta_id, $a_read_data=true)
static _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
static readIdData($a_rbac_id, $a_obj_type, $a_catalog, $a_entry)
Does id entry exist in 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 _getEntriesForRbacObj($a_rbac_id, $a_obj_type="")
Get IDs for an rbac object.
const IL_INST_ID
Definition: constants.php:38
global $DIC
Definition: goto.php:24
$query
foreach($_POST as $key=> $value) $res
global $ilDB
$data
Definition: storeScorm.php:23