ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilECSCourseMappingRule.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
11{
13 const SUBDIR_VALUE = 2;
14
15 private $rid;
16 private $sid;
17 private $mid;
18 private $attribute;
19 private $ref_id;
20 private $is_filter = false;
21 private $filter;
22 private $create_subdir = true;
24 private $directory = '';
25
26
31 public function __construct($a_rid = 0)
32 {
33 $this->rid = $a_rid;
34 $this->read();
35 }
36
42 public static function lookupLastExistingAttribute($a_sid,$a_mid,$a_ref_id)
43 {
44 global $ilDB;
45
46 $query = 'SELECT attribute FROM ecs_cmap_rule '.
47 'WHERE sid = '.$ilDB->quote($a_sid,'integer').' '.
48 'AND mid = '.$ilDB->quote($a_mid,'integer').' '.
49 'AND ref_id = '.$ilDB->quote($a_ref_id,'integer').' '.
50 'ORDER BY rid ';
51 $res = $ilDB->query($query);
52
53 $attributes = array();
54 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
55 {
56 $attributes = $row->attribute;
57 }
58 return $attributes;
59 }
60
66 public static function getRuleRefIds($a_sid, $a_mid)
67 {
68 global $ilDB;
69
70 $query = 'SELECT DISTINCT(ref_id) ref_id, rid FROM ecs_cmap_rule '.
71 'WHERE sid = '.$ilDB->quote($a_sid,'integer').' '.
72 'AND mid = '.$ilDB->quote($a_mid,'integer').' '.
73 'GROUP BY ref_id'.' '.
74 'ORDER BY rid';
75
76 $res = $ilDB->query($query);
77 $ref_ids = array();
78 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
79 {
80 $ref_ids[] = $row->ref_id;
81 }
82 return $ref_ids;
83 }
84
92 public static function getRulesOfRefId($a_sid, $a_mid, $a_ref_id)
93 {
94 global $ilDB;
95
96 $query = 'SELECT rid FROM ecs_cmap_rule '.
97 'WHERE sid = '.$ilDB->quote($a_sid,'integer').' '.
98 'AND mid = '.$ilDB->quote($a_mid,'integer').' '.
99 'AND ref_id = '.$ilDB->quote($a_ref_id,'integer');
100 $res = $ilDB->query($query);
101 $rids = array();
102 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
103 {
104 $rids = $row->rid;
105 }
106 return (array) $rids;
107 }
108
109 public static function hasRules($a_sid, $a_mid, $a_ref_id)
110 {
111 global $ilDB;
112
113 $query = 'SELECT ref_id FROM ecs_cmap_rule '.
114 'WHERE sid = '.$ilDB->quote($a_sid,'integer').' '.
115 'AND mid = '.$ilDB->quote($a_mid,'integer').' '.
116 'AND ref_id = '.$ilDB->quote($a_ref_id,'integer');
117 $res = $ilDB->query($query);
118 return $res->numRows() ? true : false;
119 }
120
126 public static function isMatching($course, $a_sid, $a_mid, $a_ref_id)
127 {
128 global $ilDB;
129
130 $query = 'SELECT rid FROM ecs_cmap_rule '.
131 'WHERE sid = '.$ilDB->quote($a_sid,'integer'). ' '.
132 'AND mid = '.$ilDB->quote($a_mid,'integer').' '.
133 'AND ref_id = '.$ilDB->quote($a_ref_id,'integer').' '.
134 'ORDER BY rid';
135 $res = $ilDB->query($query);
136 $matches = false;
137 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
138 {
139 $rule = new ilECSCourseMappingRule($row->rid);
140 if(!$rule->matches($course))
141 {
142 return false;
143 }
144 else
145 {
146 $matches = true;
147 }
148 }
149 return $matches;
150 }
151
159 public static function doMappings($course,$a_sid,$a_mid, $a_ref_id)
160 {
161 global $ilDB;
162
163 $query = 'SELECT rid FROM ecs_cmap_rule '.
164 'WHERE sid = '.$ilDB->quote($a_sid,'integer'). ' '.
165 'AND mid = '.$ilDB->quote($a_mid,'integer').' '.
166 'AND ref_id = '.$ilDB->quote($a_ref_id,'integer').' '.
167 'ORDER BY rid';
168 $res = $ilDB->query($query);
169
170 $first = true;
171 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
172 {
173 $rule = new ilECSCourseMappingRule($row->rid);
174 if($first)
175 {
176 $parent_ref = $rule->getRefId();
177 }
178 $parent_ref = $rule->doMapping($course,$parent_ref);
179 $first = false;
180 }
181 return $parent_ref;
182 }
183
189 public function doMapping($course,$parent_ref)
190 {
191 global $tree;
192
193 if(!$this->isSubdirCreationEnabled())
194 {
195 return $parent_ref;
196 }
197 include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSMappingUtils.php';
199
200 $childs = $tree->getChildsByType($parent_ref,'cat');
201
202 $existing_ref = 0;
203 foreach((array) $childs as $child)
204 {
205 if(strcmp($child['title'], $value) === 0)
206 {
207 $existing_ref = $child['child'];
208 break;
209 }
210 }
211 if(!$existing_ref)
212 {
213 // Create category
214 include_once './Modules/Category/classes/class.ilObjCategory.php';
215 $cat = new ilObjCategory();
216 $cat->setTitle($value);
217 $cat->create();
218 $cat->createReference();
219 $cat->putInTree($parent_ref);
220 $cat->setPermissions($parent_ref);
221 $cat->deleteTranslation($GLOBALS['lng']->getDefaultLanguage());
222 $cat->addTranslation(
223 $value,
224 $cat->getLongDescription(),
225 $GLOBALS['lng']->getDefaultLanguage(),
226 1
227 );
228 return $cat->getRefId();
229 }
230 return $existing_ref;
231 }
232
233
239 public function matches($course)
240 {
241 if($this->isFilterEnabled())
242 {
243 include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSMappingUtils.php';
245 $GLOBALS['ilLog']->write(__METHOD__.': Comparing '. $value . ' with ' . $this->getFilter());
246 return strcmp($value, $this->getFilter()) === 0;
247 }
248 return true;
249 }
250
251
261 public static function getInstanceByAttribute($a_sid,$a_mid,$a_ref_id,$a_att)
262 {
263 global $ilDB;
264
265 $query = 'SELECT rid FROM ecs_cmap_rule '.
266 'WHERE sid = '.$ilDB->quote($a_sid,'integer').' '.
267 'AND mid = '.$ilDB->quote($a_mid,'integer').' '.
268 'AND ref_id = '.$ilDB->quote($a_ref_id,'integer').' '.
269 'AND attribute = '.$ilDB->quote($a_att,'text');
270
271 $res = $ilDB->query($query);
272 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
273 {
274 return new ilECSCourseMappingRule($row->rid);
275 }
276 return new ilECSCourseMappingRule();
277 }
278
279 public function setRuleId($a_rule_id)
280 {
281 $this->rid = $a_rule_id;
282 }
283
284 public function getRuleId()
285 {
286 return $this->rid;
287 }
288
289 public function setServerId($a_server_id)
290 {
291 $this->sid = $a_server_id;
292 }
293
294 public function getServerId()
295 {
296 return $this->sid;
297 }
298
299 public function setMid($a_mid)
300 {
301 $this->mid = $a_mid;
302 }
303
304 public function getMid()
305 {
306 return $this->mid;
307 }
308
309 public function setAttribute($a_att)
310 {
311 $this->attribute = $a_att;
312 }
313
314 public function getAttribute()
315 {
316 return $this->attribute;
317 }
318
319 public function setRefId($a_ref_id)
320 {
321 $this->ref_id = $a_ref_id;
322 }
323
324 public function getRefId()
325 {
326 return $this->ref_id;
327 }
328
329 public function enableFilter($a_status)
330 {
331 $this->is_filter = $a_status;
332 }
333
334 public function isFilterEnabled()
335 {
336 return $this->is_filter;
337 }
338
339 public function setFilter($a_filter)
340 {
341 $this->filter = $a_filter;
342 }
343
344 public function getFilter()
345 {
346 return $this->filter;
347 }
348
349 public function enableSubdirCreation($a_stat)
350 {
351 $this->create_subdir = $a_stat;
352 }
353
354 public function isSubdirCreationEnabled()
355 {
357 }
358
359 public function setSubDirectoryType($a_type)
360 {
361 $this->subdir_type = $a_type;
362 }
363
364 public function getSubDirectoryType()
365 {
366 return self::SUBDIR_VALUE;
367 }
368
369 public function setDirectory($a_dir)
370 {
371 $this->directory = $a_dir;
372 }
373
374 public function getDirectory()
375 {
376 return $this->directory;
377 }
378
379 public function delete()
380 {
381 global $ilDB;
382
383 $query = 'DELETE from ecs_cmap_rule '.
384 'WHERE rid = '.$ilDB->quote($this->getRuleId(),'integer');
385 $ilDB->manipulate($query);
386 return true;
387 }
388
394 public function save()
395 {
396 global $ilDB;
397
398 $this->setRuleId($ilDB->nextId('ecs_cmap_rule'));
399 $query = 'INSERT INTO ecs_cmap_rule '.
400 '(rid,sid,mid,attribute,ref_id,is_filter,filter,create_subdir,subdir_type,directory) '.
401 'VALUES ('.
402 $ilDB->quote($this->getRuleId(),'integer').', '.
403 $ilDB->quote($this->getServerId(),'integer').', '.
404 $ilDB->quote($this->getMid(),'integer').', '.
405 $ilDB->quote($this->getAttribute(),'text').', '.
406 $ilDB->quote($this->getRefId(),'integer').', '.
407 $ilDB->quote($this->isFilterEnabled(),'integer').', '.
408 $ilDB->quote($this->getFilter(),'text').', '.
409 $ilDB->quote($this->isSubdirCreationEnabled(),'integer').', '.
410 $ilDB->quote($this->getSubDirectoryType(),'integer').', '.
411 $ilDB->quote($this->getDirectory(),'text').' '.
412 ')';
413 $ilDB->manipulate($query);
414 return $this->getRuleId();
415 }
416
421 public function update()
422 {
423 global $ilDB;
424
425 $query = 'UPDATE ecs_cmap_rule '.' '.
426 'SET '.
427 'attribute = '.$ilDB->quote($this->getAttribute(),'text').', '.
428 'ref_id = '.$ilDB->quote($this->getRefId(),'integer').', '.
429 'is_filter = '.$ilDB->quote($this->isFilterEnabled(),'integer').', '.
430 'filter = '.$ilDB->quote($this->getFilter(),'text').', '.
431 'create_subdir = '.$ilDB->quote($this->isSubdirCreationEnabled(),'integer').', '.
432 'subdir_type = '.$ilDB->quote($this->getSubDirectoryType(),'integer').', '.
433 'directory = '.$ilDB->quote($this->getDirectory(),'text').' '.
434 'WHERE rid = '.$ilDB->quote($this->getRuleId(),'integer');
435 $ilDB->manipulate($query);
436 }
437
441 protected function read()
442 {
443 global $ilDB;
444
445 if(!$this->getRuleId())
446 {
447 return true;
448 }
449 $query = 'SELECT * from ecs_cmap_rule '.' '.
450 'WHERE rid = '.$ilDB->quote($this->getRuleId(),'integer');
451 $res = $ilDB->query($query);
452 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
453 {
454 $this->setServerId($row->sid);
455 $this->setMid($row->mid);
456 $this->setRefId($row->ref_id);
457 $this->setAttribute($row->attribute);
458 $this->enableFilter($row->is_filter);
459 $this->setFilter($row->filter);
460 $this->enableSubdirCreation($row->create_subdir);
461 $this->setSubDirectoryType($row->subdir_type);
462 $this->setDirectory($row->directory);
463 }
464 }
465}
466?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
static isMatching($course, $a_sid, $a_mid, $a_ref_id)
Check if rule matches.
static lookupLastExistingAttribute($a_sid, $a_mid, $a_ref_id)
Lookup existing attributes.
save()
Save a new rule @global type $ilDB.
static hasRules($a_sid, $a_mid, $a_ref_id)
doMapping($course, $parent_ref)
Do mapping.
static getRulesOfRefId($a_sid, $a_mid, $a_ref_id)
Get all rule of ref_id @global type $ilDB.
matches($course)
Check if rule matches.
static doMappings($course, $a_sid, $a_mid, $a_ref_id)
static getInstanceByAttribute($a_sid, $a_mid, $a_ref_id, $a_att)
Get rule instance by attribute @global type $ilDB.
static getRuleRefIds($a_sid, $a_mid)
update()
Update mapping rule @global type $ilDB.
static getCourseValueByMappingAttribute($course, $a_field)
Get course value by mapping.
Class ilObjCategory.
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
global $ilDB