ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 // SET/GET
37 public function setEntity($a_entity)
38 {
39 $this->entity = $a_entity;
40 }
41 public function getEntity()
42 {
43 return $this->entity;
44 }
45
46 public function save()
47 {
48 if ($this->db->autoExecute(
49 'il_meta_entity',
50 $this->__getFields(),
52 )) {
53 $this->setMetaId($this->db->getLastInsertId());
54
55 return $this->getMetaId();
56 }
57 return false;
58 }
59
60 public function update()
61 {
62 global $ilDB;
63
64 if ($this->getMetaId()) {
65 if ($this->db->autoExecute(
66 'il_meta_entity',
67 $this->__getFields(),
69 "meta_entity_id = " . $ilDB->quote($this->getMetaId())
70 )) {
71 return true;
72 }
73 }
74 return false;
75 }
76
77 public function delete()
78 {
79 global $ilDB;
80
81 if ($this->getMetaId()) {
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 public 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 public function read()
104 {
105 global $ilDB;
106
107 if ($this->getMetaId()) {
108 $query = "SELECT * FROM il_meta_entity " .
109 "WHERE meta_entity_id = " . $ilDB->quote($this->getMetaId());
110
111 $res = $this->db->query($query);
112 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
113 $this->setRBACId($row->rbac_id);
114 $this->setObjId($row->obj_id);
115 $this->setObjType($row->obj_type);
116 $this->setParentId($row->parent_id);
117 $this->setParentType($row->parent_type);
118 $this->setEntity(ilUtil::stripSlashes($row->entity));
119 }
120 }
121 return true;
122 }
123
124 /*
125 * XML Export of all meta data
126 * @param object (xml writer) see class.ilMD2XML.php
127 *
128 */
129 public function toXML(&$writer)
130 {
131 $writer->xmlElement('Entity', null, $this->getEntity());
132 }
133
134
135 // STATIC
136 public function _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
137 {
138 global $ilDB;
139
140 $query = "SELECT meta_entity_id FROM il_meta_entity " .
141 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id) . " " .
142 "AND obj_id = " . $ilDB->quote($a_obj_id) . " " .
143 "AND parent_id = " . $ilDB->quote($a_parent_id) . " " .
144 "AND parent_type = " . $ilDB->quote($a_parent_type);
145
146 $res = $ilDB->query($query);
147 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
148 $ids[] = $row->meta_entity_id;
149 }
150 return $ids ? $ids : array();
151 }
152}
An exception for terminatinating execution or to throw for unit testing.
setObjId($a_id)
setParentId($a_id)
setMetaId($a_meta_id, $a_read_data=true)
setObjType($a_type)
setRBACId($a_id)
setParentType($a_parent_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
$row
$query
foreach($_POST as $key=> $value) $res
global $ilDB