ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
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->xmlSetGenCmt("Export of a ILIAS Folder");
56  $this->xmlHeader();
57  }
58 
59  protected function init(): void
60  {
61  $this->xmlClear();
62 
63  if (!$this->obj_id) {
64  throw new UnexpectedValueException('No obj_id given: ');
65  }
66  if (!$this->folder = ilObjectFactory::getInstanceByObjId($this->obj_id, false)) {
67  throw new UnexpectedValueException('Invalid obj_id given: ' . $this->obj_id);
68  }
69  if ($this->folder->getType() !== 'fold') {
70  throw new UnexpectedValueException('Invalid obj_id given. Object is not of type folder');
71  }
72  }
73 }
xmlSetGenCmt(string $genCmt)
Sets generated comment.
xmlEndTag(string $tag)
Writes an endtag.
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)