ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilGroupXMLWriter.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
26 public const int MODE_SOAP = 1;
27 public const int MODE_EXPORT = 2;
28 public const int EXPORT_VERSION = 3;
29
30 private int $mode = self::MODE_SOAP;
31
35
38 private bool $attach_users = true;
39
41 {
42 global $DIC;
43
44 $this->logger = $DIC->logger()->grp();
45 $this->settings = $DIC->settings();
46 $this->access = $DIC->access();
48 $this->group_obj = $group_obj;
49 $this->participants = ilGroupParticipants::_getInstanceByObjId($this->group_obj->getId());
50 }
51
52 public function setMode(int $a_mode): void
53 {
54 $this->mode = $a_mode;
55 }
56
57 public function getMode(): int
58 {
59 return $this->mode;
60 }
61
62 public function start(): void
63 {
64 if ($this->getMode() == self::MODE_SOAP) {
65 $this->logger->debug('Using soap mode');
66 $this->__buildHeader();
67 $this->__buildGroup();
70 $this->__buildRegistration();
71 $this->__buildExtraSettings();
72 if ($this->attach_users) {
73 $this->__buildAdmin();
74 $this->__buildMember();
75 }
77 ilContainer::_exportContainerSettings($this, $this->group_obj->getId());
78 $this->__buildFooter();
79 } elseif ($this->getMode() == self::MODE_EXPORT) {
80 $this->logger->debug('Using export mode');
81 $this->__buildGroup();
83 $this->__buildRegistration();
84 $this->__buildExtraSettings();
85 $this->__buildPeriod();
87 ilContainer::_exportContainerSettings($this, $this->group_obj->getId());
88 $this->__buildFooter();
89 }
90 }
91
92 public function getXML(): string
93 {
94 return $this->xmlDumpMem(false);
95 }
96
97 // PRIVATE
98 public function __buildHeader(): bool
99 {
100 $this->xmlSetDtdDef("<!DOCTYPE group PUBLIC \"-//ILIAS//DTD Group//EN\" \"" . ILIAS_HTTP_PATH . "/components/ILIAS/Export/xml/ilias_grp_9_0.xsd\">");
101 $this->xmlSetGenCmt("Export of ILIAS group " . $this->group_obj->getId() . " of installation " . $this->settings->get('inst_id') . ".");
102 $this->xmlHeader();
103 return true;
104 }
105
106 public function __buildGroup(): void
107 {
108 $attrs["exportVersion"] = self::EXPORT_VERSION;
109 $attrs["id"] = "il_" . $this->settings->get('inst_id') . '_grp_' . $this->group_obj->getId();
110
111 switch ($this->group_obj->readGroupStatus()) {
113 $attrs['type'] = 'open';
114 break;
115
117 default:
118 $attrs['type'] = 'closed';
119 break;
120 }
121 $this->xmlStartTag("group", $attrs);
122 }
123
124 private function __buildAdvancedMetaData(): void
125 {
126 ilAdvancedMDValues::_appendXMLByObjId($this, $this->group_obj->getId());
127 }
128
129
130 public function __buildTitleDescription(): void
131 {
132 $this->xmlElement('title', null, $this->group_obj->getTitle());
133
134 if ($desc = $this->group_obj->getDescription()) {
135 $this->xmlElement('description', null, $desc);
136 }
137
138 $attr['id'] = 'il_' . $this->settings->get('inst_id') . '_usr_' . $this->group_obj->getOwner();
139 $this->xmlElement('owner', $attr);
140
141 $this->xmlElement('information', null, $this->group_obj->getInformation());
142 }
143
147 protected function __buildPeriod(): void
148 {
149 if (!$this->group_obj->getStart() || !$this->group_obj->getEnd()) {
150 return;
151 }
152
153 $this->xmlStartTag(
154 'period',
155 [
156 'withTime' => $this->group_obj->getStartTimeIndication()
157 ]
158 );
159 $this->xmlElement(
160 'start',
161 null,
162 $this->group_obj->getStart()?->get(IL_CAL_UNIX)
163 );
164 $this->xmlElement(
165 'end',
166 null,
167 $this->group_obj->getEnd()->get(IL_CAL_UNIX) ?
168 $this->group_obj->getEnd()->get(IL_CAL_UNIX) :
169 null
170 );
171
172 $this->xmlEndTag('period');
173 }
174
175 public function __buildRegistration(): void
176 {
177 // registration type
178 switch ($this->group_obj->getRegistrationType()) {
180 $attrs['type'] = 'direct';
181 break;
183 $attrs['type'] = 'confirmation';
184 break;
186 $attrs['type'] = 'password';
187 break;
188
189 default:
191 $attrs['type'] = 'disabled';
192 break;
193 }
194 $attrs['waitingList'] = $this->group_obj->isWaitingListEnabled() ? 'Yes' : 'No';
195
196 $this->xmlStartTag('registration', $attrs);
197
198 if (strlen($pwd = $this->group_obj->getPassword())) {
199 $this->xmlElement('password', null, $pwd);
200 }
201
202
203 // limited registration period
204 if (!$this->group_obj->isRegistrationUnlimited()) {
205 $this->xmlStartTag('temporarilyAvailable');
206 $this->xmlElement('start', null, $this->group_obj->getRegistrationStart()->get(IL_CAL_UNIX));
207 $this->xmlElement('end', null, $this->group_obj->getRegistrationEnd()->get(IL_CAL_UNIX));
208 $this->xmlEndTag('temporarilyAvailable');
209 }
210
211 // max members
212 $attrs = array();
213 $attrs['enabled'] = $this->group_obj->isMembershipLimited() ? 'Yes' : 'No';
214 $this->xmlElement('maxMembers', $attrs, $this->group_obj->getMaxMembers());
215 $this->xmlElement('minMembers', null, $this->group_obj->getMinMembers());
216 $this->xmlElement('WaitingListAutoFill', null, (int) $this->group_obj->hasWaitingListAutoFill());
217 $this->xmlElement('CancellationEnd', null, ($this->group_obj->getCancellationEnd() && !$this->group_obj->getCancellationEnd()->isNull()) ? $this->group_obj->getCancellationEnd()->get(IL_CAL_UNIX) : null);
218
219 $this->xmlElement('mailMembersType', null, (string) $this->group_obj->getMailToMembersType());
220
221 $this->xmlElement(
222 'RegistrationAccessCode',
223 [
224 'enabled' => (int) $this->group_obj->isRegistrationAccessCodeEnabled(),
225 'code' => $this->group_obj->getRegistrationAccessCode()
226 ]
227 );
228
229 $this->xmlEndTag('registration');
230 }
231
235 public function __buildExtraSettings(): void
236 {
237 $this->xmlElement('showMembers', null, $this->group_obj->getShowMembers());
238 $this->xmlElement('admissionNotification', null, $this->group_obj->getAutoNotification() ? 1 : 0);
239
240 $this->xmlElement('ViewMode', null, ilObjGroup::lookupViewMode($this->group_obj->getId()));
241 $this->xmlElement(
242 'SessionLimit',
243 [
244 'active' => $this->group_obj->isSessionLimitEnabled() ? 1 : 0,
245 'previous' => $this->group_obj->getNumberOfPreviousSessions(),
246 'next' => $this->group_obj->getNumberOfNextSessions()
247 ]
248 );
249
250 $this->xmlElement('GroupMap', [
251 'enabled' => (int) $this->group_obj->getEnableGroupMap(),
252 'latitude' => $this->group_obj->getLatitude(),
253 'longitude' => $this->group_obj->getLongitude(),
254 'location_zoom' => $this->group_obj->getLocationZoom()
255 ]);
256 }
257
258 public function __buildAdmin(): void
259 {
260 $admins = $this->group_obj->getGroupAdminIds();
261 $admins = $this->access->filterUserIdsByRbacOrPositionOfCurrentUser(
262 'manage_members',
264 $this->group_obj->getRefId(),
265 $admins
266 );
267
268 foreach ($admins as $id) {
269 $attr['id'] = 'il_' . $this->settings->get('inst_id') . '_usr_' . $id;
270 $attr['notification'] = $this->participants->isNotificationEnabled($id) ? 'Yes' : 'No';
271
272 $this->xmlElement('admin', $attr);
273 }
274 }
275
276 public function __buildMember(): void
277 {
278 $members = $this->group_obj->getGroupMemberIds();
279 $members = $this->access->filterUserIdsByRbacOrPositionOfCurrentUser(
280 'manage_members',
282 $this->group_obj->getRefId(),
283 $members
284 );
285 foreach ($members as $id) {
286 if (!$this->group_obj->isAdmin($id)) {
287 $attr['id'] = 'il_' . $this->settings->get('inst_id') . '_usr_' . $id;
288
289 $this->xmlElement('member', $attr);
290 }
291 }
292 }
293
294 public function __buildFooter(): void
295 {
296 $this->xmlEndTag('group');
297 }
298
299 public function setAttachUsers(bool $value)
300 {
301 $this->attach_users = $value;
302 }
303}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
const IL_CAL_UNIX
static _appendXMLByObjId(ilXmlWriter $a_xml_writer, int $a_obj_id)
Get xml of object values.
static _exportContainerSortingSettings(ilXmlWriter $xml, int $obj_id)
sorting XML-export for all container objects
static _exportContainerSettings(ilXmlWriter $a_xml, int $a_obj_id)
static _getInstanceByObjId(int $a_obj_id)
Get singleton instance.
__buildExtraSettings()
Build extra settings, like "show member list".
ilGroupParticipants $participants
__construct(ilObjGroup $group_obj)
__buildPeriod()
Add group period settings to xml.
Component logger with individual log levels by component id.
Class ilObjGroup.
static lookupViewMode($a_obj_id)
ILIAS Setting Class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlSetGenCmt(string $genCmt)
Sets generated comment.
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
xmlHeader()
Writes xml header.
xmlEndTag(string $tag)
Writes an endtag.
xmlSetDtdDef(string $dtdDef)
Sets dtd definition.
xmlDumpMem(bool $format=true)
Returns xml document from memory.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26