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