ILIAS  eassessment Revision 61809
 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 
24 
31 include_once 'class.ilMDBase.php';
32 
33 class ilMDIdentifier extends ilMDBase
34 {
35 
36  function ilMDIdentifier($a_rbac_id = 0,$a_obj_id = 0,$a_obj_type = '')
37  {
38  parent::ilMDBase($a_rbac_id,
39  $a_obj_id,
40  $a_obj_type);
41  }
42 
43  // SET/GET
44  function setCatalog($a_catalog)
45  {
46  $this->catalog = $a_catalog;
47  }
48  function getCatalog()
49  {
50  return $this->catalog;
51  }
52  function setEntry($a_entry)
53  {
54  $this->entry = $a_entry;
55  }
56  function getEntry()
57  {
58  return $this->entry;
59  }
60 
61 
62  function save()
63  {
64  global $ilDB;
65 
66  $fields = $this->__getFields();
67  $fields['meta_identifier_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_identifier'));
68 
69  if($this->db->insert('il_meta_identifier',$fields))
70  {
71  $this->setMetaId($next_id);
72  return $this->getMetaId();
73  }
74  return false;
75  }
76 
77  function update()
78  {
79  global $ilDB;
80 
81  if($this->getMetaId())
82  {
83  if($this->db->update('il_meta_identifier',
84  $this->__getFields(),
85  array("meta_identifier_id" => array('integer',$this->getMetaId()))))
86  {
87  return true;
88  }
89  }
90  return false;
91  }
92 
93  function delete()
94  {
95  global $ilDB;
96 
97  if($this->getMetaId())
98  {
99  $query = "DELETE FROM il_meta_identifier ".
100  "WHERE meta_identifier_id = ".$ilDB->quote($this->getMetaId() ,'integer');
101  $res = $ilDB->manipulate($query);
102  return true;
103  }
104  return false;
105  }
106 
107 
108  function __getFields()
109  {
110  return array('rbac_id' => array('integer',$this->getRBACId()),
111  'obj_id' => array('integer',$this->getObjId()),
112  'obj_type' => array('text',$this->getObjType()),
113  'parent_type' => array('text',$this->getParentType()),
114  'parent_id' => array('integer',$this->getParentId()),
115  'catalog' => array('text',$this->getCatalog()),
116  'entry' => array('text',$this->getEntry()));
117 
118  }
119 
120  function read()
121  {
122  global $ilDB;
123 
124  if($this->getMetaId())
125  {
126  $query = "SELECT * FROM il_meta_identifier ".
127  "WHERE meta_identifier_id = ".$ilDB->quote($this->getMetaId() ,'integer');
128 
129  $res = $this->db->query($query);
130  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
131  {
132  $this->setRBACId($row->rbac_id);
133  $this->setObjId($row->obj_id);
134  $this->setObjType($row->obj_type);
135  $this->setParentId($row->parent_id);
136  $this->setParentType($row->parent_type);
137  $this->setCatalog($row->catalog);
138  $this->setEntry($row->entry);
139  }
140  }
141  return true;
142  }
143 
144  /*
145  * XML Export of all meta data
146  * @param object (xml writer) see class.ilMD2XML.php
147  *
148  */
149  function toXML(&$writer, $a_overwrite_id = false)
150  {
151  $entry_default = ($this->getObjId() == 0)
152  ? "il_".IL_INST_ID."_".$this->getObjType()."_".$this->getRBACId()
153  : "il_".IL_INST_ID."_".$this->getObjType()."_".$this->getObjId();
154 
155  $entry = $this->getEntry() ? $this->getEntry() : $entry_default;
156  $catalog = $this->getCatalog();
157 
158  if ($this->getExportMode() && $this->getCatalog() != "ILIAS_NID")
159  {
160  $entry = $entry_default;
161  $catalog = "ILIAS";
162  }
163 
164  if(strlen($catalog))
165  {
166  $writer->xmlElement('Identifier',array('Catalog' => $catalog,
167  'Entry' => $entry));
168  }
169  else
170  {
171  $writer->xmlElement('Identifier',array('Entry' => $entry));
172  }
173  }
174 
175 
176  // STATIC
177  function _getIds($a_rbac_id,$a_obj_id,$a_parent_id,$a_parent_type)
178  {
179  global $ilDB;
180 
181  $query = "SELECT meta_identifier_id FROM il_meta_identifier ".
182  "WHERE rbac_id = ".$ilDB->quote($a_rbac_id ,'integer')." ".
183  "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ".
184  "AND parent_id = ".$ilDB->quote($a_parent_id ,'integer')." ".
185  "AND parent_type = ".$ilDB->quote($a_parent_type ,'text');
186 
187 
188  $res = $ilDB->query($query);
189  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
190  {
191  $ids[] = $row->meta_identifier_id;
192  }
193  return $ids ? $ids : array();
194  }
195 }
196 ?>