ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ObjectDefinitionProcessor.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\ILIASObject\Setup;
22 
24 {
25  protected ?string $component;
26  protected ?string $current_object;
27 
28  public function __construct(
29  private readonly \ilDBInterface $db
30  ) {
31  }
32 
33  public function purge(): void
34  {
35  $this->db->manipulate("DELETE FROM il_object_def");
36  $this->db->manipulate("DELETE FROM il_object_subobj");
37  $this->db->manipulate("DELETE FROM il_object_group");
38  $this->db->manipulate("DELETE FROM il_object_sub_type");
39  }
40 
41  public function beginComponent(string $component, string $type): void
42  {
43  $this->component = $type . "/" . $component;
44  $this->current_object = null;
45  }
46 
47  public function endComponent(string $component, string $type): void
48  {
49  $this->component = null;
50  $this->current_object = null;
51  }
52 
53  public function beginTag(string $name, array $attributes): void
54  {
55  switch ($name) {
56  case 'object':
57 
58  // if attributes are not given, set default (repository only)
59  if (($attributes["repository"] ?? null) === null) {
60  $attributes["repository"] = true;
61  }
62  if (($attributes["workspace"] ?? null) === null) {
63  $attributes["workspace"] = false;
64  }
65 
66  $this->current_object = $attributes["id"];
67  $this->db->manipulateF(
68  "INSERT INTO il_object_def (id, class_name, component,location," .
69  "checkbox,inherit,translate,devmode,allow_link,allow_copy,rbac,default_pos," .
70  "default_pres_pos,sideblock,grp," . $this->db->quoteIdentifier("system") . ",export,repository,workspace,administration," .
71  "amet,orgunit_permissions,lti_provider,offline_handling) VALUES " .
72  "(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
73  ["text", "text", "text", "text", "integer", "integer", "text", "integer","integer","integer",
74  "integer","integer","integer","integer", "text", "integer", "integer", "integer", "integer",
75  'integer','integer','integer','integer','integer'],
76  [
77  $attributes["id"],
78  $attributes["class_name"],
80  $this->component . "/" . $attributes["dir"],
81  (int) ($attributes["checkbox"] ?? null),
82  (int) ($attributes["inherit"] ?? null),
83  $attributes["translate"] ?? null,
84  (int) ($attributes["devmode"] ?? null),
85  (int) ($attributes["allow_link"] ?? null),
86  (int) ($attributes["allow_copy"] ?? null),
87  (int) ($attributes["rbac"] ?? null),
88  (int) ($attributes["default_pos"] ?? null),
89  (int) ($attributes["default_pres_pos"] ?? null),
90  (int) ($attributes["sideblock"] ?? null),
91  $attributes["group"] ?? null,
92  (int) ($attributes["system"] ?? null),
93  (int) ($attributes["export"] ?? null),
94  (int) ($attributes["repository"] ?? null),
95  (int) ($attributes["workspace"] ?? null),
96  (int) ($attributes['administration'] ?? null),
97  (int) ($attributes['amet'] ?? null),
98  (int) ($attributes['orgunit_permissions'] ?? null),
99  (int) ($attributes['lti_provider'] ?? null),
100  (int) ($attributes['offline_handling'] ?? null)
101  ]
102  );
103  break;
104 
105  case "subobj":
106  $this->db->manipulateF(
107  "INSERT INTO il_object_subobj (parent, subobj, mmax) VALUES (%s,%s,%s)",
108  ["text", "text", "integer"],
109  [$this->current_object, $attributes["id"], (int) ($attributes["max"] ?? null)]
110  );
111  break;
112 
113  case "parent":
114  $this->db->manipulateF(
115  "INSERT INTO il_object_subobj (parent, subobj, mmax) VALUES (%s,%s,%s)",
116  ["text", "text", "integer"],
117  [$attributes["id"], $this->current_object, (int) ($attributes["max"] ?? null)]
118  );
119  break;
120 
121  case "objectgroup":
122  $this->db->manipulateF(
123  "INSERT INTO il_object_group (id, name, default_pres_pos) VALUES (%s,%s,%s)",
124  ["text", "text", "integer"],
125  [$attributes["id"], $attributes["name"], $attributes["default_pres_pos"]]
126  );
127  break;
128  case "sub_type":
129  $this->db->manipulate("INSERT INTO il_object_sub_type " .
130  "(obj_type, sub_type, amet) VALUES (" .
131  $this->db->quote($this->current_object, "text") . "," .
132  $this->db->quote($attributes["id"], "text") . "," .
133  $this->db->quote($attributes["amet"], "integer") .
134  ")");
135  break;
136  }
137  }
138 
139  public function endTag(string $name): void
140  {
141  }
142 }
beginComponent(string $component, string $type)
This method is called when parsing of component.xml for the given component starts.
An ilComponentDefinitionProcessor processes some attributes from a component.xml (i.e.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
beginTag(string $name, array $attributes)
This is called when a tag starts in the context of the given component.
endComponent(string $component, string $type)
This method is called when parsing of component.xml for the given component ends. ...
endTag(string $name)
This is called when a tag ends in the context of the given component.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Agent.php:19
purge()
This methods is supposed to purge existing data in the provider of the component, so new components c...