ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilSoapRoleObjectXMLWriter.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
16 {
17  public string $xml = '';
18  private array $roles = [];
19  private string $role_type = '';
20 
21  public function __construct()
22  {
23  global $DIC;
24 
25  $ilUser = $DIC->user();
26 
28  }
29 
30  public function setObjects(array $roles): void
31  {
32  $this->roles = $roles;
33  }
34 
35  public function setType(string $type): void
36  {
37  $this->role_type = $type;
38  }
39 
40  public function start(): bool
41  {
42  global $DIC;
43 
44  $rbacreview = $DIC['rbacreview'];
45  if ($this->roles === []) {
46  return false;
47  }
48 
49  $this->buildHeader();
50 
51  foreach ($this->roles as $role) {
52  // if role type is not empty and does not match, then continue;
53  if (!empty($this->role_type) && strcasecmp($this->role_type, $role["role_type"]) !== 0) {
54  continue;
55  }
56  if ($rbacreview->isRoleDeleted($role["obj_id"])) {
57  continue;
58  }
59 
60  $attrs = [
61  'role_type' => ucwords($role["role_type"]),
62  'id' => "il_" . IL_INST_ID . "_role_" . $role["obj_id"]
63  ];
64 
65  $this->xmlStartTag("Role", $attrs);
66  $this->xmlElement('Title', null, $role["title"]);
67  $this->xmlElement('Description', null, $role["description"]);
68  $this->xmlElement('Translation', null, ilObjRole::_getTranslation($role["title"]));
69 
70  if ($ref_id = ilUtil::__extractRefId($role["title"])) {
71  $ownerObj = ilObjectFactory::getInstanceByRefId($ref_id, false);
72 
73  if (is_object($ownerObj)) {
74  $attrs = [
75  "obj_id" => implode(
76  '_',
77  [
78  "il",
79  IL_INST_ID,
80  $ownerObj->getType(),
81  $ownerObj->getId()
82  ]
83  ),
84  "ref_id" => $ownerObj->getRefId(),
85  "type" => $ownerObj->getType()
86  ];
87  $this->xmlStartTag('AssignedObject', $attrs);
88  $this->xmlElement('Title', null, $ownerObj->getTitle());
89  $this->xmlElement('Description', null, $ownerObj->getDescription());
91  $this->xmlEndTag('AssignedObject');
92  }
93  }
94  $this->xmlEndTag("Role");
95  }
96  $this->buildFooter();
97  return true;
98  }
99 
100  public function getXML(): string
101  {
102  return $this->xmlDumpMem(false);
103  }
104 
105  private function buildHeader(): void
106  {
107  $this->xmlSetDtdDef("<!DOCTYPE Roles PUBLIC \"-//ILIAS//DTD ILIAS Roles//EN\" \"" . ILIAS_HTTP_PATH . "/components/ILIAS/Export/xml/ilias_role_object_3_10.dtd\">");
108  $this->xmlSetGenCmt("Roles information of ilias system");
109  $this->xmlHeader();
110  $this->xmlStartTag('Roles');
111  }
112 
113  private function buildFooter(): void
114  {
115  $this->xmlEndTag('Roles');
116  }
117 }
const IL_INST_ID
Definition: constants.php:40
xmlSetGenCmt(string $genCmt)
Sets generated comment.
xmlEndTag(string $tag)
Writes an endtag.
xmlSetDtdDef(string $dtdDef)
Sets dtd definition.
$ref_id
Definition: ltiauth.php:66
static _getTranslation(string $a_role_title)
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
global $DIC
Definition: shib_login.php:25
xmlHeader()
Writes xml header.
__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)
XML writer class Class to simplify manual writing of xml documents.
xmlDumpMem(bool $format=true)
Returns xml document from memory.
static appendPathToObject(ilXmlWriter $writer, int $refid)
static __extractRefId(string $role_title)
extract ref id from role title, e.g.