ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
5include_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 {
42 return self::$instances[$a_server_id.'_'.$a_mid];
43 }
44 return self::$instances[$a_server_id.'_'.$a_mid] = new ilECSCourseAttributes($a_server_id,$a_mid);
45 }
46
51 public function getAttributes()
52 {
53 return (array) $this->attributes;
54 }
55
60 public function getFirstAttribute()
61 {
62 foreach ($this->getAttributes() as $att)
63 {
64 return $att;
65 }
66 return NULL;
67 }
68
73 public function getFirstAttributeName()
74 {
75 if($this->getFirstAttribute() instanceof ilECSCourseAttribute)
76 {
77 return $this->getFirstAttribute()->getName();
78 }
79 return '';
80 }
81
87 public function getAttributeSequence($a_last_attribute)
88 {
89 if(!$a_last_attribute)
90 {
91 return array();
92 }
93 $sequence = array();
94 foreach ($this->getAttributes() as $att)
95 {
96 $sequence[] = $att->getName();
97 if($a_last_attribute == $att->getName())
98 {
99 break;
100 }
101 }
102 return $sequence;
103 }
104
109 public function getUpperAttributes($a_name)
110 {
111 $reverse_attributes = array_reverse($this->getAttributes());
112
113 $found = false;
114 $upper = array();
115 foreach ($reverse_attributes as $att)
116 {
117 if($att->getName() == $a_name)
118 {
119 $found = true;
120 continue;
121 }
122 if($found)
123 {
124 $upper[] = $att->getName();
125 }
126 }
127 return array_reverse($upper);
128 }
129
134 public function getNextAttributeName($a_name)
135 {
136 if(!$a_name)
137 {
138 return $this->getFirstAttributeName();
139 }
140 $found = false;
141 foreach($this->getAttributes() as $att)
142 {
143 if($a_name == $att->getName())
144 {
145 $found = true;
146 continue;
147 }
148 if($found)
149 {
150 return $att->getName();
151 }
152 }
153 return '';
154 }
155
160 public function getPreviousAttributeName($a_name)
161 {
162 if(!$a_name)
163 {
164 return '';
165 }
166 $found = false;
167 $reverse_attributes = array_reverse($this->getAttributes());
168 foreach($reverse_attributes as $att)
169 {
170 if($a_name == $att->getName())
171 {
172 $found = true;
173 continue;
174 }
175 if($found)
176 {
177 return $att->getName();
178 }
179 }
180 return '';
181 }
182
186 public function getAttributeValues()
187 {
188 $values = array();
189 foreach ($this->getAttributes() as $att)
190 {
191 $values[] = $att->getName();
192 }
193 return $values;
194 }
195
199 public function delete()
200 {
201 foreach($this->getAttributes() as $att)
202 {
203 $att->delete();
204 }
205 $this->attributes = array();
206 }
207
208
213 protected function read()
214 {
215 global $ilDB;
216
217 $this->attributes = array();
218
219 $query = 'SELECT * FROM ecs_crs_mapping_atts '.
220 'WHERE sid = '.$ilDB->quote($this->server_id,'integer').' '.
221 'AND mid = '.$ilDB->quote($this->mid,'integer').' '.
222 'ORDER BY id';
223 $res = $ilDB->query($query);
224 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
225 {
226 $this->attributes[] = new ilECSCourseAttribute($row->id);
227 }
228 }
229}
230?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
Storage of course attributes for assignment rules.
Storage of course attributes for assignment rules.
__construct($a_server_id, $a_mid)
Constructor.
getFirstAttributeName()
Get first attribute name.
getAttributeValues()
Get active attribute values.
static getInstance($a_server_id, $a_mid)
Get instance.
getNextAttributeName($a_name)
Get next attribute name in sequence.
getAttributeSequence($a_last_attribute)
Get attribute sequence.
getUpperAttributes($a_name)
Get upper attributes in hierarchy.
getFirstAttribute()
Get first defined attribute.
read()
Read attributes @global type $ilDB.
getAttributes()
Get current attributes.
getPreviousAttributeName($a_name)
Get next attribute name in sequence.
global $ilDB