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