ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
30 include_once 'class.ilMDBase.php';
31 
32 class ilMDIdentifier extends ilMDBase
33 {
34 
35  function ilMDIdentifier($a_rbac_id = 0,$a_obj_id = 0,$a_obj_type = '')
36  {
37  parent::ilMDBase($a_rbac_id,
38  $a_obj_id,
39  $a_obj_type);
40  }
41 
42  // SET/GET
43  function setCatalog($a_catalog)
44  {
45  $this->catalog = $a_catalog;
46  }
47  function getCatalog()
48  {
49  return $this->catalog;
50  }
51  function setEntry($a_entry)
52  {
53  $this->entry = $a_entry;
54  }
55  function getEntry()
56  {
57  return $this->entry;
58  }
59 
60 
61  function save()
62  {
63  global $ilDB;
64 
65  $fields = $this->__getFields();
66  $fields['meta_identifier_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_identifier'));
67 
68  if($this->db->insert('il_meta_identifier',$fields))
69  {
70  $this->setMetaId($next_id);
71  return $this->getMetaId();
72  }
73  return false;
74  }
75 
76  function update()
77  {
78  global $ilDB;
79 
80  if($this->getMetaId())
81  {
82  if($this->db->update('il_meta_identifier',
83  $this->__getFields(),
84  array("meta_identifier_id" => array('integer',$this->getMetaId()))))
85  {
86  return true;
87  }
88  }
89  return false;
90  }
91 
92  function delete()
93  {
94  global $ilDB;
95 
96  if($this->getMetaId())
97  {
98  $query = "DELETE FROM il_meta_identifier ".
99  "WHERE meta_identifier_id = ".$ilDB->quote($this->getMetaId() ,'integer');
100  $res = $ilDB->manipulate($query);
101  return true;
102  }
103  return false;
104  }
105 
106 
107  function __getFields()
108  {
109  return array('rbac_id' => array('integer',$this->getRBACId()),
110  'obj_id' => array('integer',$this->getObjId()),
111  'obj_type' => array('text',$this->getObjType()),
112  'parent_type' => array('text',$this->getParentType()),
113  'parent_id' => array('integer',$this->getParentId()),
114  'catalog' => array('text',$this->getCatalog()),
115  'entry' => array('text',$this->getEntry()));
116 
117  }
118 
119  function read()
120  {
121  global $ilDB;
122 
123  if($this->getMetaId())
124  {
125  $query = "SELECT * FROM il_meta_identifier ".
126  "WHERE meta_identifier_id = ".$ilDB->quote($this->getMetaId() ,'integer');
127 
128  $res = $this->db->query($query);
129  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
130  {
131  $this->setRBACId($row->rbac_id);
132  $this->setObjId($row->obj_id);
133  $this->setObjType($row->obj_type);
134  $this->setParentId($row->parent_id);
135  $this->setParentType($row->parent_type);
136  $this->setCatalog($row->catalog);
137  $this->setEntry($row->entry);
138  }
139  }
140  return true;
141  }
142 
143  /*
144  * XML Export of all meta data
145  * @param object (xml writer) see class.ilMD2XML.php
146  *
147  */
148  function toXML(&$writer, $a_overwrite_id = false)
149  {
150  $entry_default = ($this->getObjId() == 0)
151  ? "il_".IL_INST_ID."_".$this->getObjType()."_".$this->getRBACId()
152  : "il_".IL_INST_ID."_".$this->getObjType()."_".$this->getObjId();
153 
154  $entry = $this->getEntry() ? $this->getEntry() : $entry_default;
155  $catalog = $this->getCatalog();
156 
157  if ($this->getExportMode() && $this->getCatalog() != "ILIAS_NID")
158  {
159  $entry = $entry_default;
160  $catalog = "ILIAS";
161  }
162 
163  if(strlen($catalog))
164  {
165  $writer->xmlElement('Identifier',array('Catalog' => $catalog,
166  'Entry' => $entry));
167  }
168  else
169  {
170  $writer->xmlElement('Identifier',array('Entry' => $entry));
171  }
172  }
173 
174 
175  // STATIC
176  function _getIds($a_rbac_id,$a_obj_id,$a_parent_id,$a_parent_type)
177  {
178  global $ilDB;
179 
180  $query = "SELECT meta_identifier_id FROM il_meta_identifier ".
181  "WHERE rbac_id = ".$ilDB->quote($a_rbac_id ,'integer')." ".
182  "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ".
183  "AND parent_id = ".$ilDB->quote($a_parent_id ,'integer')." ".
184  "AND parent_type = ".$ilDB->quote($a_parent_type ,'text');
185 
186  $res = $ilDB->query($query);
187  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
188  {
189  $ids[] = $row->meta_identifier_id;
190  }
191  return $ids ? $ids : array();
192  }
193 
200  static public function _getEntriesForObj($a_rbac_id, $a_obj_id, $a_obj_type)
201  {
202  global $ilDB;
203 
204  $query = "SELECT meta_identifier_id, catalog, entry FROM il_meta_identifier ".
205  "WHERE rbac_id = ".$ilDB->quote($a_rbac_id ,'integer')." ".
206  "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ".
207  "AND obj_type = ".$ilDB->quote($a_obj_type ,'text');
208 
209  $res = $ilDB->query($query);
210  $entries = array();
211  while($r = $ilDB->fetchAssoc($res))
212  {
213  $entries[$r["meta_identifier_id"]] =
214  array("catalog" => $r["catalog"],
215  "entry" => $r["entry"]);
216  }
217  return $entries;
218  }
219 
226  static public function _getEntriesForRbacObj($a_rbac_id, $a_obj_type = "")
227  {
228  global $ilDB;
229 
230  $query = "SELECT meta_identifier_id, catalog, entry, obj_id FROM il_meta_identifier ".
231  "WHERE rbac_id = ".$ilDB->quote($a_rbac_id ,'integer');
232 
233  if ($a_obj_type != "")
234  {
235  $query.=
236  " AND obj_type = ".$ilDB->quote($a_obj_type ,'text');
237  }
238 
239  $res = $ilDB->query($query);
240  $entries = array();
241  while($r = $ilDB->fetchAssoc($res))
242  {
243  $entries[$r["meta_identifier_id"]] =
244  array("catalog" => $r["catalog"],
245  "entry" => $r["entry"],
246  "obj_id" => $r["obj_id"]);
247  }
248  return $entries;
249  }
250 
257  static public function existsIdInRbacObject($a_rbac_id, $a_obj_type, $a_catalog, $a_entry)
258  {
259  global $ilDB;
260 
261  $query = "SELECT meta_identifier_id, obj_id FROM il_meta_identifier ".
262  "WHERE rbac_id = ".$ilDB->quote($a_rbac_id , 'integer').
263  " AND obj_type = ".$ilDB->quote($a_obj_type , 'text').
264  " AND catalog = ".$ilDB->quote($a_catalog , 'text').
265  " AND entry = ".$ilDB->quote($a_entry , 'text');
266  $s = $ilDB->query($query);
267  if ($r = $ilDB->fetchAssoc($s))
268  {
269  return true;
270  }
271  return false;
272  }
273 
280  static public function readIdData($a_rbac_id, $a_obj_type, $a_catalog, $a_entry)
281  {
282  global $ilDB;
283 
284  $query = "SELECT * FROM il_meta_identifier ".
285  "WHERE rbac_id = ".$ilDB->quote($a_rbac_id , 'integer').
286  " AND obj_type = ".$ilDB->quote($a_obj_type , 'text').
287  " AND catalog = ".$ilDB->quote($a_catalog , 'text').
288  " AND entry = ".$ilDB->quote($a_entry , 'text');
289  $s = $ilDB->query($query);
290  $data = array();
291  while ($r = $ilDB->fetchAssoc($s))
292  {
293  $data[] = $r;
294  }
295  return $data;
296  }
297 
298 }
299 
300 ?>