ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilECSCourseAttributes.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseAttribute.php';
6 
13 {
14  private static $instances = null;
15 
16  private $server_id = 0;
17  private $mid = 0;
18 
19  private $attributes = array();
20 
24  public function __construct($a_server_id, $a_mid)
25  {
26  $this->server_id = $a_server_id;
27  $this->mid = $a_mid;
28 
29  $this->read();
30  }
31 
38  public static function getInstance($a_server_id, $a_mid)
39  {
40  if (isset(self::$instances[$a_server_id . '_' . $a_mid])) {
41  return self::$instances[$a_server_id . '_' . $a_mid];
42  }
43  return self::$instances[$a_server_id . '_' . $a_mid] = new ilECSCourseAttributes($a_server_id, $a_mid);
44  }
45 
50  public function getAttributes()
51  {
52  return (array) $this->attributes;
53  }
54 
59  public function getFirstAttribute()
60  {
61  foreach ($this->getAttributes() as $att) {
62  return $att;
63  }
64  return null;
65  }
66 
71  public function getFirstAttributeName()
72  {
73  if ($this->getFirstAttribute() instanceof ilECSCourseAttribute) {
74  return $this->getFirstAttribute()->getName();
75  }
76  return '';
77  }
78 
84  public function getAttributeSequence($a_last_attribute)
85  {
86  if (!$a_last_attribute) {
87  return array();
88  }
89  $sequence = array();
90  foreach ($this->getAttributes() as $att) {
91  $sequence[] = $att->getName();
92  if ($a_last_attribute == $att->getName()) {
93  break;
94  }
95  }
96  return $sequence;
97  }
98 
103  public function getUpperAttributes($a_name)
104  {
105  $reverse_attributes = array_reverse($this->getAttributes());
106 
107  $found = false;
108  $upper = array();
109  foreach ($reverse_attributes as $att) {
110  if ($att->getName() == $a_name) {
111  $found = true;
112  continue;
113  }
114  if ($found) {
115  $upper[] = $att->getName();
116  }
117  }
118  return array_reverse($upper);
119  }
120 
125  public function getNextAttributeName($a_name)
126  {
127  if (!$a_name) {
128  return $this->getFirstAttributeName();
129  }
130  $found = false;
131  foreach ($this->getAttributes() as $att) {
132  if ($a_name == $att->getName()) {
133  $found = true;
134  continue;
135  }
136  if ($found) {
137  return $att->getName();
138  }
139  }
140  return '';
141  }
142 
147  public function getPreviousAttributeName($a_name)
148  {
149  if (!$a_name) {
150  return '';
151  }
152  $found = false;
153  $reverse_attributes = array_reverse($this->getAttributes());
154  foreach ($reverse_attributes as $att) {
155  if ($a_name == $att->getName()) {
156  $found = true;
157  continue;
158  }
159  if ($found) {
160  return $att->getName();
161  }
162  }
163  return '';
164  }
165 
169  public function getAttributeValues()
170  {
171  $values = array();
172  foreach ($this->getAttributes() as $att) {
173  $values[] = $att->getName();
174  }
175  return $values;
176  }
177 
181  public function delete()
182  {
183  foreach ($this->getAttributes() as $att) {
184  $att->delete();
185  }
186  $this->attributes = array();
187  }
188 
189 
194  protected function read()
195  {
196  global $DIC;
197 
198  $ilDB = $DIC['ilDB'];
199 
200  $this->attributes = array();
201 
202  $query = 'SELECT * FROM ecs_crs_mapping_atts ' .
203  'WHERE sid = ' . $ilDB->quote($this->server_id, 'integer') . ' ' .
204  'AND mid = ' . $ilDB->quote($this->mid, 'integer') . ' ' .
205  'ORDER BY id';
206  $res = $ilDB->query($query);
207  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
208  $this->attributes[] = new ilECSCourseAttribute($row->id);
209  }
210  }
211 }
global $DIC
Definition: saml.php:7
getAttributeValues()
Get active attribute values.
getFirstAttributeName()
Get first attribute name.
getAttributeSequence($a_last_attribute)
Get attribute sequence.
getFirstAttribute()
Get first defined attribute.
getAttributes()
Get current attributes.
getUpperAttributes($a_name)
Get upper attributes in hierarchy.
foreach($_POST as $key=> $value) $res
Storage of course attributes for assignment rules.
$values
static getInstance($a_server_id, $a_mid)
Get instance.
getPreviousAttributeName($a_name)
Get next attribute name in sequence.
read()
Read attributes type $ilDB.
$query
getNextAttributeName($a_name)
Get next attribute name in sequence.
$row
Storage of course attributes for assignment rules.
global $ilDB
__construct($a_server_id, $a_mid)
Constructor.