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