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/Migration/DBUpdate_426/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/Migration/DBUpdate_426/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/Migration/DBUpdate_426/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  $this->role = $a_role;
89  return true;
90 
91  default:
92  return false;
93  }
94  }
95  function getRole()
96  {
97  return $this->role;
98  }
99  function setDate($a_date)
100  {
101  $this->date = $a_date;
102  }
103  function getDate()
104  {
105  return $this->date;
106  }
107 
108 
109  function save()
110  {
111  if($this->db->autoExecute('il_meta_contribute',
112  $this->__getFields(),
114  {
115  $this->setMetaId($this->db->getLastInsertId());
116 
117  return $this->getMetaId();
118  }
119  return false;
120  }
121 
122  function update()
123  {
124  global $ilDB;
125 
126  if($this->getMetaId())
127  {
128  if($this->db->autoExecute('il_meta_contribute',
129  $this->__getFields(),
131  "meta_contribute_id = ".$ilDB->quote($this->getMetaId())))
132  {
133  return true;
134  }
135  }
136  return false;
137  }
138 
139  function delete()
140  {
141  global $ilDB;
142 
143  if($this->getMetaId())
144  {
145  $query = "DELETE FROM il_meta_contribute ".
146  "WHERE meta_contribute_id = ".$ilDB->quote($this->getMetaId());
147 
148  $this->db->query($query);
149 
150  foreach($this->getEntityIds() as $id)
151  {
152  $ent =& $this->getEntity($id);
153  $ent->delete();
154  }
155  return true;
156  }
157  return false;
158  }
159 
160 
161  function __getFields()
162  {
163  return array('rbac_id' => $this->getRBACId(),
164  'obj_id' => $this->getObjId(),
165  'obj_type' => ilUtil::prepareDBString($this->getObjType()),
166  'parent_type' => $this->getParentType(),
167  'parent_id' => $this->getParentId(),
168  'role' => ilUtil::prepareDBString($this->getRole()),
169  'date' => ilUtil::prepareDBString($this->getDate()));
170  }
171 
172  function read()
173  {
174  global $ilDB;
175 
176  include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDLanguageItem.php';
177 
178  if($this->getMetaId())
179  {
180  $query = "SELECT * FROM il_meta_contribute ".
181  "WHERE meta_contribute_id = ".$ilDB->quote($this->getMetaId());
182 
183  $res = $this->db->query($query);
184  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
185  {
186  $this->setRBACId($row->rbac_id);
187  $this->setObjId($row->obj_id);
188  $this->setObjType($row->obj_type);
189  $this->setParentId($row->parent_id);
190  $this->setParentType($row->parent_type);
191  $this->setRole(ilUtil::stripSlashes($row->role));
192  $this->setDate(ilUtil::stripSlashes($row->date));
193  }
194  }
195  return true;
196  }
197 
198  /*
199  * XML Export of all meta data
200  * @param object (xml writer) see class.ilMD2XML.php
201  *
202  */
203  function toXML(&$writer)
204  {
205  $writer->xmlStartTag('Contribute',array('Role' => $this->getRole()));
206 
207  // Entities
208  foreach($this->getEntityIds() as $id)
209  {
210  $ent =& $this->getEntity($id);
211  $ent->toXML($writer);
212  }
213  $writer->xmlElement('Date',null,$this->getDate());
214  $writer->xmlEndTag('Contribute');
215  }
216 
217 
218  // STATIC
219  function _getIds($a_rbac_id,$a_obj_id,$a_parent_id,$a_parent_type)
220  {
221  global $ilDB;
222 
223  $query = "SELECT meta_contribute_id FROM il_meta_contribute ".
224  "WHERE rbac_id = ".$ilDB->quote($a_rbac_id)." ".
225  "AND obj_id = ".$ilDB->quote($a_obj_id)." ".
226  "AND parent_id = ".$ilDB->quote($a_parent_id)." ".
227  "AND parent_type = ".$ilDB->quote($a_parent_type);
228 
229  $res = $ilDB->query($query);
230  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
231  {
232  $ids[] = $row->meta_contribute_id;
233  }
234  return $ids ? $ids : array();
235  }
236 }
237 ?>
setObjType($a_type)
& getEntity($a_entity_id)
static _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
_getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
setMetaId($a_meta_id, $a_read_data=true)
setObjId($a_id)
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
setRBACId($a_id)
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
Create styles array
The data for the language used.
setParentId($a_id)
static prepareDBString($a_str)
prepare a string for db writing (insert/update)
global $ilDB
setParentType($a_parent_type)