ILIAS  release_8 Revision v8.24
class.ilMDLifecycle.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
27{
29 private string $version = "";
30 private string $status = "";
31
35 public function getPossibleSubelements(): array
36 {
37 $subs['Contribute'] = 'meta_contribute';
38
39 return $subs;
40 }
41
45 public function getContributeIds(): array
46 {
47 return ilMDContribute::_getIds($this->getRBACId(), $this->getObjId(), $this->getMetaId(), 'meta_lifecycle');
48 }
49
50 public function getContribute(int $a_contribute_id): ?ilMDContribute
51 {
52 if (!$a_contribute_id) {
53 return null;
54 }
55 $con = new ilMDContribute();
56 $con->setMetaId($a_contribute_id);
57
58 return $con;
59 }
60
61 public function addContribute(): ilMDContribute
62 {
63 $con = new ilMDContribute($this->getRBACId(), $this->getObjId(), $this->getObjType());
64 $con->setParentId($this->getMetaId());
65 $con->setParentType('meta_lifecycle');
66
67 return $con;
68 }
69
70 // SET/GET
71 public function setStatus(string $a_status): void
72 {
73 switch ($a_status) {
74 case 'Draft':
75 case 'Final':
76 case 'Revised':
77 case 'Unavailable':
78 $this->status = $a_status;
79 break;
80 }
81 }
82
83 public function getStatus(): string
84 {
85 return $this->status;
86 }
87
88 public function setVersion(string $a_version): void
89 {
90 $this->version = $a_version;
91 }
92
93 public function getVersion(): string
94 {
95 return $this->version;
96 }
97
98 public function setVersionLanguage(ilMDLanguageItem $lng_obj): void
99 {
100 $this->version_language = $lng_obj;
101 }
102
104 {
106 }
107
108 public function getVersionLanguageCode(): string
109 {
110 return is_object($this->version_language) ? $this->version_language->getLanguageCode() : '';
111 }
112
113 public function save(): int
114 {
115 $fields = $this->__getFields();
116 $fields['meta_lifecycle_id'] = array('integer', $next_id = $this->db->nextId('il_meta_lifecycle'));
117
118 if ($this->db->insert('il_meta_lifecycle', $fields)) {
119 $this->setMetaId($next_id);
120 return $this->getMetaId();
121 }
122 return 0;
123 }
124
125 public function update(): bool
126 {
127 return $this->getMetaId() && $this->db->update(
128 'il_meta_lifecycle',
129 $this->__getFields(),
130 array("meta_lifecycle_id" => array('integer', $this->getMetaId()))
131 );
132 }
133
134 public function delete(): bool
135 {
136 // Delete 'contribute'
137 foreach ($this->getContributeIds() as $id) {
138 $con = $this->getContribute($id);
139 $con->delete();
140 }
141
142 if ($this->getMetaId()) {
143 $query = "DELETE FROM il_meta_lifecycle " .
144 "WHERE meta_lifecycle_id = " . $this->db->quote($this->getMetaId(), 'integer');
145 $res = $this->db->manipulate($query);
146 return true;
147 }
148 return false;
149 }
150
154 public function __getFields(): array
155 {
156 return array(
157 'rbac_id' => array('integer', $this->getRBACId()),
158 'obj_id' => array('integer', $this->getObjId()),
159 'obj_type' => array('text', $this->getObjType()),
160 'lifecycle_status' => array('text', $this->getStatus()),
161 'meta_version' => array('text', $this->getVersion()),
162 'version_language' => array('text', $this->getVersionLanguageCode())
163 );
164 }
165
166 public function read(): bool
167 {
168 if ($this->getMetaId()) {
169 $query = "SELECT * FROM il_meta_lifecycle " .
170 "WHERE meta_lifecycle_id = " . $this->db->quote($this->getMetaId(), 'integer');
171
172 $res = $this->db->query($query);
173 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
174 $this->setRBACId((int) $row->rbac_id);
175 $this->setObjId((int) $row->obj_id);
176 $this->setObjType($row->obj_type);
177 $this->setStatus((string) $row->lifecycle_status);
178 $this->setVersion((string) $row->meta_version);
179 $this->setVersionLanguage(new ilMDLanguageItem((string) $row->version_language));
180 }
181 }
182 return true;
183 }
184
185 public function toXML(ilXmlWriter $writer): void
186 {
187 $writer->xmlStartTag('Lifecycle', array(
188 'Status' => $this->getStatus() ?: 'Draft'
189 ));
190 $writer->xmlElement(
191 'Version',
192 array(
193 'Language' => $this->getVersionLanguageCode() ?: 'en'
194 ),
195 $this->getVersion()
196 );
197
198 // contribute
199 $contributes = $this->getContributeIds();
200 foreach ($contributes as $id) {
201 $con = $this->getContribute($id);
202 $con->toXML($writer);
203 }
204 if (!count($contributes)) {
205 $con = new ilMDContribute($this->getRBACId(), $this->getObjId());
206 $con->toXML($writer);
207 }
208 $writer->xmlEndTag('Lifecycle');
209 }
210
211 // STATIC
212 public static function _getId(int $a_rbac_id, int $a_obj_id): int
213 {
214 global $DIC;
215
216 $ilDB = $DIC->database();
217
218 $query = "SELECT meta_lifecycle_id FROM il_meta_lifecycle " .
219 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
220 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer');
221
222 $res = $ilDB->query($query);
223 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
224 return (int) $row->meta_lifecycle_id;
225 }
226 return 0;
227 }
228}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
setObjType(string $a_type)
setObjId(int $a_id)
setMetaId(int $a_meta_id, bool $a_read_data=true)
setRBACId(int $a_id)
static _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type)
toXML(ilXmlWriter $writer)
setVersionLanguage(ilMDLanguageItem $lng_obj)
ilMDLanguageItem $version_language
static _getId(int $a_rbac_id, int $a_obj_id)
getContribute(int $a_contribute_id)
setVersion(string $a_version)
setStatus(string $a_status)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
xmlEndTag(string $tag)
Writes an endtag.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
global $DIC
Definition: feed.php:28
$res
Definition: ltiservices.php:69
$query