ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilWebLinkXmlWriter.php
Go to the documentation of this file.
1 <?php
2 
3 declare(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->xmlSetGenCmt("WebLink Object");
61  $this->xmlHeader();
62  return true;
63  }
64 
68  protected function init(): void
69  {
70  $this->xmlClear();
71 
72  if (!$this->obj_id) {
73  throw new UnexpectedValueException('No obj_id given: ');
74  }
75  if (!$this->weblink = ilObjectFactory::getInstanceByObjId(
76  $this->obj_id,
77  false
78  )) {
79  throw new UnexpectedValueException(
80  'Invalid obj_id given: ' . $this->obj_id
81  );
82  }
83  if ($this->weblink->getType() != 'webr') {
84  throw new UnexpectedValueException(
85  'Invalid obj_id given. Object is not of type webr'
86  );
87  }
88  }
89 }
__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.
__construct(VocabulariesInterface $vocabularies)
xmlHeader()
Writes xml header.
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...
xmlClear()
clears xmlStr
Class ilObjLinkResource.