ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCategoryXmlWriter.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
28 public const MODE_SOAP = 1;
29 public const MODE_EXPORT = 2;
30
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->xmlSetGenCmt("Export of ILIAS category " . $this->getCategory()->getId() . " of installation " . $ilSetting->get('inst_id') . ".");
85 $this->xmlHeader();
86
87 return true;
88 }
89
90 // Build category start tag
91 protected function buildCategory(): void
92 {
93 $this->xmlStartTag('Category');
94 }
95
96 // category end tag
97 protected function buildFooter(): void
98 {
99 $this->xmlEndTag('Category');
100 }
101
102 // Add Translations
103 protected function buildTranslations(): void
104 {
105 $this->xmlStartTag('Translations');
106
107 $translations = $this->getCategory()->getObjectTranslation()->getLanguages();
108 foreach ($translations as $translation) {
109 $this->xmlStartTag(
110 'Translation',
111 [
112 'default' => (int) $translation->isDefault(),
113 'language' => $translation->getLanguageCode()
114 ]
115 );
116 $this->xmlElement('Title', [], $translation->getTitle());
117 $this->xmlElement('Description', [], $translation->getDescription());
118 $this->xmlEndTag('Translation');
119 }
120 $this->xmlEndTag('Translations');
121 }
122}
Class for category export.
export(bool $a_with_header=true)
__construct(?ilObjCategory $cat=null)
static _exportContainerSortingSettings(ilXmlWriter $xml, int $obj_id)
sorting XML-export for all container objects
static _exportContainerSettings(ilXmlWriter $a_xml, int $a_obj_id)
Class ilObjCategory.
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.
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.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $ilSetting
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26