ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilMDContribute.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 ilMDContribute extends ilMDBase
35{
36 // Subelements
37 public function &getEntityIds()
38 {
39 include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDEntity.php';
40
41 return ilMDEntity::_getIds($this->getRBACId(), $this->getObjId(), $this->getMetaId(), 'meta_contribute');
42 }
43 public function &getEntity($a_entity_id)
44 {
45 include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDEntity.php';
46
47 if (!$a_entity_id) {
48 return false;
49 }
50 $ent = new ilMDEntity();
51 $ent->setMetaId($a_entity_id);
52
53 return $ent;
54 }
55 public function &addEntity()
56 {
57 include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDEntity.php';
58
59 $ent = new ilMDEntity($this->getRBACId(), $this->getObjId(), $this->getObjType());
60 $ent->setParentId($this->getMetaId());
61 $ent->setParentType('meta_contribute');
62
63 return $ent;
64 }
65
66 // SET/GET
67 public function setRole($a_role)
68 {
69 switch ($a_role) {
70 case 'Author':
71 case 'Publisher':
72 case 'Unknown':
73 case 'Initiator':
74 case 'Terminator':
75 case 'Editor':
76 case 'GraphicalDesigner':
77 case 'TechnicalImplementer':
78 case 'ContentProvider':
79 case 'TechnicalValidator':
80 case 'EducationalValidator':
81 case 'ScriptWriter':
82 case 'InstructionalDesigner':
83 case 'SubjectMatterExpert':
84 case 'Creator':
85 case 'Validator':
86 $this->role = $a_role;
87 return true;
88
89 default:
90 return false;
91 }
92 }
93 public function getRole()
94 {
95 return $this->role;
96 }
97 public function setDate($a_date)
98 {
99 $this->date = $a_date;
100 }
101 public function getDate()
102 {
103 return $this->date;
104 }
105
106
107 public function save()
108 {
109 if ($this->db->autoExecute(
110 'il_meta_contribute',
111 $this->__getFields(),
113 )) {
114 $this->setMetaId($this->db->getLastInsertId());
115
116 return $this->getMetaId();
117 }
118 return false;
119 }
120
121 public function update()
122 {
123 global $ilDB;
124
125 if ($this->getMetaId()) {
126 if ($this->db->autoExecute(
127 'il_meta_contribute',
128 $this->__getFields(),
130 "meta_contribute_id = " . $ilDB->quote($this->getMetaId())
131 )) {
132 return true;
133 }
134 }
135 return false;
136 }
137
138 public function delete()
139 {
140 global $ilDB;
141
142 if ($this->getMetaId()) {
143 $query = "DELETE FROM il_meta_contribute " .
144 "WHERE meta_contribute_id = " . $ilDB->quote($this->getMetaId());
145
146 $this->db->query($query);
147
148 foreach ($this->getEntityIds() as $id) {
149 $ent = &$this->getEntity($id);
150 $ent->delete();
151 }
152 return true;
153 }
154 return false;
155 }
156
157
158 public function __getFields()
159 {
160 return array('rbac_id' => $this->getRBACId(),
161 'obj_id' => $this->getObjId(),
162 'obj_type' => ilUtil::prepareDBString($this->getObjType()),
163 'parent_type' => $this->getParentType(),
164 'parent_id' => $this->getParentId(),
165 'role' => ilUtil::prepareDBString($this->getRole()),
166 'date' => ilUtil::prepareDBString($this->getDate()));
167 }
168
169 public function read()
170 {
171 global $ilDB;
172
173 include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDLanguageItem.php';
174
175 if ($this->getMetaId()) {
176 $query = "SELECT * FROM il_meta_contribute " .
177 "WHERE meta_contribute_id = " . $ilDB->quote($this->getMetaId());
178
179 $res = $this->db->query($query);
180 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
181 $this->setRBACId($row->rbac_id);
182 $this->setObjId($row->obj_id);
183 $this->setObjType($row->obj_type);
184 $this->setParentId($row->parent_id);
185 $this->setParentType($row->parent_type);
186 $this->setRole(ilUtil::stripSlashes($row->role));
187 $this->setDate(ilUtil::stripSlashes($row->date));
188 }
189 }
190 return true;
191 }
192
193 /*
194 * XML Export of all meta data
195 * @param object (xml writer) see class.ilMD2XML.php
196 *
197 */
198 public function toXML(&$writer)
199 {
200 $writer->xmlStartTag('Contribute', array('Role' => $this->getRole()));
201
202 // Entities
203 foreach ($this->getEntityIds() as $id) {
204 $ent = &$this->getEntity($id);
205 $ent->toXML($writer);
206 }
207 $writer->xmlElement('Date', null, $this->getDate());
208 $writer->xmlEndTag('Contribute');
209 }
210
211
212 // STATIC
213 public function _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
214 {
215 global $ilDB;
216
217 $query = "SELECT meta_contribute_id FROM il_meta_contribute " .
218 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id) . " " .
219 "AND obj_id = " . $ilDB->quote($a_obj_id) . " " .
220 "AND parent_id = " . $ilDB->quote($a_parent_id) . " " .
221 "AND parent_type = " . $ilDB->quote($a_parent_type);
222
223 $res = $ilDB->query($query);
224 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
225 $ids[] = $row->meta_contribute_id;
226 }
227 return $ids ? $ids : array();
228 }
229}
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)
_getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
& getEntity($a_entity_id)
static _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
if(!array_key_exists('StateId', $_REQUEST)) $id
$row
$query
foreach($_POST as $key=> $value) $res
global $ilDB