ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
32include_once 'class.ilMDBase.php';
33
34class 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?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
setObjId($a_id)
setParentId($a_id)
setMetaId($a_meta_id, $a_read_data=true)
setObjType($a_type)
setRBACId($a_id)
setParentType($a_parent_type)
ilMDEntity($a_rbac_id=0, $a_obj_id=0, $a_obj_type='')
setEntity($a_entity)
toXML(&$writer)
_getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
static prepareDBString($a_str)
prepare a string for db writing (insert/update)
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
global $ilDB