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