ILIAS  release_8 Revision v8.24
class.ilECSCourseAttributes.php
Go to the documentation of this file.
1<?php
2
18declare(strict_types=1);
19
26{
27 private static ?array $instances = null;
28
29 private int $server_id ;
30 private int $mid;
31
32 private array $attributes = array();
33
35
39 public function __construct(int $a_server_id, int $a_mid)
40 {
41 global $DIC;
42
43 $this->db = $DIC->database();
44
45 $this->server_id = $a_server_id;
46 $this->mid = $a_mid;
47
48 $this->read();
49 }
50
54 public static function getInstance(int $a_server_id, int $a_mid): \ilECSCourseAttributes
55 {
56 $id = $a_server_id . '_' . $a_mid;
57 return self::$instances[$id] ?? (self::$instances[$id] = new ilECSCourseAttributes($a_server_id, $a_mid));
58 }
59
63 public function getAttributes(): array
64 {
65 return $this->attributes;
66 }
67
72 {
73 return $this->getAttributes()[0] ?? null;
74 }
75
79 public function getFirstAttributeName(): string
80 {
81 if ($this->getFirstAttribute() instanceof ilECSCourseAttribute) {
82 return $this->getFirstAttribute()->getName();
83 }
84 return '';
85 }
86
90 public function getAttributeSequence($a_last_attribute): array
91 {
92 if (!$a_last_attribute) {
93 return [];
94 }
95 $sequence = [];
96 foreach ($this->getAttributes() as $att) {
97 $sequence[] = $att->getName();
98 if ($a_last_attribute === $att->getName()) {
99 break;
100 }
101 }
102 return $sequence;
103 }
104
108 public function getUpperAttributes($a_name): array
109 {
110 $reverse_attributes = array_reverse($this->getAttributes());
111
112 $found = false;
113 $upper = array();
114 foreach ($reverse_attributes as $att) {
115 if ($att->getName() === $a_name) {
116 $found = true;
117 continue;
118 }
119 if ($found) {
120 $upper[] = $att->getName();
121 }
122 }
123 return array_reverse($upper);
124 }
125
129 public function getNextAttributeName(string $a_name): string
130 {
131 if (!$a_name) {
132 return $this->getFirstAttributeName();
133 }
134 $found = false;
135 foreach ($this->getAttributes() as $att) {
136 if ($a_name === $att->getName()) {
137 $found = true;
138 continue;
139 }
140 if ($found) {
141 return $att->getName();
142 }
143 }
144 return '';
145 }
146
150 public function getPreviousAttributeName(string $a_name): string
151 {
152 if (!$a_name) {
153 return '';
154 }
155 $found = false;
156 $reverse_attributes = array_reverse($this->getAttributes());
157 foreach ($reverse_attributes as $att) {
158 if ($a_name === $att->getName()) {
159 $found = true;
160 continue;
161 }
162 if ($found) {
163 return $att->getName();
164 }
165 }
166 return '';
167 }
168
172 public function getAttributeValues(): array
173 {
174 $values = array();
175 foreach ($this->getAttributes() as $att) {
176 $values[] = $att->getName();
177 }
178 return $values;
179 }
180
184 public function delete(): void
185 {
186 foreach ($this->getAttributes() as $att) {
187 $att->delete();
188 }
189 $this->attributes = [];
190 }
191
192
196 protected function read(): void
197 {
198 $this->attributes = [];
199
200 $query = 'SELECT * FROM ecs_crs_mapping_atts ' .
201 'WHERE sid = ' . $this->db->quote($this->server_id, 'integer') . ' ' .
202 'AND mid = ' . $this->db->quote($this->mid, 'integer') . ' ' .
203 'ORDER BY id';
204 $res = $this->db->query($query);
205 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
206 $this->attributes[] = new ilECSCourseAttribute((int) $row->id);
207 }
208 }
209}
$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.
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
$query