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 
43  // Get subelemsts 'Contribute'
44  function &getContributeIds()
45  {
46  include_once 'Services/Migration/DBUpdate_426/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/Migration/DBUpdate_426/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/Migration/DBUpdate_426/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  if($this->db->autoExecute('il_meta_lifecycle',
125  $this->__getFields(),
126  DB_AUTOQUERY_INSERT))
127  {
128  $this->setMetaId($this->db->getLastInsertId());
129 
130  return $this->getMetaId();
131  }
132  return false;
133  }
134 
135  function update()
136  {
137  global $ilDB;
138 
139  if($this->getMetaId())
140  {
141  if($this->db->autoExecute('il_meta_lifecycle',
142  $this->__getFields(),
143  DB_AUTOQUERY_UPDATE,
144  "meta_lifecycle_id = ".$ilDB->quote($this->getMetaId())))
145  {
146  return true;
147  }
148  }
149  return false;
150  }
151 
152  function delete()
153  {
154  global $ilDB;
155 
156  // Delete 'contribute'
157  foreach($this->getContributeIds() as $id)
158  {
159  $con = $this->getContribute($id);
160  $con->delete();
161  }
162 
163 
164  if($this->getMetaId())
165  {
166  $query = "DELETE FROM il_meta_lifecycle ".
167  "WHERE meta_lifecycle_id = ".$ilDB->quote($this->getMetaId());
168 
169  $this->db->query($query);
170 
171  return true;
172  }
173  return false;
174  }
175 
176 
177  function __getFields()
178  {
179  return array('rbac_id' => $this->getRBACId(),
180  'obj_id' => $this->getObjId(),
181  'obj_type' => ilUtil::prepareDBString($this->getObjType()),
182  'lifecycle_status' => ilUtil::prepareDBString($this->getStatus()),
183  'meta_version' => ilUtil::prepareDBString($this->getVersion()),
184  'version_language' => ilUtil::prepareDBString($this->getVersionLanguageCode()));
185  }
186 
187  function read()
188  {
189  global $ilDB;
190 
191  include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDLanguageItem.php';
192 
193  if($this->getMetaId())
194  {
195  $query = "SELECT * FROM il_meta_lifecycle ".
196  "WHERE meta_lifecycle_id = ".$ilDB->quote($this->getMetaId());
197 
198  $res = $this->db->query($query);
199  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
200  {
201  $this->setRBACId($row->rbac_id);
202  $this->setObjId($row->obj_id);
203  $this->setObjType($row->obj_type);
204  $this->setStatus(ilUtil::stripSlashes($row->lifecycle_status));
205  $this->setVersion(ilUtil::stripSlashes($row->meta_version));
206  $this->setVersionLanguage(new ilMDLanguageItem($row->version_language));
207  }
208  }
209  return true;
210  }
211 
212  /*
213  * XML Export of all meta data
214  * @param object (xml writer) see class.ilMD2XML.php
215  *
216  */
217  function toXML(&$writer)
218  {
219  $writer->xmlStartTag('Lifecycle',array('Status' => $this->getStatus()));
220  $writer->xmlElement('Version',array('Language' => $this->getVersionLanguageCode()),$this->getVersion());
221 
222  // contribute
223  foreach($this->getContributeIds() as $id)
224  {
225  $con =& $this->getContribute($id);
226  $con->toXML($writer);
227  }
228 
229  $writer->xmlEndTag('Lifecycle');
230  }
231 
232 
233 
234  // STATIC
235  function _getId($a_rbac_id,$a_obj_id)
236  {
237  global $ilDB;
238 
239  $query = "SELECT meta_lifecycle_id FROM il_meta_lifecycle ".
240  "WHERE rbac_id = ".$ilDB->quote($a_rbac_id)." ".
241  "AND obj_id = ".$ilDB->quote($a_obj_id);
242 
243 
244  $res = $ilDB->query($query);
245  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
246  {
247  return $row->meta_lifecycle_id;
248  }
249  return false;
250  }
251 }
252 ?>