ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  // SET/GET
37  function setEntity($a_entity)
38  {
39  $this->entity = $a_entity;
40  }
41  function getEntity()
42  {
43  return $this->entity;
44  }
45 
46  function save()
47  {
48  if($this->db->autoExecute('il_meta_entity',
49  $this->__getFields(),
51  {
52  $this->setMetaId($this->db->getLastInsertId());
53 
54  return $this->getMetaId();
55  }
56  return false;
57  }
58 
59  function update()
60  {
61  global $ilDB;
62 
63  if($this->getMetaId())
64  {
65  if($this->db->autoExecute('il_meta_entity',
66  $this->__getFields(),
68  "meta_entity_id = ".$ilDB->quote($this->getMetaId())))
69  {
70  return true;
71  }
72  }
73  return false;
74  }
75 
76  function delete()
77  {
78  global $ilDB;
79 
80  if($this->getMetaId())
81  {
82  $query = "DELETE FROM il_meta_entity ".
83  "WHERE meta_entity_id = ".$ilDB->quote($this->getMetaId());
84 
85  $this->db->query($query);
86 
87  return true;
88  }
89  return false;
90  }
91 
92 
93  function __getFields()
94  {
95  return array('rbac_id' => $this->getRBACId(),
96  'obj_id' => $this->getObjId(),
97  'obj_type' => ilUtil::prepareDBString($this->getObjType()),
98  'parent_type' => $this->getParentType(),
99  'parent_id' => $this->getParentId(),
100  'entity' => ilUtil::prepareDBString($this->getEntity()));
101  }
102 
103  function read()
104  {
105  global $ilDB;
106 
107  if($this->getMetaId())
108  {
109  $query = "SELECT * FROM il_meta_entity ".
110  "WHERE meta_entity_id = ".$ilDB->quote($this->getMetaId());
111 
112  $res = $this->db->query($query);
113  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
114  {
115  $this->setRBACId($row->rbac_id);
116  $this->setObjId($row->obj_id);
117  $this->setObjType($row->obj_type);
118  $this->setParentId($row->parent_id);
119  $this->setParentType($row->parent_type);
120  $this->setEntity(ilUtil::stripSlashes($row->entity));
121  }
122  }
123  return true;
124  }
125 
126  /*
127  * XML Export of all meta data
128  * @param object (xml writer) see class.ilMD2XML.php
129  *
130  */
131  function toXML(&$writer)
132  {
133  $writer->xmlElement('Entity',null,$this->getEntity());
134  }
135 
136 
137  // STATIC
138  function _getIds($a_rbac_id,$a_obj_id,$a_parent_id,$a_parent_type)
139  {
140  global $ilDB;
141 
142  $query = "SELECT meta_entity_id FROM il_meta_entity ".
143  "WHERE rbac_id = ".$ilDB->quote($a_rbac_id)." ".
144  "AND obj_id = ".$ilDB->quote($a_obj_id)." ".
145  "AND parent_id = ".$ilDB->quote($a_parent_id)." ".
146  "AND parent_type = ".$ilDB->quote($a_parent_type);
147 
148  $res = $ilDB->query($query);
149  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
150  {
151  $ids[] = $row->meta_entity_id;
152  }
153  return $ids ? $ids : array();
154  }
155 }
156 ?>
setObjType($a_type)
toXML(&$writer)
setMetaId($a_meta_id, $a_read_data=true)
setObjId($a_id)
_getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
setRBACId($a_id)
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
Create styles array
The data for the language used.
setParentId($a_id)
static prepareDBString($a_str)
prepare a string for db writing (insert/update)
global $ilDB
setParentType($a_parent_type)
setEntity($a_entity)