ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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->__buildTitleDescription();
88  $this->__buildRegistration();
89  $this->__buildExtraSettings();
90  $this->__buildPeriod();
91  ilContainerSortingSettings::_exportContainerSortingSettings($this, $this->group_obj->getId());
92  ilContainer::_exportContainerSettings($this, $this->group_obj->getId());
93  $this->__buildFooter();
94  }
95  }
96 
97  public function getXML(): string
98  {
99  return $this->xmlDumpMem(false);
100  }
101 
102  // PRIVATE
103  public function __buildHeader(): bool
104  {
105  $this->xmlSetDtdDef("<!DOCTYPE group PUBLIC \"-//ILIAS//DTD Group//EN\" \"" . ILIAS_HTTP_PATH . "/xml/ilias_grp_9_0.xsd\">");
106  $this->xmlSetGenCmt("Export of ILIAS group " . $this->group_obj->getId() . " of installation " . $this->settings->get('inst_id') . ".");
107  $this->xmlHeader();
108  return true;
109  }
110 
111  public function __buildGroup(): void
112  {
113  $attrs["exportVersion"] = self::EXPORT_VERSION;
114  $attrs["id"] = "il_" . $this->settings->get('inst_id') . '_grp_' . $this->group_obj->getId();
115 
116  switch ($this->group_obj->readGroupStatus()) {
118  $attrs['type'] = 'open';
119  break;
120 
122  default:
123  $attrs['type'] = 'closed';
124  break;
125  }
126  $this->xmlStartTag("group", $attrs);
127  }
128 
129  protected function __buildMetaData(): bool
130  {
131  $md2xml = new ilMD2XML($this->group_obj->getId(), $this->group_obj->getId(), 'grp');
132  $md2xml->startExport();
133  $this->appendXML($md2xml->getXML());
134  return true;
135  }
136 
137  private function __buildAdvancedMetaData(): void
138  {
139  ilAdvancedMDValues::_appendXMLByObjId($this, $this->group_obj->getId());
140  }
141 
142 
143  public function __buildTitleDescription(): void
144  {
145  $this->xmlElement('title', null, $this->group_obj->getTitle());
146 
147  if ($desc = $this->group_obj->getDescription()) {
148  $this->xmlElement('description', null, $desc);
149  }
150 
151  $attr['id'] = 'il_' . $this->settings->get('inst_id') . '_usr_' . $this->group_obj->getOwner();
152  $this->xmlElement('owner', $attr);
153 
154  $this->xmlElement('information', null, $this->group_obj->getInformation());
155  }
156 
160  protected function __buildPeriod(): void
161  {
162  if (!$this->group_obj->getStart() || !$this->group_obj->getEnd()) {
163  return;
164  }
165 
166  $this->xmlStartTag(
167  'period',
168  [
169  'withTime' => $this->group_obj->getStartTimeIndication()
170  ]
171  );
172  $this->xmlElement(
173  'start',
174  null,
175  $this->group_obj->getStart() ?
176  $this->group_obj->getStart()->get(IL_CAL_UNIX) :
177  null
178  );
179  $this->xmlElement(
180  'end',
181  null,
182  $this->group_obj->getEnd()->get(IL_CAL_UNIX) ?
183  $this->group_obj->getEnd()->get(IL_CAL_UNIX) :
184  null
185  );
186 
187  $this->xmlEndTag('period');
188  }
189 
190  public function __buildRegistration(): void
191  {
192  // registration type
193  switch ($this->group_obj->getRegistrationType()) {
195  $attrs['type'] = 'direct';
196  break;
198  $attrs['type'] = 'confirmation';
199  break;
201  $attrs['type'] = 'password';
202  break;
203 
204  default:
206  $attrs['type'] = 'disabled';
207  break;
208  }
209  $attrs['waitingList'] = $this->group_obj->isWaitingListEnabled() ? 'Yes' : 'No';
210 
211  $this->xmlStartTag('registration', $attrs);
212 
213  if (strlen($pwd = $this->group_obj->getPassword())) {
214  $this->xmlElement('password', null, $pwd);
215  }
216 
217 
218  // limited registration period
219  if (!$this->group_obj->isRegistrationUnlimited()) {
220  $this->xmlStartTag('temporarilyAvailable');
221  $this->xmlElement('start', null, $this->group_obj->getRegistrationStart()->get(IL_CAL_UNIX));
222  $this->xmlElement('end', null, $this->group_obj->getRegistrationEnd()->get(IL_CAL_UNIX));
223  $this->xmlEndTag('temporarilyAvailable');
224  }
225 
226  // max members
227  $attrs = array();
228  $attrs['enabled'] = $this->group_obj->isMembershipLimited() ? 'Yes' : 'No';
229  $this->xmlElement('maxMembers', $attrs, $this->group_obj->getMaxMembers());
230  $this->xmlElement('minMembers', null, $this->group_obj->getMinMembers());
231  $this->xmlElement('WaitingListAutoFill', null, (int) $this->group_obj->hasWaitingListAutoFill());
232  $this->xmlElement('CancellationEnd', null, ($this->group_obj->getCancellationEnd() && !$this->group_obj->getCancellationEnd()->isNull()) ? $this->group_obj->getCancellationEnd()->get(IL_CAL_UNIX) : null);
233 
234  $this->xmlElement('mailMembersType', null, (string) $this->group_obj->getMailToMembersType());
235 
236  $this->xmlElement(
237  'RegistrationAccessCode',
238  [
239  'enabled' => (int) $this->group_obj->isRegistrationAccessCodeEnabled(),
240  'code' => $this->group_obj->getRegistrationAccessCode()
241  ]
242  );
243 
244  $this->xmlEndTag('registration');
245  }
246 
250  public function __buildExtraSettings(): void
251  {
252  $this->xmlElement('showMembers', null, $this->group_obj->getShowMembers());
253  $this->xmlElement('admissionNotification', null, $this->group_obj->getAutoNotification() ? 1 : 0);
254 
255  $this->xmlElement('ViewMode', null, ilObjGroup::lookupViewMode($this->group_obj->getId()));
256  $this->xmlElement(
257  'SessionLimit',
258  [
259  'active' => $this->group_obj->isSessionLimitEnabled() ? 1 : 0,
260  'previous' => $this->group_obj->getNumberOfPreviousSessions(),
261  'next' => $this->group_obj->getNumberOfNextSessions()
262  ]
263  );
264 
265  $this->xmlElement('GroupMap', [
266  'enabled' => (int) $this->group_obj->getEnableGroupMap(),
267  'latitude' => $this->group_obj->getLatitude(),
268  'longitude' => $this->group_obj->getLongitude(),
269  'location_zoom' => $this->group_obj->getLocationZoom()
270  ]);
271  }
272 
273  public function __buildAdmin(): void
274  {
275  $admins = $this->group_obj->getGroupAdminIds();
276  $admins = $this->access->filterUserIdsByRbacOrPositionOfCurrentUser(
277  'manage_members',
279  $this->group_obj->getRefId(),
280  $admins
281  );
282 
283  foreach ($admins as $id) {
284  $attr['id'] = 'il_' . $this->settings->get('inst_id') . '_usr_' . $id;
285  $attr['notification'] = $this->participants->isNotificationEnabled($id) ? 'Yes' : 'No';
286 
287  $this->xmlElement('admin', $attr);
288  }
289  }
290 
291  public function __buildMember(): void
292  {
293  $members = $this->group_obj->getGroupMemberIds();
294  $members = $this->access->filterUserIdsByRbacOrPositionOfCurrentUser(
295  'manage_members',
297  $this->group_obj->getRefId(),
298  $members
299  );
300  foreach ($members as $id) {
301  if (!$this->group_obj->isAdmin($id)) {
302  $attr['id'] = 'il_' . $this->settings->get('inst_id') . '_usr_' . $id;
303 
304  $this->xmlElement('member', $attr);
305  }
306  }
307  }
308 
309  public function __buildFooter(): void
310  {
311  $this->xmlEndTag('group');
312  }
313 
314  public function setAttachUsers(bool $value)
315  {
316  $this->attach_users = $value;
317  }
318 }
__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
__construct(VocabulariesInterface $vocabularies)
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.
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.