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