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