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
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/MetaData/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/MetaData/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/MetaData/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 case 'PointOfContact':
97 $this->role = $a_role;
98 return true;
99
100 default:
101 return false;
102 }
103 }
104 function getRole()
105 {
106 return $this->role;
107 }
108 function setDate($a_date)
109 {
110 $this->date = $a_date;
111 }
112 function getDate()
113 {
114 return $this->date;
115 }
116
117
118 function save()
119 {
120 global $ilDB;
121
122 $fields = $this->__getFields();
123 $fields['meta_contribute_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_contribute'));
124
125 if($this->db->insert('il_meta_contribute',$fields))
126 {
127 $this->setMetaId($next_id);
128 return $this->getMetaId();
129 }
130 return false;
131 }
132
133 function update()
134 {
135 global $ilDB;
136
137 if($this->getMetaId())
138 {
139 if($this->db->update('il_meta_contribute',
140 $this->__getFields(),
141 array("meta_contribute_id" => array('integer',$this->getMetaId()))))
142 {
143 return true;
144 }
145 }
146 return false;
147 }
148
149 function delete()
150 {
151 global $ilDB;
152
153 if($this->getMetaId())
154 {
155 $query = "DELETE FROM il_meta_contribute ".
156 "WHERE meta_contribute_id = ".$ilDB->quote($this->getMetaId() ,'integer');
157 $res = $ilDB->manipulate($query);
158
159 foreach($this->getEntityIds() as $id)
160 {
161 $ent = $this->getEntity($id);
162 $ent->delete();
163 }
164 return true;
165 }
166 return false;
167 }
168
169
170 function __getFields()
171 {
172 return array('rbac_id' => array('integer',$this->getRBACId()),
173 'obj_id' => array('integer',$this->getObjId()),
174 'obj_type' => array('text',$this->getObjType()),
175 'parent_type' => array('text',$this->getParentType()),
176 'parent_id' => array('integer',$this->getParentId()),
177 'role' => array('text',$this->getRole()),
178 'c_date' => array('text',$this->getDate()));
179 }
180
181 function read()
182 {
183 global $ilDB;
184
185 include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php';
186
187 if($this->getMetaId())
188 {
189 $query = "SELECT * FROM il_meta_contribute ".
190 "WHERE meta_contribute_id = ".$ilDB->quote($this->getMetaId() ,'integer');
191
192 $res = $this->db->query($query);
193 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
194 {
195 $this->setRBACId($row->rbac_id);
196 $this->setObjId($row->obj_id);
197 $this->setObjType($row->obj_type);
198 $this->setParentId($row->parent_id);
199 $this->setParentType($row->parent_type);
200 $this->setRole($row->role);
201 $this->setDate($row->c_date);
202 }
203 }
204 return true;
205 }
206
207 /*
208 * XML Export of all meta data
209 * @param object (xml writer) see class.ilMD2XML.php
210 *
211 */
212 function toXML(&$writer)
213 {
214 $writer->xmlStartTag('Contribute',array('Role' => $this->getRole()
215 ? $this->getRole()
216 : 'Author'));
217
218 // Entities
219 $entities = $this->getEntityIds();
220 foreach($entities as $id)
221 {
222 $ent =& $this->getEntity($id);
223 $ent->toXML($writer);
224 }
225 if(!count($entities))
226 {
227 include_once 'Services/MetaData/classes/class.ilMDEntity.php';
228 $ent = new ilMDEntity($this->getRBACId(),$this->getObjId());
229 $ent->toXML($writer);
230 }
231
232 $writer->xmlElement('Date',null,$this->getDate());
233 $writer->xmlEndTag('Contribute');
234 }
235
236
237 // STATIC
238 function _getIds($a_rbac_id,$a_obj_id,$a_parent_id,$a_parent_type)
239 {
240 global $ilDB;
241
242 $query = "SELECT meta_contribute_id FROM il_meta_contribute ".
243 "WHERE rbac_id = ".$ilDB->quote($a_rbac_id ,'integer')." ".
244 "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ".
245 "AND parent_id = ".$ilDB->quote($a_parent_id ,'integer')." ".
246 "AND parent_type = ".$ilDB->quote($a_parent_type ,'text');
247
248 $res = $ilDB->query($query);
249 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
250 {
251 $ids[] = $row->meta_contribute_id;
252 }
253 return $ids ? $ids : array();
254 }
255
267 public static function _lookupAuthors($a_rbac_id,$a_obj_id,$a_obj_type)
268 {
269 global $ilDB;
270
271 // Ask for 'author' later to use indexes
272 $query = "SELECT entity,ent.parent_type,role FROM il_meta_entity ent ".
273 "JOIN il_meta_contribute con ON ent.parent_id = con.meta_contribute_id ".
274 "WHERE ent.rbac_id = ".$ilDB->quote($a_rbac_id ,'integer')." ".
275 "AND ent.obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
276 $res = $ilDB->query($query);
277 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
278 {
279 if($row->role == 'Author' and $row->parent_type == 'meta_contribute')
280 {
281 $authors[] = trim($row->entity);
282 }
283 }
284 return $authors ? $authors : array();
285 }
286}
287?>
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)
static _lookupAuthors($a_rbac_id, $a_obj_id, $a_obj_type)
Lookup authors.
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)
global $ilDB