ILIAS  release_8 Revision v8.24
class.ilWebLinkXmlWriter.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
27{
28 private bool $add_header = true;
29
30 private int $obj_id = 0;
31 private ?ilObjLinkResource $weblink = null;
32
33 public function __construct(bool $a_add_header)
34 {
35 $this->add_header = $a_add_header;
37 }
38
39 public function setObjId(int $a_obj_id): void
40 {
41 $this->obj_id = $a_obj_id;
42 }
43
47 public function write(): void
48 {
49 $this->init();
50 if ($this->add_header) {
51 $this->buildHeader();
52 }
53 $this->weblink->toXML($this);
54 }
55
58 protected function buildHeader(): bool
59 {
60 $this->xmlSetDtdDef(
61 "<!DOCTYPE WebLinks PUBLIC \"-//ILIAS//DTD WebLinkAdministration//EN\" \"" . ILIAS_HTTP_PATH . "/xml/ilias_weblinks_5_1.dtd\">"
62 );
63 $this->xmlSetGenCmt("WebLink Object");
64 $this->xmlHeader();
65 return true;
66 }
67
71 protected function init(): void
72 {
73 $this->xmlClear();
74
75 if (!$this->obj_id) {
76 throw new UnexpectedValueException('No obj_id given: ');
77 }
78 if (!$this->weblink = ilObjectFactory::getInstanceByObjId(
79 $this->obj_id,
80 false
81 )) {
82 throw new UnexpectedValueException(
83 'Invalid obj_id given: ' . $this->obj_id
84 );
85 }
86 if ($this->weblink->getType() != 'webr') {
87 throw new UnexpectedValueException(
88 'Invalid obj_id given. Object is not of type webr'
89 );
90 }
91 }
92}
Class ilObjLinkResource.
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(bool $a_add_header)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlSetGenCmt(string $genCmt)
Sets generated comment.
xmlClear()
clears xmlStr
xmlHeader()
Writes xml header.
xmlSetDtdDef(string $dtdDef)
Sets dtd definition.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc