38 $this->logger =
$GLOBALS[
'DIC']->logger()->wsrv();
52 $query =
'SELECT attribute FROM ecs_cmap_rule '.
53 'WHERE sid = '.$ilDB->quote($a_sid,
'integer').
' '.
54 'AND mid = '.$ilDB->quote($a_mid,
'integer').
' '.
55 'AND ref_id = '.$ilDB->quote($a_ref_id,
'integer').
' '.
59 $attributes =
array();
62 $attributes =
$row->attribute;
76 $query =
'SELECT DISTINCT(ref_id) ref_id, rid FROM ecs_cmap_rule '.
77 'WHERE sid = '.$ilDB->quote($a_sid,
'integer').
' '.
78 'AND mid = '.$ilDB->quote($a_mid,
'integer').
' '.
79 'GROUP BY ref_id'.
' '.
86 $ref_ids[] =
$row->ref_id;
89 $checked_ref_ids = [];
93 $GLOBALS[
'DIC']->repositoryTree()->isInTree($ref_id))
98 return $checked_ref_ids;
113 $query =
'SELECT rid 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');
123 return (
array) $rids;
126 public static function hasRules($a_sid, $a_mid, $a_ref_id)
130 $query =
'SELECT ref_id 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');
135 return $res->numRows() ? true :
false;
144 public static function isMatching($course, $a_sid, $a_mid, $a_ref_id)
148 $query =
'SELECT rid FROM ecs_cmap_rule '.
149 'WHERE sid = '.$ilDB->quote($a_sid,
'integer').
' '.
150 'AND mid = '.$ilDB->quote($a_mid,
'integer').
' '.
151 'AND ref_id = '.$ilDB->quote($a_ref_id,
'integer').
' '.
156 $sortable_index =
'';
160 $matches = $rule->matches($course);
166 $sortable_index .= str_pad($matches, 4,
'0' ,STR_PAD_LEFT);
170 return $sortable_index;
183 public static function doMappings($course,$a_sid,$a_mid, $a_ref_id)
187 $query =
'SELECT rid FROM ecs_cmap_rule '.
188 'WHERE sid = '.$ilDB->quote($a_sid,
'integer').
' '.
189 'AND mid = '.$ilDB->quote($a_mid,
'integer').
' '.
190 'AND ref_id = '.$ilDB->quote($a_ref_id,
'integer').
' '.
195 $last_level_category =
array();
201 $last_level_category[] = $rule->getRefId();
204 $found_new_level =
false;
205 $new_level_cats =
array();
206 foreach((
array) $last_level_category as $cat_ref_id)
208 $refs = $rule->doMapping($course, $cat_ref_id);
209 foreach($refs as $new_ref_id)
211 $found_new_level =
true;
212 $new_level_cats[] = $new_ref_id;
217 $last_level_category = $new_level_cats;
222 return (
array) $last_level_category;
238 include_once
'./Services/WebServices/ECS/classes/Mapping/class.ilECSMappingUtils.php';
241 $childs = $tree->getChildsByType($parent_ref,
'cat');
242 foreach($values as $value)
245 foreach((
array) $childs as $child)
248 if(strcmp($child[
'title'], $value) === 0)
251 $category_references[] = $child[
'child'];
257 $category_references[] = $this->
createCategory($value, $parent_ref);
260 return (
array) $category_references;
270 include_once
'./Modules/Category/classes/class.ilObjCategory.php';
272 $cat->setOwner(SYSTEM_USER_ID);
273 $cat->setTitle($a_title);
275 $cat->createReference();
276 $cat->putInTree($a_parent_ref);
277 $cat->setPermissions($a_parent_ref);
278 $cat->deleteTranslation(
$GLOBALS[
'lng']->getDefaultLanguage());
279 $cat->addTranslation(
281 $cat->getLongDescription(),
282 $GLOBALS[
'lng']->getDefaultLanguage(),
285 return $cat->getRefId();
298 include_once
'./Services/WebServices/ECS/classes/Mapping/class.ilECSMappingUtils.php';
300 $this->logger->dump($values);
302 foreach($values as $value)
307 $this->logger->debug(
'Comparing ' . $value .
' with ' . $filter_element);
308 if(strcmp(trim($value), trim($filter_element)) === 0)
310 $this->logger->debug($value .
' matches ' . $filter_element);
311 $this->logger->debug(
'Found index: ' . $index);
335 $query =
'SELECT rid FROM ecs_cmap_rule '.
336 'WHERE sid = '.$ilDB->quote($a_sid,
'integer').
' '.
337 'AND mid = '.$ilDB->quote($a_mid,
'integer').
' '.
338 'AND ref_id = '.$ilDB->quote($a_ref_id,
'integer').
' '.
339 'AND attribute = '.$ilDB->quote($a_att,
'text');
351 $this->rid = $a_rule_id;
361 $this->sid = $a_server_id;
381 $this->attribute = $a_att;
391 $this->ref_id = $a_ref_id;
401 $this->is_filter = $a_status;
411 $this->filter = $a_filter;
426 $this->create_subdir = $a_stat;
441 return self::SUBDIR_VALUE;
454 public function delete()
458 $query =
'DELETE from ecs_cmap_rule '.
459 'WHERE rid = '.$ilDB->quote($this->
getRuleId(),
'integer');
460 $ilDB->manipulate(
$query);
473 $this->
setRuleId($ilDB->nextId(
'ecs_cmap_rule'));
474 $query =
'INSERT INTO ecs_cmap_rule '.
475 '(rid,sid,mid,attribute,ref_id,is_filter,filter,create_subdir,subdir_type,directory) '.
477 $ilDB->quote($this->
getRuleId(),
'integer').
', '.
479 $ilDB->quote($this->
getMid(),
'integer').
', '.
481 $ilDB->quote($this->
getRefId(),
'integer').
', '.
483 $ilDB->quote($this->
getFilter(),
'text').
', '.
488 $ilDB->manipulate($query);
500 $query =
'UPDATE ecs_cmap_rule '.
' '.
502 'attribute = '.$ilDB->quote($this->
getAttribute(),
'text').
', '.
503 'ref_id = '.$ilDB->quote($this->
getRefId(),
'integer').
', '.
505 'filter = '.$ilDB->quote($this->
getFilter(),
'text').
', '.
508 'directory = '.$ilDB->quote($this->
getDirectory(),
'text').
' '.
509 'WHERE rid = '.$ilDB->quote($this->
getRuleId(),
'integer');
510 $ilDB->manipulate(
$query);
524 $query =
'SELECT * from ecs_cmap_rule '.
' '.
525 'WHERE rid = '.$ilDB->quote($this->
getRuleId(),
'integer');
551 $escaped_filter = str_replace(
'\,',
'#:#',
$filter);
557 $replaced = str_replace(
'#:#',
',', $filter_element);
558 if(strlen(trim($replaced)))
560 $this->filter_elements[] = $replaced;
static getRulesOfRefId($a_sid, $a_mid, $a_ref_id)
Get all rule of ref_id type $ilDB.
static hasRules($a_sid, $a_mid, $a_ref_id)
static doMappings($course, $a_sid, $a_mid, $a_ref_id)
createCategory($a_title, $a_parent_ref)
Create attribute category.
static isMatching($course, $a_sid, $a_mid, $a_ref_id)
Check if rule matches.
static getCourseValueByMappingAttribute($course, $a_field)
Get course value by mapping.
isSubdirCreationEnabled()
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
enableSubdirCreation($a_stat)
save()
Save a new rule type $ilDB.
matches($course)
Check if rule matches.
setServerId($a_server_id)
const SUBDIR_ATTRIBUTE_NAME
setSubDirectoryType($a_type)
static lookupLastExistingAttribute($a_sid, $a_mid, $a_ref_id)
Lookup existing attributes.
update()
Update mapping rule type $ilDB.
static getRuleRefIds($a_sid, $a_mid)
Create styles array
The data for the language used.
static getInstanceByAttribute($a_sid, $a_mid, $a_ref_id, $a_att)
Get rule instance by attribute type $ilDB.
__construct($a_rid=0)
Constructor.
parseFilter()
Parse filter.
doMapping($course, $parent_ref)
Do mapping.