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