ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilMDEntity.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 
32 include_once 'class.ilMDBase.php';
33 
34 class ilMDEntity extends ilMDBase
35 {
36  function ilMDEntity($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 setEntity($a_entity)
45  {
46  $this->entity = $a_entity;
47  }
48  function getEntity()
49  {
50  return $this->entity;
51  }
52 
53  function save()
54  {
55  global $ilDB;
56 
57  $fields = $this->__getFields();
58  $fields['meta_entity_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_entity'));
59 
60  if($this->db->insert('il_meta_entity',$fields))
61  {
62  $this->setMetaId($next_id);
63  return $this->getMetaId();
64  }
65  return false;
66  }
67 
68  function update()
69  {
70  global $ilDB;
71 
72  if($this->getMetaId())
73  {
74  if($this->db->update('il_meta_entity',
75  $this->__getFields(),
76  array("meta_entity_id" => array('integer',$this->getMetaId()))))
77  {
78  return true;
79  }
80  }
81  return false;
82  }
83 
84  function delete()
85  {
86  global $ilDB;
87 
88  if($this->getMetaId())
89  {
90  $query = "DELETE FROM il_meta_entity ".
91  "WHERE meta_entity_id = ".$ilDB->quote($this->getMetaId(),'integer');
92  $res = $ilDB->manipulate($query);
93 
94  $this->db->query($query);
95 
96  return true;
97  }
98  return false;
99  }
100 
101 
102  function __getFields()
103  {
104  return array('rbac_id' => array('integer',$this->getRBACId()),
105  'obj_id' => array('integer',$this->getObjId()),
106  'obj_type' => array('text',$this->getObjType()),
107  'parent_type' => array('text',$this->getParentType()),
108  'parent_id' => array('integer',$this->getParentId()),
109  'entity' => array('text',$this->getEntity()));
110  }
111 
112  function read()
113  {
114  global $ilDB;
115 
116  if($this->getMetaId())
117  {
118  $query = "SELECT * FROM il_meta_entity ".
119  "WHERE meta_entity_id = ".$ilDB->quote($this->getMetaId() ,'integer');
120 
121  $res = $this->db->query($query);
122  while($row = $res->fetchRow(DB_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->setEntity($row->entity);
130  }
131  }
132  return true;
133  }
134 
135  /*
136  * XML Export of all meta data
137  * @param object (xml writer) see class.ilMD2XML.php
138  *
139  */
140  function toXML(&$writer)
141  {
142  $writer->xmlElement('Entity',null,$this->getEntity());
143  }
144 
145 
146  // STATIC
147  function _getIds($a_rbac_id,$a_obj_id,$a_parent_id,$a_parent_type)
148  {
149  global $ilDB;
150 
151  $query = "SELECT meta_entity_id FROM il_meta_entity ".
152  "WHERE rbac_id = ".$ilDB->quote($a_rbac_id ,'integer')." ".
153  "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ".
154  "AND parent_id = ".$ilDB->quote($a_parent_id ,'integer')." ".
155  "AND parent_type = ".$ilDB->quote($a_parent_type ,'text')." ".
156  "ORDER BY meta_entity_id ";
157 
158  $res = $ilDB->query($query);
159  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
160  {
161  $ids[] = $row->meta_entity_id;
162  }
163  return $ids ? $ids : array();
164  }
165 }
166 ?>