ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilWebLinkXmlWriter.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 {
26  private bool $add_header = true;
27 
28  private int $obj_id = 0;
30 
31  public function __construct(bool $a_add_header)
32  {
33  $this->add_header = $a_add_header;
35  }
36 
37  public function setObjId(int $a_obj_id): void
38  {
39  $this->obj_id = $a_obj_id;
40  }
41 
45  public function write(): void
46  {
47  $this->init();
48  if ($this->add_header) {
49  $this->buildHeader();
50  }
51  $this->weblink->toXML($this);
52  }
53 
56  protected function buildHeader(): bool
57  {
58  $this->xmlSetGenCmt("WebLink Object");
59  $this->xmlHeader();
60  return true;
61  }
62 
66  protected function init(): void
67  {
68  $this->xmlClear();
69 
70  if (!$this->obj_id) {
71  throw new UnexpectedValueException('No obj_id given: ');
72  }
73  if (!$this->weblink = ilObjectFactory::getInstanceByObjId(
74  $this->obj_id,
75  false
76  )) {
77  throw new UnexpectedValueException(
78  'Invalid obj_id given: ' . $this->obj_id
79  );
80  }
81  if ($this->weblink->getType() != 'webr') {
82  throw new UnexpectedValueException(
83  'Invalid obj_id given. Object is not of type webr'
84  );
85  }
86  }
87 }
__construct(bool $a_add_header)
xmlSetGenCmt(string $genCmt)
Sets generated comment.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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)
xmlClear()
clears xmlStr