ILIAS  release_8 Revision v8.23
class.ilCategoryXmlWriter.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
27 {
28  public const MODE_SOAP = 1;
29  public const MODE_EXPORT = 2;
30 
31  protected ilSetting $settings;
32  private int $mode = self::MODE_SOAP;
34 
35  public function __construct(ilObjCategory $cat = null)
36  {
37  global $DIC;
38 
39  $this->settings = $DIC->settings();
41 
42  $this->category = $cat;
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 getCategory(): ilObjCategory
56  {
57  return $this->category;
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->buildCategory();
67  $this->buildTranslations();
69  ilContainer::_exportContainerSettings($this, $this->category->getId());
70  $this->buildFooter();
71  }
72  }
73 
74  public function getXml(): string
75  {
76  return $this->xmlDumpMem(false);
77  }
78 
79  // Build xml header
80  protected function buildHeader(): bool
81  {
83 
84  $this->xmlSetDtdDef("<!DOCTYPE category PUBLIC \"-//ILIAS//DTD Group//EN\" \"" . ILIAS_HTTP_PATH . "/xml/ilias_cat_4_5.dtd\">");
85  $this->xmlSetGenCmt("Export of ILIAS category " . $this->getCategory()->getId() . " of installation " . $ilSetting->get('inst_id') . ".");
86  $this->xmlHeader();
87 
88  return true;
89  }
90 
91  // Build category start tag
92  protected function buildCategory(): void
93  {
94  $this->xmlStartTag('Category');
95  }
96 
97  // category end tag
98  protected function buildFooter(): void
99  {
100  $this->xmlEndTag('Category');
101  }
102 
103  // Add Translations
104  protected function buildTranslations(): void
105  {
106  $this->xmlStartTag('Translations');
107 
108  $translations = $this->getCategory()->getObjectTranslation()->getLanguages();
109  foreach ($translations as $translation) {
110  $this->xmlStartTag(
111  'Translation',
112  [
113  'default' => (int) $translation->isDefault(),
114  'language' => $translation->getLanguageCode()
115  ]
116  );
117  $this->xmlElement('Title', [], $translation->getTitle());
118  $this->xmlElement('Description', [], $translation->getDescription());
119  $this->xmlEndTag('Translation');
120  }
121  $this->xmlEndTag('Translations');
122  }
123 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilObjCategory $cat=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlSetGenCmt(string $genCmt)
Sets generated comment.
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
export(bool $a_with_header=true)
xmlHeader()
Writes xml header.
static _exportContainerSettings(ilXmlWriter $a_xml, int $a_obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $ilSetting
Definition: privfeed.php:17
__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.