ILIAS  release_8 Revision v8.23
class.ilFolderXmlWriter.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
24 {
25  private bool $add_header;
26  private int $obj_id = 0;
27  private ?ilObject $folder = null;
28 
29  public function __construct(bool $a_add_header)
30  {
31  $this->add_header = $a_add_header;
33  }
34 
35  public function setObjId(int $a_obj_id): void
36  {
37  $this->obj_id = $a_obj_id;
38  }
39 
40  public function write(): void
41  {
42  $this->init();
43  if ($this->add_header) {
44  $this->buildHeader();
45  }
46  $this->xmlStartTag('Folder', ['Id' => $this->folder->getId()]);
47  $this->xmlElement('Title', [], $this->folder->getTitle());
48  $this->xmlElement('Description', [], $this->folder->getDescription());
50  $this->xmlEndTag('Folder');
51  }
52 
53  protected function buildHeader(): void
54  {
55  $this->xmlSetDtdDef("<!DOCTYPE WebLinks PUBLIC \"-//ILIAS//DTD WebLinkAdministration//EN\" \"" . ILIAS_HTTP_PATH . "/xml/ilias_fold_4_5.dtd\">");
56  $this->xmlSetGenCmt("Export of a ILIAS Folder");
57  $this->xmlHeader();
58  }
59 
60  protected function init(): void
61  {
62  $this->xmlClear();
63 
64  if (!$this->obj_id) {
65  throw new UnexpectedValueException('No obj_id given: ');
66  }
67  if (!$this->folder = ilObjectFactory::getInstanceByObjId($this->obj_id, false)) {
68  throw new UnexpectedValueException('Invalid obj_id given: ' . $this->obj_id);
69  }
70  if ($this->folder->getType() !== 'fold') {
71  throw new UnexpectedValueException('Invalid obj_id given. Object is not of type folder');
72  }
73  }
74 }
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.
xmlSetDtdDef(string $dtdDef)
Sets dtd definition.
static _exportContainerSortingSettings(ilXmlWriter $xml, int $obj_id)
sorting XML-export for all container objects
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlHeader()
Writes xml header.
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
__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)
xmlClear()
clears xmlStr
__construct(bool $a_add_header)