ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  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  function &getEntity($a_entity_id)
44  {
45  include_once 'Services/MetaData/classes/class.ilMDEntity.php';
46 
47  if(!$a_entity_id)
48  {
49  return false;
50  }
51  $ent = new ilMDEntity();
52  $ent->setMetaId($a_entity_id);
53 
54  return $ent;
55  }
56  function &addEntity()
57  {
58  include_once 'Services/MetaData/classes/class.ilMDEntity.php';
59 
60  $ent = new ilMDEntity($this->getRBACId(),$this->getObjId(),$this->getObjType());
61  $ent->setParentId($this->getMetaId());
62  $ent->setParentType('meta_contribute');
63 
64  return $ent;
65  }
66 
67  // SET/GET
68  function setRole($a_role)
69  {
70  switch($a_role)
71  {
72  case 'Author':
73  case 'Publisher':
74  case 'Unknown':
75  case 'Initiator':
76  case 'Terminator':
77  case 'Editor':
78  case 'GraphicalDesigner':
79  case 'TechnicalImplementer':
80  case 'ContentProvider':
81  case 'TechnicalValidator':
82  case 'EducationalValidator':
83  case 'ScriptWriter':
84  case 'InstructionalDesigner':
85  case 'SubjectMatterExpert':
86  case 'Creator':
87  case 'Validator':
88  case 'PointOfContact':
89  $this->role = $a_role;
90  return true;
91 
92  default:
93  return false;
94  }
95  }
96  function getRole()
97  {
98  return $this->role;
99  }
100  function setDate($a_date)
101  {
102  $this->date = $a_date;
103  }
104  function getDate()
105  {
106  return $this->date;
107  }
108 
109 
110  function save()
111  {
112  global $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  {
119  $this->setMetaId($next_id);
120  return $this->getMetaId();
121  }
122  return false;
123  }
124 
125  function update()
126  {
127  global $ilDB;
128 
129  if($this->getMetaId())
130  {
131  if($this->db->update('il_meta_contribute',
132  $this->__getFields(),
133  array("meta_contribute_id" => array('integer',$this->getMetaId()))))
134  {
135  return true;
136  }
137  }
138  return false;
139  }
140 
141  function delete()
142  {
143  global $ilDB;
144 
145  if($this->getMetaId())
146  {
147  $query = "DELETE FROM il_meta_contribute ".
148  "WHERE meta_contribute_id = ".$ilDB->quote($this->getMetaId() ,'integer');
149  $res = $ilDB->manipulate($query);
150 
151  foreach($this->getEntityIds() as $id)
152  {
153  $ent = $this->getEntity($id);
154  $ent->delete();
155  }
156  return true;
157  }
158  return false;
159  }
160 
161 
162  function __getFields()
163  {
164  return array('rbac_id' => array('integer',$this->getRBACId()),
165  'obj_id' => array('integer',$this->getObjId()),
166  'obj_type' => array('text',$this->getObjType()),
167  'parent_type' => array('text',$this->getParentType()),
168  'parent_id' => array('integer',$this->getParentId()),
169  'role' => array('text',$this->getRole()),
170  'c_date' => array('text',$this->getDate()));
171  }
172 
173  function read()
174  {
175  global $ilDB;
176 
177  include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php';
178 
179  if($this->getMetaId())
180  {
181  $query = "SELECT * FROM il_meta_contribute ".
182  "WHERE meta_contribute_id = ".$ilDB->quote($this->getMetaId() ,'integer');
183 
184  $res = $this->db->query($query);
185  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
186  {
187  $this->setRBACId($row->rbac_id);
188  $this->setObjId($row->obj_id);
189  $this->setObjType($row->obj_type);
190  $this->setParentId($row->parent_id);
191  $this->setParentType($row->parent_type);
192  $this->setRole($row->role);
193  $this->setDate($row->c_date);
194  }
195  }
196  return true;
197  }
198 
199  /*
200  * XML Export of all meta data
201  * @param object (xml writer) see class.ilMD2XML.php
202  *
203  */
204  function toXML(&$writer)
205  {
206  $writer->xmlStartTag('Contribute',array('Role' => $this->getRole()
207  ? $this->getRole()
208  : 'Author'));
209 
210  // Entities
211  $entities = $this->getEntityIds();
212  foreach($entities as $id)
213  {
214  $ent =& $this->getEntity($id);
215  $ent->toXML($writer);
216  }
217  if(!count($entities))
218  {
219  include_once 'Services/MetaData/classes/class.ilMDEntity.php';
220  $ent = new ilMDEntity($this->getRBACId(),$this->getObjId());
221  $ent->toXML($writer);
222  }
223 
224  $writer->xmlElement('Date',null,$this->getDate());
225  $writer->xmlEndTag('Contribute');
226  }
227 
228 
229  // STATIC
230  static function _getIds($a_rbac_id,$a_obj_id,$a_parent_id,$a_parent_type)
231  {
232  global $ilDB;
233 
234  $query = "SELECT meta_contribute_id FROM il_meta_contribute ".
235  "WHERE rbac_id = ".$ilDB->quote($a_rbac_id ,'integer')." ".
236  "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ".
237  "AND parent_id = ".$ilDB->quote($a_parent_id ,'integer')." ".
238  "AND parent_type = ".$ilDB->quote($a_parent_type ,'text');
239 
240  $res = $ilDB->query($query);
241  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
242  {
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 $ilDB;
262 
263  // Ask for 'author' later to use indexes
264  $query = "SELECT entity,ent.parent_type,role FROM il_meta_entity ent ".
265  "JOIN il_meta_contribute con ON ent.parent_id = con.meta_contribute_id ".
266  "WHERE ent.rbac_id = ".$ilDB->quote($a_rbac_id ,'integer')." ".
267  "AND ent.obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
268  $res = $ilDB->query($query);
269  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
270  {
271  if($row->role == 'Author' and $row->parent_type == 'meta_contribute')
272  {
273  $authors[] = trim($row->entity);
274  }
275  }
276  return $authors ? $authors : array();
277  }
278 }
279 ?>
setObjType($a_type)
& getEntity($a_entity_id)
static _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
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)
setObjId($a_id)
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
setRBACId($a_id)
Create styles array
The data for the language used.
setParentId($a_id)
global $ilDB
setParentType($a_parent_type)