ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilContainerReferenceXmlWriter.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
27 {
28  public const MODE_SOAP = 1;
29  public const MODE_EXPORT = 2;
30 
31  protected ilSetting $settings;
32 
33  private int $mode = self::MODE_SOAP;
35 
36  public function __construct(?ilContainerReference $ref = null)
37  {
38  global $DIC;
39 
40  $this->settings = $DIC->settings();
42  $this->ref = $ref;
43  }
44 
45  public function setMode(int $a_mode): void
46  {
47  $this->mode = $a_mode;
48  }
49 
50  public function getMode(): int
51  {
52  return $this->mode;
53  }
54 
55  public function getReference(): ?ilContainerReference
56  {
57  return $this->ref;
58  }
59 
60  public function export(bool $a_with_header = true): void
61  {
62  if ($this->getMode() === self::MODE_EXPORT) {
63  if ($a_with_header) {
64  $this->buildHeader();
65  }
66  $this->buildReference();
67  $this->buildTarget();
68  $this->buildTitle();
69  $this->buildFooter();
70  }
71  }
72 
73  public function getXml(): string
74  {
75  return $this->xmlDumpMem(false);
76  }
77 
78  protected function buildHeader(): void
79  {
80  $this->xmlSetGenCmt("Export of ILIAS container reference " . $this->getReference()->getId() . " of installation " . $this->settings->get('inst_id') . ".");
81  $this->xmlHeader();
82  }
83 
84  protected function buildTarget(): void
85  {
86  $this->xmlElement('Target', ['id' => $this->getReference()->getTargetId()]);
87  }
88 
89  protected function buildTitle(): void
90  {
91  $title = '';
92  if ($this->getReference()->getTitleType() === ilContainerReference::TITLE_TYPE_CUSTOM) {
93  $title = $this->getReference()->getTitle();
94  }
95 
96  $this->xmlElement(
97  'Title',
98  [
99  'type' => $this->getReference()->getTitleType()
100  ],
101  $title
102  );
103  }
104 
105  protected function buildReference(): void
106  {
107  $this->xmlStartTag('ContainerReference');
108  }
109 
110  protected function buildFooter(): void
111  {
112  $this->xmlEndTag('ContainerReference');
113  }
114 }
xmlSetGenCmt(string $genCmt)
Sets generated comment.
xmlEndTag(string $tag)
Writes an endtag.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
global $DIC
Definition: shib_login.php:22
xmlHeader()
Writes xml header.
__construct(?ilContainerReference $ref=null)
__construct(Container $dic, ilPlugin $plugin)
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
xmlDumpMem(bool $format=true)
Returns xml document from memory.
Class for container reference export.