ILIAS  trunk Revision v11.0_alpha-1761-g6dbbfa7b760
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilMDOrComposite.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
29 {
30  private int $or_composite_id = 0;
31 
32  // SET/GET
33  public function setOrCompositeId(int $a_or_composite_id): void
34  {
35  $this->or_composite_id = $a_or_composite_id;
36  }
37 
38  public function getOrCompositeId(): int
39  {
40  if (!$this->or_composite_id) {
41  $query = "SELECT MAX(or_composite_id) orc FROM il_meta_requirement " .
42  "WHERE rbac_id = " . $this->db->quote($this->getRBACId(), 'integer') . " " .
43  "AND obj_id = " . $this->db->quote($this->getObjId(), 'integer') . " ";
44 
45  $res = $this->db->query($query);
46  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
47  $this->or_composite_id = (int) $row->orc;
48  }
50  }
52  }
53 
57  public function getRequirementIds(): array
58  {
60  $this->getRBACId(),
61  $this->getObjId(),
62  $this->getParentId(),
63  'meta_technical',
64  $this->getOrCompositeId()
65  );
66  }
67 
68  public function getRequirement(int $a_requirement_id): ?ilMDRequirement
69  {
70  if (!$a_requirement_id) {
71  return null;
72  }
73  $req = new ilMDRequirement();
74  $req->setMetaId($a_requirement_id);
75 
76  return $req;
77  }
78 
79  public function addRequirement(): ilMDRequirement
80  {
81  $req = new ilMDRequirement($this->getRBACId(), $this->getObjId(), $this->getObjType());
82  $req->setParentId($this->getParentId());
83  $req->setParentType('meta_technical');
84  $req->setOrCompositeId($this->getOrCompositeId());
85 
86  return $req;
87  }
88 
89  public function save(): int
90  {
91  echo 'Use ilMDOrcomposite::addRequirement()';
92  return 0;
93  }
94 
95  public function delete(): bool
96  {
97  foreach ($this->getRequirementIds() as $id) {
98  $req = $this->getRequirement($id);
99  $req->delete();
100  }
101  return true;
102  }
103 
104  public function toXML(ilXmlWriter $writer): void
105  {
106  // For all requirements
107  $writer->xmlStartTag('OrComposite');
108 
109  $reqs = $this->getRequirementIds();
110  foreach ($reqs as $id) {
111  $req = $this->getRequirement($id);
112  $req->toXML($writer);
113  }
114  if (!count($reqs)) {
115  $req = new ilMDRequirement($this->getRBACId(), $this->getObjId());
116  $req->toXML($writer);
117  }
118  $writer->xmlEndTag('OrComposite');
119  }
120 
121  // STATIC
122 
126  public static function _getIds(
127  int $a_rbac_id,
128  int $a_obj_id,
129  int $a_parent_id,
130  string $a_parent_type,
131  int $a_or_composite_id = 0
132  ): array {
133  global $DIC;
134 
135  $ilDB = $DIC->database();
136 
137  $query = "SELECT DISTINCT(or_composite_id) or_composite_id FROM il_meta_requirement " .
138  "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
139  "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
140  "AND parent_id = " . $ilDB->quote($a_parent_id, 'integer') . " " .
141  "AND parent_type = " . $ilDB->quote($a_parent_type, 'text') . " " .
142  "AND or_composite_id > 0 ";
143 
144  $res = $ilDB->query($query);
145  $ids = [];
146  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
147  $ids[] = (int) $row->or_composite_id;
148  }
149  return $ids;
150  }
151 }
$res
Definition: ltiservices.php:66
toXML(ilXmlWriter $writer)
setOrCompositeId(int $a_or_composite_id)
catch(\Exception $e) $req
Definition: xapiproxy.php:91
xmlEndTag(string $tag)
Writes an endtag.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type, int $a_or_composite_id=0)
global $DIC
Definition: shib_login.php:22
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
getRequirement(int $a_requirement_id)
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
static _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type, int $a_or_composite_id=0)