18 declare(strict_types=1);
48 $this->
logger = $DIC->logger()->wsrv();
49 $this->tree = $DIC->repositoryTree();
50 $this->
lng = $DIC->language();
51 $this->db = $DIC->database();
66 $query =
'SELECT attribute FROM ecs_cmap_rule ' .
67 'WHERE sid = ' .
$ilDB->quote($a_sid,
'integer') .
' ' .
68 'AND mid = ' .
$ilDB->quote($a_mid,
'integer') .
' ' .
69 'AND ref_id = ' .
$ilDB->quote($a_ref_id,
'integer') .
' ' .
89 $query =
'SELECT DISTINCT(ref_id) ref_id, rid FROM ecs_cmap_rule ' .
90 'WHERE sid = ' .
$ilDB->quote($a_sid,
'integer') .
' ' .
91 'AND mid = ' .
$ilDB->quote($a_mid,
'integer') .
' ' .
92 'GROUP BY ref_id' .
' ' .
98 $ref_ids[] = (
int) $row->ref_id;
101 $checked_ref_ids = [];
102 foreach ($ref_ids as $ref_id) {
104 $DIC->repositoryTree()->isInTree($ref_id)) {
108 return $checked_ref_ids;
119 $ilDB = $DIC[
'ilDB'];
121 $query =
'SELECT rid FROM ecs_cmap_rule ' .
122 'WHERE sid = ' .
$ilDB->quote($a_sid,
'integer') .
' ' .
123 'AND mid = ' .
$ilDB->quote($a_mid,
'integer') .
' ' .
124 'AND ref_id = ' .
$ilDB->quote($a_ref_id,
'integer');
133 public static function hasRules(
int $a_sid,
int $a_mid,
int $a_ref_id): bool
137 $ilDB = $DIC[
'ilDB'];
139 $query =
'SELECT ref_id FROM ecs_cmap_rule ' .
140 'WHERE sid = ' .
$ilDB->quote($a_sid,
'integer') .
' ' .
141 'AND mid = ' .
$ilDB->quote($a_mid,
'integer') .
' ' .
142 'AND ref_id = ' .
$ilDB->quote($a_ref_id,
'integer');
144 return $res->numRows() ? true :
false;
151 public static function isMatching($course,
int $a_sid,
int $a_mid,
int $a_ref_id): string
155 $ilDB = $DIC[
'ilDB'];
157 $query =
'SELECT rid FROM ecs_cmap_rule ' .
158 'WHERE sid = ' .
$ilDB->quote($a_sid,
'integer') .
' ' .
159 'AND mid = ' .
$ilDB->quote($a_mid,
'integer') .
' ' .
160 'AND ref_id = ' .
$ilDB->quote($a_ref_id,
'integer') .
' ' .
165 $sortable_index =
'';
168 $matches = $rule->matches($course);
169 if ($matches === -1) {
173 $sortable_index .= str_pad((
string) $matches, 4,
'0', STR_PAD_LEFT);
176 return $sortable_index;
181 public static function doMappings($course,
int $a_sid,
int $a_mid,
int $a_ref_id): array
185 $ilDB = $DIC[
'ilDB'];
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 = [];
199 $last_level_category[] = $rule->getRefId();
202 $found_new_level =
false;
203 $new_level_cats = [];
204 foreach ($last_level_category as $cat_ref_id) {
205 $refs = $rule->doMapping($course, (
int) $cat_ref_id);
206 foreach ($refs as $new_ref_id) {
207 $found_new_level =
true;
208 $new_level_cats[] = $new_ref_id;
211 if ($found_new_level) {
212 $last_level_category = $new_level_cats;
217 return $last_level_category;
223 public function doMapping($course,
int $parent_ref): array
230 $children = $this->tree->getChildsByType($parent_ref,
'cat');
231 $category_references = [];
232 foreach ($values as $value) {
234 foreach ($children as $child) {
236 if (strcmp($child[
'title'], $value) === 0) {
238 $category_references[] = (
int) $child[
'child'];
243 $category_references[] = $this->
createCategory($value, $parent_ref);
246 return $category_references;
258 $cat->setTitle($a_title);
260 $cat->createReference();
261 $cat->putInTree($a_parent_ref);
262 $cat->setPermissions($a_parent_ref);
263 $cat->deleteTranslation($this->
lng->getDefaultLanguage());
264 $cat->addTranslation(
266 $cat->getLongDescription(),
267 $this->
lng->getDefaultLanguage(),
268 $this->
lng->getDefaultLanguage()
270 return $cat->getRefId();
283 foreach ($values as $value) {
286 $this->
logger->debug(
'Comparing ' . $value .
' with ' . $filter_element);
287 if (strcmp(trim($value), trim($filter_element)) === 0) {
288 $this->
logger->debug($value .
' matches ' . $filter_element);
307 $ilDB = $DIC[
'ilDB'];
309 $query =
'SELECT rid FROM ecs_cmap_rule ' .
310 'WHERE sid = ' .
$ilDB->quote($a_sid,
'integer') .
' ' .
311 'AND mid = ' .
$ilDB->quote($a_mid,
'integer') .
' ' .
312 'AND ref_id = ' .
$ilDB->quote($a_ref_id,
'integer') .
' ' .
313 'AND attribute = ' .
$ilDB->quote($a_att,
'text');
324 $this->rid = $a_rule_id;
334 $this->sid = $a_server_id;
354 $this->attribute = $a_att;
364 $this->ref_id = $a_ref_id;
374 $this->is_filter = $a_status;
384 $this->
filter = $a_filter;
399 $this->create_subdir = $a_stat;
409 return self::SUBDIR_VALUE;
414 $this->directory = $a_dir;
422 public function delete():
bool 424 $query =
'DELETE from ecs_cmap_rule ' .
425 'WHERE rid = ' . $this->db->quote($this->
getRuleId(),
'integer');
426 $this->db->manipulate(
$query);
435 $this->
setRuleId($this->db->nextId(
'ecs_cmap_rule'));
436 $query =
'INSERT INTO ecs_cmap_rule ' .
437 '(rid,sid,mid,attribute,ref_id,is_filter,filter,create_subdir,subdir_type,directory) ' .
439 $this->db->quote($this->
getRuleId(),
'integer') .
', ' .
440 $this->db->quote($this->
getServerId(),
'integer') .
', ' .
441 $this->db->quote($this->
getMid(),
'integer') .
', ' .
442 $this->db->quote($this->
getAttribute(),
'text') .
', ' .
443 $this->db->quote($this->
getRefId(),
'integer') .
', ' .
445 $this->db->quote($this->
getFilter(),
'text') .
', ' .
450 $this->db->manipulate($query);
459 $query =
'UPDATE ecs_cmap_rule ' .
' ' .
461 'attribute = ' . $this->db->quote($this->
getAttribute(),
'text') .
', ' .
462 'ref_id = ' . $this->db->quote($this->
getRefId(),
'integer') .
', ' .
463 'is_filter = ' . $this->db->quote($this->
isFilterEnabled(),
'integer') .
', ' .
464 'filter = ' . $this->db->quote($this->
getFilter(),
'text') .
', ' .
467 'directory = ' . $this->db->quote($this->
getDirectory(),
'text') .
' ' .
468 'WHERE rid = ' . $this->db->quote($this->
getRuleId(),
'integer');
469 $this->db->manipulate(
$query);
475 protected function read(): void
480 $query =
'SELECT * from ecs_cmap_rule ' .
' ' .
481 'WHERE rid = ' . $this->db->quote($this->
getRuleId(),
'integer');
485 $this->
setMid((
int) $row->mid);
486 $this->
setRefId((
int) $row->ref_id);
506 $escaped_filter = str_replace(
'\,',
'#:#', $filter);
509 $filter_elements = explode(
',', $escaped_filter);
510 foreach ((array) $filter_elements as $filter_element) {
511 $replaced = str_replace(
'#:#',
',', $filter_element);
512 if (trim($replaced) !==
'') {
513 $this->filter_elements[] = $replaced;
setRuleId(int $a_rule_id)
createCategory($a_title, $a_parent_ref)
Create attribute category.
static getCourseValueByMappingAttribute($course, $a_field)
Get course value by mapping.
isSubdirCreationEnabled()
const SYSTEM_USER_ID
This file contains constants for PHPStan analyis, see: https://phpstan.org/config-reference#constants...
enableFilter(bool $a_status)
setFilter(string $a_filter)
matches($course)
Check if rule matches.
setAttribute(string $a_att)
static getRulesOfRefId(int $a_sid, int $a_mid, int $a_ref_id)
Get all rule of ref_id.
static lookupLastExistingAttribute(int $a_sid, int $a_mid, int $a_ref_id)
Lookup existing attributes.
static isMatching($course, int $a_sid, int $a_mid, int $a_ref_id)
Check if rule matches.
__construct(int $a_rid=0)
const SUBDIR_ATTRIBUTE_NAME
enableSubdirCreation(bool $a_stat)
static getRuleRefIds(int $a_sid, int $a_mid)
update()
Update mapping rule.
static getInstanceByAttribute($a_sid, $a_mid, $a_ref_id, $a_att)
Get rule instance by attribute.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static hasRules(int $a_sid, int $a_mid, int $a_ref_id)
parseFilter()
Parse filter.
static doMappings($course, int $a_sid, int $a_mid, int $a_ref_id)
setDirectory(string $a_dir)
doMapping($course, int $parent_ref)
Do mapping.
setServerId(int $a_server_id)