ILIAS  eassessment Revision 61809
 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  if($this->db->autoExecute('il_meta_entity',
56  $this->__getFields(),
57  DB_AUTOQUERY_INSERT))
58  {
59  $this->setMetaId($this->db->getLastInsertId());
60 
61  return $this->getMetaId();
62  }
63  return false;
64  }
65 
66  function update()
67  {
68  global $ilDB;
69 
70  if($this->getMetaId())
71  {
72  if($this->db->autoExecute('il_meta_entity',
73  $this->__getFields(),
74  DB_AUTOQUERY_UPDATE,
75  "meta_entity_id = ".$ilDB->quote($this->getMetaId())))
76  {
77  return true;
78  }
79  }
80  return false;
81  }
82 
83  function delete()
84  {
85  global $ilDB;
86 
87  if($this->getMetaId())
88  {
89  $query = "DELETE FROM il_meta_entity ".
90  "WHERE meta_entity_id = ".$ilDB->quote($this->getMetaId());
91 
92  $this->db->query($query);
93 
94  return true;
95  }
96  return false;
97  }
98 
99 
100  function __getFields()
101  {
102  return array('rbac_id' => $this->getRBACId(),
103  'obj_id' => $this->getObjId(),
104  'obj_type' => ilUtil::prepareDBString($this->getObjType()),
105  'parent_type' => $this->getParentType(),
106  'parent_id' => $this->getParentId(),
107  'entity' => ilUtil::prepareDBString($this->getEntity()));
108  }
109 
110  function read()
111  {
112  global $ilDB;
113 
114  if($this->getMetaId())
115  {
116  $query = "SELECT * FROM il_meta_entity ".
117  "WHERE meta_entity_id = ".$ilDB->quote($this->getMetaId());
118 
119  $res = $this->db->query($query);
120  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
121  {
122  $this->setRBACId($row->rbac_id);
123  $this->setObjId($row->obj_id);
124  $this->setObjType($row->obj_type);
125  $this->setParentId($row->parent_id);
126  $this->setParentType($row->parent_type);
127  $this->setEntity(ilUtil::stripSlashes($row->entity));
128  }
129  }
130  return true;
131  }
132 
133  /*
134  * XML Export of all meta data
135  * @param object (xml writer) see class.ilMD2XML.php
136  *
137  */
138  function toXML(&$writer)
139  {
140  $writer->xmlElement('Entity',null,$this->getEntity());
141  }
142 
143 
144  // STATIC
145  function _getIds($a_rbac_id,$a_obj_id,$a_parent_id,$a_parent_type)
146  {
147  global $ilDB;
148 
149  $query = "SELECT meta_entity_id FROM il_meta_entity ".
150  "WHERE rbac_id = ".$ilDB->quote($a_rbac_id)." ".
151  "AND obj_id = ".$ilDB->quote($a_obj_id)." ".
152  "AND parent_id = ".$ilDB->quote($a_parent_id)." ".
153  "AND parent_type = ".$ilDB->quote($a_parent_type);
154 
155  $res = $ilDB->query($query);
156  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
157  {
158  $ids[] = $row->meta_entity_id;
159  }
160  return $ids ? $ids : array();
161  }
162 }
163 ?>