ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilECSCourseAttributes.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
28 private static ?array $instances = null;
29
30 private int $server_id ;
31 private int $mid;
32
33 private array $attributes = array();
34
36
40 public function __construct(int $a_server_id, int $a_mid)
41 {
42 global $DIC;
43
44 $this->db = $DIC->database();
45
46 $this->server_id = $a_server_id;
47 $this->mid = $a_mid;
48
49 $this->read();
50 }
51
55 public static function getInstance(int $a_server_id, int $a_mid): \ilECSCourseAttributes
56 {
57 $id = $a_server_id . '_' . $a_mid;
58 return self::$instances[$id] ?? (self::$instances[$id] = new ilECSCourseAttributes($a_server_id, $a_mid));
59 }
60
64 public function getAttributes(): array
65 {
66 return $this->attributes;
67 }
68
73 {
74 return $this->getAttributes()[0] ?? null;
75 }
76
80 public function getFirstAttributeName(): string
81 {
82 if ($this->getFirstAttribute() instanceof ilECSCourseAttribute) {
83 return $this->getFirstAttribute()->getName();
84 }
85 return '';
86 }
87
91 public function getAttributeSequence($a_last_attribute): array
92 {
93 if (!$a_last_attribute) {
94 return [];
95 }
96 $sequence = [];
97 foreach ($this->getAttributes() as $att) {
98 $sequence[] = $att->getName();
99 if ($a_last_attribute === $att->getName()) {
100 break;
101 }
102 }
103 return $sequence;
104 }
105
109 public function getUpperAttributes($a_name): array
110 {
111 $reverse_attributes = array_reverse($this->getAttributes());
112
113 $found = false;
114 $upper = array();
115 foreach ($reverse_attributes as $att) {
116 if ($att->getName() === $a_name) {
117 $found = true;
118 continue;
119 }
120 if ($found) {
121 $upper[] = $att->getName();
122 }
123 }
124 return array_reverse($upper);
125 }
126
130 public function getNextAttributeName(string $a_name): string
131 {
132 if (!$a_name) {
133 return $this->getFirstAttributeName();
134 }
135 $found = false;
136 foreach ($this->getAttributes() as $att) {
137 if ($a_name === $att->getName()) {
138 $found = true;
139 continue;
140 }
141 if ($found) {
142 return $att->getName();
143 }
144 }
145 return '';
146 }
147
151 public function getPreviousAttributeName(string $a_name): string
152 {
153 if (!$a_name) {
154 return '';
155 }
156 $found = false;
157 $reverse_attributes = array_reverse($this->getAttributes());
158 foreach ($reverse_attributes as $att) {
159 if ($a_name === $att->getName()) {
160 $found = true;
161 continue;
162 }
163 if ($found) {
164 return $att->getName();
165 }
166 }
167 return '';
168 }
169
173 public function getAttributeValues(): array
174 {
175 $values = array();
176 foreach ($this->getAttributes() as $att) {
177 $values[] = $att->getName();
178 }
179 return $values;
180 }
181
185 public function delete(): void
186 {
187 foreach ($this->getAttributes() as $att) {
188 $att->delete();
189 }
190 $this->attributes = [];
191 }
192
193
197 protected function read(): void
198 {
199 $this->attributes = [];
200
201 $query = 'SELECT * FROM ecs_crs_mapping_atts ' .
202 'WHERE sid = ' . $this->db->quote($this->server_id, 'integer') . ' ' .
203 'AND mid = ' . $this->db->quote($this->mid, 'integer') . ' ' .
204 'ORDER BY id';
205 $res = $this->db->query($query);
206 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
207 $this->attributes[] = new ilECSCourseAttribute((int) $row->id);
208 }
209 }
210}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Storage of course attributes for assignment rules.
Storage of course attributes for assignment rules.
getFirstAttributeName()
Get first attribute name.
getPreviousAttributeName(string $a_name)
Get next attribute name in sequence.
getAttributeValues()
Get active attribute values.
getAttributeSequence($a_last_attribute)
Get attribute sequence.
getNextAttributeName(string $a_name)
Get next attribute name in sequence.
__construct(int $a_server_id, int $a_mid)
Constructor.
getUpperAttributes($a_name)
Get upper attributes in hierarchy.
getFirstAttribute()
Get first defined attribute.
getAttributes()
Get current attributes.
static getInstance(int $a_server_id, int $a_mid)
Get instance.
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26