ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilMDLifecycle.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 ilMDLifecycle extends ilMDBase
35 {
36  function ilMDLifecycle($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 
44  {
45  $subs['Contribute'] = 'meta_contribute';
46 
47  return $subs;
48  }
49 
50  // Get subelemsts 'Contribute'
51  function &getContributeIds()
52  {
53  include_once 'Services/MetaData/classes/class.ilMDContribute.php';
54 
55  return ilMDContribute::_getIds($this->getRBACId(),$this->getObjId(),$this->getMetaId(),'meta_lifecycle');
56  }
57  function &getContribute($a_contribute_id)
58  {
59  include_once 'Services/MetaData/classes/class.ilMDContribute.php';
60 
61  if(!$a_contribute_id)
62  {
63  return false;
64  }
65  $con =& new ilMDContribute();
66  $con->setMetaId($a_contribute_id);
67 
68  return $con;
69  }
70  function &addContribute()
71  {
72  include_once 'Services/MetaData/classes/class.ilMDContribute.php';
73 
74  $con =& new ilMDContribute($this->getRBACId(),$this->getObjId(),$this->getObjType());
75  $con->setParentId($this->getMetaId());
76  $con->setParentType('meta_lifecycle');
77 
78  return $con;
79  }
80 
81 
82  // SET/GET
83  function setStatus($a_status)
84  {
85  switch($a_status)
86  {
87  case 'Draft':
88  case 'Final':
89  case 'Revised':
90  case 'Unavailable':
91  $this->status = $a_status;
92 
93  default:
94  return false;
95  }
96  }
97  function getStatus()
98  {
99  return $this->status;
100  }
101  function setVersion($a_version)
102  {
103  $this->version = $a_version;
104  }
105  function getVersion()
106  {
107  return $this->version;
108  }
109  function setVersionLanguage($lng_obj)
110  {
111  if(is_object($lng_obj))
112  {
113  $this->version_language =& $lng_obj;
114  }
115  }
116  function &getVersionLanguage()
117  {
118  return $this->version_language;
119  }
121  {
122  if(is_object($this->version_language))
123  {
124  return $this->version_language->getLanguageCode();
125  }
126  return false;
127  }
128 
129  function save()
130  {
131  global $ilDB;
132 
133  $fields = $this->__getFields();
134  $fields['meta_lifecycle_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_lifecycle'));
135 
136  if($this->db->insert('il_meta_lifecycle',$fields))
137  {
138  $this->setMetaId($next_id);
139  return $this->getMetaId();
140  }
141  return false;
142  }
143 
144  function update()
145  {
146  global $ilDB;
147 
148  if($this->getMetaId())
149  {
150  if($this->db->update('il_meta_lifecycle',
151  $this->__getFields(),
152  array("meta_lifecycle_id" => array('integer',$this->getMetaId()))))
153  {
154  return true;
155  }
156  }
157  return false;
158  }
159 
160  function delete()
161  {
162  global $ilDB;
163 
164  // Delete 'contribute'
165  foreach($this->getContributeIds() as $id)
166  {
167  $con = $this->getContribute($id);
168  $con->delete();
169  }
170 
171 
172  if($this->getMetaId())
173  {
174  $query = "DELETE FROM il_meta_lifecycle ".
175  "WHERE meta_lifecycle_id = ".$ilDB->quote($this->getMetaId() ,'integer');
176  $res = $ilDB->manipulate($query);
177  return true;
178  }
179  return false;
180  }
181 
182 
183  function __getFields()
184  {
185  return array('rbac_id' => array('integer',$this->getRBACId()),
186  'obj_id' => array('integer',$this->getObjId()),
187  'obj_type' => array('text',$this->getObjType()),
188  'lifecycle_status' => array('text',$this->getStatus()),
189  'meta_version' => array('text',$this->getVersion()),
190  'version_language' => array('text',$this->getVersionLanguageCode()));
191  }
192 
193  function read()
194  {
195  global $ilDB;
196 
197  include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php';
198 
199  if($this->getMetaId())
200  {
201  $query = "SELECT * FROM il_meta_lifecycle ".
202  "WHERE meta_lifecycle_id = ".$ilDB->quote($this->getMetaId() ,'integer');
203 
204  $res = $this->db->query($query);
205  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
206  {
207  $this->setRBACId($row->rbac_id);
208  $this->setObjId($row->obj_id);
209  $this->setObjType($row->obj_type);
210  $this->setStatus($row->lifecycle_status);
211  $this->setVersion($row->meta_version);
212  $this->setVersionLanguage(new ilMDLanguageItem($row->version_language));
213  }
214  }
215  return true;
216  }
217 
218  /*
219  * XML Export of all meta data
220  * @param object (xml writer) see class.ilMD2XML.php
221  *
222  */
223  function toXML(&$writer)
224  {
225  $writer->xmlStartTag('Lifecycle',array('Status' => $this->getStatus()
226  ? $this->getStatus()
227  : 'Draft'));
228  $writer->xmlElement('Version',array('Language' => $this->getVersionLanguageCode()
229  ? $this->getVersionLanguageCode()
230  : 'en'),
231  $this->getVersion());
232 
233  // contribute
234  $contributes = $this->getContributeIds();
235  foreach($contributes as $id)
236  {
237  $con =& $this->getContribute($id);
238  $con->toXML($writer);
239  }
240  if(!count($contributes))
241  {
242  include_once 'Services/MetaData/classes/class.ilMDContribute.php';
243  $con = new ilMDContribute($this->getRBACId(),$this->getObjId());
244  $con->toXML($writer);
245  }
246  $writer->xmlEndTag('Lifecycle');
247  }
248 
249 
250 
251  // STATIC
252  function _getId($a_rbac_id,$a_obj_id)
253  {
254  global $ilDB;
255 
256  $query = "SELECT meta_lifecycle_id FROM il_meta_lifecycle ".
257  "WHERE rbac_id = ".$ilDB->quote($a_rbac_id ,'integer')." ".
258  "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer');
259 
260 
261  $res = $ilDB->query($query);
262  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
263  {
264  return $row->meta_lifecycle_id;
265  }
266  return false;
267  }
268 }
269 ?>