ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilECSCategoryMappingRule.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
24include_once './Services/Calendar/classes/class.ilDate.php';
25
36{
37 const ATTR_STRING = 1;
38 const ATTR_INT = 2;
39 const ATTR_ARRAY = 3;
40
41 const TYPE_FIXED = 0;
42 const TYPE_DURATION = 1;
43 const TYPE_BY_TYPE = 2;
44
45 const ERR_MISSING_VALUE = 'ecs_err_missing_value';
46 const ERR_INVALID_DATES = 'ecs_err_invalid_dates';
47 const ERR_INVALID_TYPE = 'ecs_err_invalid_type';
48 const ERR_MISSING_BY_TYPE = 'ecs_err_invalid_by_type';
49
50 protected $db;
51
52 private $mapping_id;
54 private $field_name;
59 private $by_type;
60
65 public function __construct($a_mapping_id = 0)
66 {
67 global $DIC;
68
69 $ilDB = $DIC['ilDB'];
70
71 $this->mapping_id = $a_mapping_id;
72
73 $this->db = $ilDB;
74 $this->read();
75 }
76
82 protected function setMappingId($a_id)
83 {
84 $this->mapping_id = $a_id;
85 }
86
91 public function getMappingId()
92 {
93 return $this->mapping_id;
94 }
95
101 public function setContainerId($a_id)
102 {
103 $this->container_id = $a_id;
104 }
105
110 public function getContainerId()
111 {
112 return $this->container_id;
113 }
114
120 public function setDateRangeStart($start)
121 {
122 $this->range_dt_start = $start;
123 }
124
129 public function getDateRangeStart()
130 {
131 return $this->range_dt_start ? $this->range_dt_start : new ilDate(time(), IL_CAL_UNIX);
132 }
133
139 public function setDateRangeEnd($end)
140 {
141 $this->range_dt_end = $end;
142 }
143
148 public function getDateRangeEnd()
149 {
150 if ($this->range_dt_end) {
151 return $this->range_dt_end;
152 }
153 $this->range_dt_end = $this->getDateRangeStart();
154 $this->range_dt_end->increment(IL_CAL_MONTH, 6);
155 return $this->range_dt_end;
156 }
157
163 public function setFieldName($a_field)
164 {
165 $this->field_name = $a_field;
166 }
167
172 public function getFieldName()
173 {
174 return $this->field_name;
175 }
176
182 public function setMappingType($a_type)
183 {
184 $this->mapping_type = $a_type;
185 }
186
191 public function getMappingType()
192 {
193 return $this->mapping_type;
194 }
195
201 public function setMappingValue($a_value)
202 {
203 $this->mapping_value = $a_value;
204 }
205
210 public function getMappingValue()
211 {
213 }
214
219 public function getMappingAsArray()
220 {
221 return explode(',', $this->getMappingValue());
222 }
223
229 public function setByType($a_type)
230 {
231 $this->by_type = $a_type;
232 }
233
238 public function getByType()
239 {
240 return $this->by_type;
241 }
242
247 public function delete()
248 {
249 $sta = $this->db->manipulateF(
250 'DELETE FROM ecs_container_mapping WHERE mapping_id = %s ',
251 array('integer'),
252 array($this->getMappingId())
253 );
254 }
255
260 public function update()
261 {
262 if ($this->getMappingType() == self::TYPE_BY_TYPE) {
263 $mapping_value = $this->getByType();
264 } else {
266 }
267
268 $sta = $this->db->manipulateF(
269 'UPDATE ecs_container_mapping SET ' .
270 'container_id = %s, ' .
271 'field_name = %s, ' .
272 'mapping_type = %s, ' .
273 'mapping_value = %s, ' .
274 'date_range_start = %s,' .
275 'date_range_end = %s ' .
276 'WHERE mapping_id = %s',
277 array('integer','text','integer','text','integer','integer','integer'),
278 array(
279 $this->getContainerId(),
280 $this->getFieldName(),
281 $this->getMappingType(),
283 $this->getDateRangeStart()->get(IL_CAL_UNIX),
284 $this->getDateRangeEnd()->get(IL_CAL_UNIX),
285 $this->getMappingId())
286 );
287 }
288
293 public function save()
294 {
295 global $DIC;
296
297 $ilDB = $DIC['ilDB'];
298
299 if ($this->getMappingType() == self::TYPE_BY_TYPE) {
300 $mapping_value = $this->getByType();
301 } else {
303 }
304
305 $mapping_id = $ilDB->nextId('ecs_container_mapping');
306 $sta = $this->db->manipulateF(
307 'INSERT INTO ecs_container_mapping ' .
308 '(mapping_id,container_id,field_name,mapping_type,mapping_value,date_range_start,date_range_end) ' .
309 'VALUES(%s,%s,%s,%s,%s,%s,%s) ',
310 array('integer','integer','text','integer','text','integer','integer'),
311 array(
313 $this->getContainerId(),
314 $this->getFieldName(),
315 $this->getMappingType(),
317 $this->getDateRangeStart()->get(IL_CAL_UNIX),
318 $this->getDateRangeEnd()->get(IL_CAL_UNIX))
319 );
320 }
321
326 public function validate()
327 {
330 }
333 }
334 if ($this->getMappingType() == self::TYPE_DURATION && !in_array($this->getFieldName(), array('begin', 'end'))) {
336 }
337 // handled by form gui?
338 if ($this->getMappingType() == self::TYPE_FIXED and !$this->getMappingValue()) {
340 }
341 if ($this->getMappingType() == self::TYPE_BY_TYPE && $this->getFieldName() != 'type') {
343 }
344 if ($this->getMappingType() != self::TYPE_BY_TYPE && $this->getFieldName() == 'type') {
346 }
347 return 0;
348 }
349
354 public function conditionToString()
355 {
356 global $DIC;
357
358 $lng = $DIC['lng'];
359
360 switch ($this->getMappingType()) {
361 case self::TYPE_FIXED:
362
363 if ($this->getFieldName() == 'part_id') {
364 return $lng->txt('ecs_field_' . $this->getFieldName()) . ': ' . $this->participantsToString();
365 }
366 return $lng->txt('ecs_field_' . $this->getFieldName()) . ': ' . $this->getMappingValue();
367
369 return $lng->txt('ecs_field_' . $this->getFieldName()) . ': ' . ilDatePresentation::formatPeriod(
370 $this->getDateRangeStart(),
371 $this->getDateRangeEnd()
372 );
373
375 return $lng->txt('type') . ': ' . $lng->txt('obj_' . $this->getByType());
376 }
377 }
378
384 public function participantsToString()
385 {
386 include_once './Services/WebServices/ECS/classes/class.ilECSUtils.php';
387
388 $part_string = "";
389 $part = explode(',', $this->getMappingValue());
390 $counter = 0;
391 foreach ($part as $part_id) {
392 if ($counter++) {
393 $part_string .= ', ';
394 }
395 $part_string .= '"';
396
397 $part_id_arr = explode('_', $part_id);
398 if ($name = ilECSUtils::lookupParticipantName($part_id_arr[1], $part_id_arr[0])) {
399 $part_string .= $name;
400 } else {
401 $part_string .= $part_id;
402 }
403 $part_string .= '"';
404 }
405 return $part_string;
406 }
407
413 public function matches(array $a_matchable_content)
414 {
415 if (isset($a_matchable_content[$this->getFieldName()])) {
416 $value = $a_matchable_content[$this->getFieldName()];
417 return $this->matchesValue($value[0], $value[1]);
418 }
419 return false;
420 }
421
428 protected function matchesValue($a_value, $a_type)
429 {
430 global $DIC;
431
432 $ilLog = $DIC['ilLog'];
433
434
435 switch ($a_type) {
436 case self::ATTR_ARRAY:
437 $values = explode(',', $a_value);
438 $ilLog->write(__METHOD__ . ': Checking for value: ' . $a_value);
439 $ilLog->write(__METHOD__ . ': Checking against attribute values: ' . $this->getMappingValue());
440 break;
441
442 case self::ATTR_INT:
443 $ilLog->write(__METHOD__ . ': Checking for value: ' . $a_value);
444 $ilLog->write(__METHOD__ . ': Checking against attribute values: ' . $this->getMappingValue());
445 $values = array($a_value);
446 break;
447
449 $values = array($a_value);
450 break;
451 }
452 $values = explode(',', $a_value);
453
454 foreach ($values as $value) {
455 $value = trim($value);
456 switch ($this->getMappingType()) {
457 case self::TYPE_FIXED:
458
459 foreach ($this->getMappingAsArray() as $attribute_value) {
460 $attribute_value = trim($attribute_value);
461 if (strcasecmp($attribute_value, $value) == 0) {
462 return true;
463 }
464 }
465 break;
466
468 include_once './Services/Calendar/classes/class.ilDateTime.php';
469 $tmp_date = new ilDate($a_value, IL_CAL_UNIX);
470 return ilDateTime::_after($tmp_date, $this->getDateRangeStart()) and
471 ilDateTime::_before($tmp_date, $this->getDateRangeEnd());
472 }
473 }
474 return false;
475 }
476
481 protected function read()
482 {
483 if (!$this->getMappingId()) {
484 return false;
485 }
486 $res = $this->db->queryF(
487 'SELECT * FROM ecs_container_mapping WHERE mapping_id = %s',
488 array('integer'),
489 array($this->getMappingId())
490 );
491 while ($row = $this->db->fetchObject($res)) {
492 $this->setMappingId($row->mapping_id);
493 $this->setDateRangeStart($row->date_range_start ? new ilDate($row->date_range_start, IL_CAL_UNIX) : null);
494 $this->setDateRangeEnd($row->date_range_end ? new ilDate($row->date_range_end, IL_CAL_UNIX) : null);
495 $this->setMappingType($row->mapping_type);
496 $this->setFieldName($row->field_name);
497 $this->setContainerId($row->container_id);
498
499 if ($this->getMappingType() == self::TYPE_BY_TYPE) {
500 $this->setByType($row->mapping_value);
501 } else {
502 $this->setMappingValue($row->mapping_value);
503 }
504 }
505 return true;
506 }
507}
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
const IL_CAL_MONTH
const IL_CAL_DAY
static formatPeriod(ilDateTime $start, ilDateTime $end, $a_skip_starting_day=false)
Format a period of two date Shows: 14.
static _after(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
compare two dates and check start is after end This method does not consider tz offsets.
static _before(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
compare two dates and check start is before end This method does not consider tz offsets.
Class for single dates.
Defines a rule for the assignment of ECS remote courses to categories.
matchesValue($a_value, $a_type)
Check if value matches.
participantsToString()
get strong presentation of participants
setDateRangeStart($start)
set date range start
setByType($a_type)
set mapping by type
setMappingValue($a_value)
set mapping value
__construct($a_mapping_id=0)
Constructor.
matches(array $a_matchable_content)
Check if rule matches a specific econtent.
getMappingAsArray()
get mapping values as array
static lookupParticipantName($a_owner, $a_server_id)
Lookup participant name.
static _lookupObjId($a_id)
static _lookupType($a_id, $a_reference=false)
lookup object type
global $DIC
Definition: goto.php:24
if($format !==null) $name
Definition: metadata.php:230
$lng
foreach($_POST as $key=> $value) $res
global $ilDB