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