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