ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 // Subelements
37 public function &getEntityIds()
38 {
39 include_once 'Services/MetaData/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/MetaData/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/MetaData/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 case 'PointOfContact':
87 $this->role = $a_role;
88 return true;
89
90 default:
91 return false;
92 }
93 }
94 public function getRole()
95 {
96 return $this->role;
97 }
98 public function setDate($a_date)
99 {
100 $this->date = $a_date;
101 }
102 public function getDate()
103 {
104 return $this->date;
105 }
106
107
108 public function save()
109 {
110 global $ilDB;
111
112 $fields = $this->__getFields();
113 $fields['meta_contribute_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_contribute'));
114
115 if ($this->db->insert('il_meta_contribute', $fields)) {
116 $this->setMetaId($next_id);
117 return $this->getMetaId();
118 }
119 return false;
120 }
121
122 public function update()
123 {
124 global $ilDB;
125
126 if ($this->getMetaId()) {
127 if ($this->db->update(
128 'il_meta_contribute',
129 $this->__getFields(),
130 array("meta_contribute_id" => array('integer',$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(), 'integer');
145 $res = $ilDB->manipulate($query);
146
147 foreach ($this->getEntityIds() as $id) {
148 $ent = $this->getEntity($id);
149 $ent->delete();
150 }
151 return true;
152 }
153 return false;
154 }
155
156
157 public function __getFields()
158 {
159 return array('rbac_id' => array('integer',$this->getRBACId()),
160 'obj_id' => array('integer',$this->getObjId()),
161 'obj_type' => array('text',$this->getObjType()),
162 'parent_type' => array('text',$this->getParentType()),
163 'parent_id' => array('integer',$this->getParentId()),
164 'role' => array('text',$this->getRole()),
165 'c_date' => array('text',$this->getDate()));
166 }
167
168 public function read()
169 {
170 global $ilDB;
171
172 include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php';
173
174 if ($this->getMetaId()) {
175 $query = "SELECT * FROM il_meta_contribute " .
176 "WHERE meta_contribute_id = " . $ilDB->quote($this->getMetaId(), 'integer');
177
178 $res = $this->db->query($query);
179 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
180 $this->setRBACId($row->rbac_id);
181 $this->setObjId($row->obj_id);
182 $this->setObjType($row->obj_type);
183 $this->setParentId($row->parent_id);
184 $this->setParentType($row->parent_type);
185 $this->setRole($row->role);
186 $this->setDate($row->c_date);
187 }
188 }
189 return true;
190 }
191
192 /*
193 * XML Export of all meta data
194 * @param object (xml writer) see class.ilMD2XML.php
195 *
196 */
197 public function toXML(&$writer)
198 {
199 $writer->xmlStartTag('Contribute', array('Role' => $this->getRole()
200 ? $this->getRole()
201 : 'Author'));
202
203 // Entities
204 $entities = $this->getEntityIds();
205 foreach ($entities as $id) {
206 $ent =&$this->getEntity($id);
207 $ent->toXML($writer);
208 }
209 if (!count($entities)) {
210 include_once 'Services/MetaData/classes/class.ilMDEntity.php';
211 $ent = new ilMDEntity($this->getRBACId(), $this->getObjId());
212 $ent->toXML($writer);
213 }
214
215 $writer->xmlElement('Date', null, $this->getDate());
216 $writer->xmlEndTag('Contribute');
217 }
218
219
220 // STATIC
221 public static function _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
222 {
223 global $ilDB;
224
225 $query = "SELECT meta_contribute_id FROM il_meta_contribute " .
226 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
227 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
228 "AND parent_id = " . $ilDB->quote($a_parent_id, 'integer') . " " .
229 "AND parent_type = " . $ilDB->quote($a_parent_type, 'text');
230
231 $res = $ilDB->query($query);
232 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
233 $ids[] = $row->meta_contribute_id;
234 }
235 return $ids ? $ids : array();
236 }
237
249 public static function _lookupAuthors($a_rbac_id, $a_obj_id, $a_obj_type)
250 {
251 global $ilDB;
252
253 // Ask for 'author' later to use indexes
254 $query = "SELECT entity,ent.parent_type,role FROM il_meta_entity ent " .
255 "JOIN il_meta_contribute con ON ent.parent_id = con.meta_contribute_id " .
256 "WHERE ent.rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
257 "AND ent.obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " ";
258 $res = $ilDB->query($query);
259 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
260 if ($row->role == 'Author' and $row->parent_type == 'meta_contribute') {
261 $authors[] = trim($row->entity);
262 }
263 }
264 return $authors ? $authors : array();
265 }
266}
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
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 _lookupAuthors($a_rbac_id, $a_obj_id, $a_obj_type)
Lookup authors.
static _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)
if(!array_key_exists('StateId', $_REQUEST)) $id
$query
foreach($_POST as $key=> $value) $res
global $ilDB