19declare(strict_types=1);
49 $this->
logger = $DIC->logger()->wsrv();
50 $this->tree =
$DIC->repositoryTree();
51 $this->
lng = $DIC->language();
52 $this->db =
$DIC->database();
67 $query =
'SELECT attribute FROM ecs_cmap_rule ' .
68 'WHERE sid = ' .
$ilDB->quote($a_sid,
'integer') .
' ' .
69 'AND mid = ' .
$ilDB->quote($a_mid,
'integer') .
' ' .
70 'AND ref_id = ' .
$ilDB->quote($a_ref_id,
'integer') .
' ' .
76 $attributes = $row->attribute;
90 $query =
'SELECT DISTINCT(ref_id) ref_id, rid FROM ecs_cmap_rule ' .
91 'WHERE sid = ' .
$ilDB->quote($a_sid,
'integer') .
' ' .
92 'AND mid = ' .
$ilDB->quote($a_mid,
'integer') .
' ' .
93 'GROUP BY ref_id' .
' ' .
99 $ref_ids[] = (
int) $row->ref_id;
102 $checked_ref_ids = [];
103 foreach ($ref_ids as
$ref_id) {
109 return $checked_ref_ids;
122 $query =
'SELECT rid FROM ecs_cmap_rule ' .
123 'WHERE sid = ' .
$ilDB->quote($a_sid,
'integer') .
' ' .
124 'AND mid = ' .
$ilDB->quote($a_mid,
'integer') .
' ' .
125 'AND ref_id = ' .
$ilDB->quote($a_ref_id,
'integer');
134 public static function hasRules(
int $a_sid,
int $a_mid,
int $a_ref_id): bool
140 $query =
'SELECT ref_id FROM ecs_cmap_rule ' .
141 'WHERE sid = ' .
$ilDB->quote($a_sid,
'integer') .
' ' .
142 'AND mid = ' .
$ilDB->quote($a_mid,
'integer') .
' ' .
143 'AND ref_id = ' .
$ilDB->quote($a_ref_id,
'integer');
145 return $res->numRows() ?
true :
false;
152 public static function isMatching($course, $a_sid, $a_mid, $a_ref_id): string
158 $query =
'SELECT rid FROM ecs_cmap_rule ' .
159 'WHERE sid = ' .
$ilDB->quote($a_sid,
'integer') .
' ' .
160 'AND mid = ' .
$ilDB->quote($a_mid,
'integer') .
' ' .
161 'AND ref_id = ' .
$ilDB->quote($a_ref_id,
'integer') .
' ' .
166 $sortable_index =
'';
169 $matches = $rule->matches($course);
170 if ($matches === -1) {
174 $sortable_index .= str_pad((
string) $matches, 4,
'0', STR_PAD_LEFT);
177 return $sortable_index;
182 public static function doMappings($course,
int $a_sid,
int $a_mid,
int $a_ref_id): array
188 $query =
'SELECT rid FROM ecs_cmap_rule ' .
189 'WHERE sid = ' .
$ilDB->quote($a_sid,
'integer') .
' ' .
190 'AND mid = ' .
$ilDB->quote($a_mid,
'integer') .
' ' .
191 'AND ref_id = ' .
$ilDB->quote($a_ref_id,
'integer') .
' ' .
196 $last_level_category = array();
200 $last_level_category[] = $rule->getRefId();
203 $found_new_level =
false;
204 $new_level_cats = array();
205 foreach ($last_level_category as $cat_ref_id) {
206 $refs = $rule->doMapping($course, (
int) $cat_ref_id);
207 foreach ($refs as $new_ref_id) {
208 $found_new_level =
true;
209 $new_level_cats[] = $new_ref_id;
212 if ($found_new_level) {
213 $last_level_category = $new_level_cats;
218 return $last_level_category;
224 public function doMapping($course,
int $parent_ref): array
231 $childs = $this->tree->getChildsByType($parent_ref,
'cat');
232 $category_references = [];
233 foreach ($values as $value) {
235 foreach ($childs as $child) {
237 if (strcmp($child[
'title'], $value) === 0) {
239 $category_references[] = $child[
'child'];
244 $category_references[] = $this->
createCategory($value, $parent_ref);
247 return $category_references;
259 $cat->setTitle($a_title);
261 $cat->createReference();
262 $cat->putInTree($a_parent_ref);
263 $cat->setPermissions($a_parent_ref);
264 $cat->deleteTranslation($this->
lng->getDefaultLanguage());
265 $cat->addTranslation(
267 $cat->getLongDescription(),
268 $this->lng->getDefaultLanguage(),
269 $this->lng->getDefaultLanguage()
271 return $cat->getRefId();
283 $this->
logger->dump($values);
285 foreach ($values as $value) {
288 $this->
logger->debug(
'Comparing ' . $value .
' with ' . $filter_element);
289 if (strcmp(trim($value), trim($filter_element)) === 0) {
290 $this->
logger->debug($value .
' matches ' . $filter_element);
291 $this->
logger->debug(
'Found index: ' . $index);
311 $query =
'SELECT rid FROM ecs_cmap_rule ' .
312 'WHERE sid = ' .
$ilDB->quote($a_sid,
'integer') .
' ' .
313 'AND mid = ' .
$ilDB->quote($a_mid,
'integer') .
' ' .
314 'AND ref_id = ' .
$ilDB->quote($a_ref_id,
'integer') .
' ' .
315 'AND attribute = ' .
$ilDB->quote($a_att,
'text');
326 $this->rid = $a_rule_id;
336 $this->sid = $a_server_id;
356 $this->attribute = $a_att;
366 $this->ref_id = $a_ref_id;
376 $this->is_filter = $a_status;
386 $this->
filter = $a_filter;
401 $this->create_subdir = $a_stat;
416 $this->directory = $a_dir;
424 public function delete():
bool
426 $query =
'DELETE from ecs_cmap_rule ' .
427 'WHERE rid = ' . $this->db->quote($this->
getRuleId(),
'integer');
428 $this->db->manipulate($query);
437 $this->
setRuleId($this->db->nextId(
'ecs_cmap_rule'));
438 $query =
'INSERT INTO ecs_cmap_rule ' .
439 '(rid,sid,mid,attribute,ref_id,is_filter,filter,create_subdir,subdir_type,directory) ' .
441 $this->db->quote($this->
getRuleId(),
'integer') .
', ' .
442 $this->db->quote($this->
getServerId(),
'integer') .
', ' .
443 $this->db->quote($this->
getMid(),
'integer') .
', ' .
444 $this->db->quote($this->
getAttribute(),
'text') .
', ' .
445 $this->db->quote($this->
getRefId(),
'integer') .
', ' .
447 $this->db->quote($this->
getFilter(),
'text') .
', ' .
452 $this->db->manipulate($query);
461 $query =
'UPDATE ecs_cmap_rule ' .
' ' .
463 'attribute = ' . $this->db->quote($this->
getAttribute(),
'text') .
', ' .
464 'ref_id = ' . $this->db->quote($this->
getRefId(),
'integer') .
', ' .
465 'is_filter = ' . $this->db->quote($this->
isFilterEnabled(),
'integer') .
', ' .
466 'filter = ' . $this->db->quote($this->
getFilter(),
'text') .
', ' .
469 'directory = ' . $this->db->quote($this->
getDirectory(),
'text') .
' ' .
470 'WHERE rid = ' . $this->db->quote($this->
getRuleId(),
'integer');
471 $this->db->manipulate($query);
477 protected function read(): void
482 $query =
'SELECT * from ecs_cmap_rule ' .
' ' .
483 'WHERE rid = ' . $this->db->quote($this->
getRuleId(),
'integer');
484 $res = $this->db->query($query);
487 $this->
setMid((
int) $row->mid);
488 $this->
setRefId((
int) $row->ref_id);
508 $escaped_filter = str_replace(
'\,',
'#:#',
$filter);
513 $replaced = str_replace(
'#:#',
',', $filter_element);
514 if (trim($replaced) !==
'') {
515 $this->filter_elements[] = $replaced;
static hasRules(int $a_sid, int $a_mid, int $a_ref_id)
static isMatching($course, $a_sid, $a_mid, $a_ref_id)
Check if rule matches.
static getRuleRefIds(int $a_sid, int $a_mid)
isSubdirCreationEnabled()
__construct(int $a_rid=0)
static doMappings($course, int $a_sid, int $a_mid, int $a_ref_id)
static lookupLastExistingAttribute(int $a_sid, int $a_mid, int $a_ref_id)
Lookup existing attributes.
setFilter(string $a_filter)
parseFilter()
Parse filter.
enableFilter(bool $a_status)
static getRulesOfRefId(int $a_sid, int $a_mid, int $a_ref_id)
Get all rule of ref_id.
matches($course)
Check if rule matches.
doMapping($course, int $parent_ref)
Do mapping.
enableSubdirCreation(bool $a_stat)
static getInstanceByAttribute($a_sid, $a_mid, $a_ref_id, $a_att)
Get rule instance by attribute.
setDirectory(string $a_dir)
setRuleId(int $a_rule_id)
setAttribute(string $a_att)
createCategory($a_title, $a_parent_ref)
Create attribute category.
update()
Update mapping rule.
const SUBDIR_ATTRIBUTE_NAME
setServerId(int $a_server_id)
static getCourseValueByMappingAttribute($course, $a_field)
Get course value by mapping.
Component logger with individual log levels by component id.
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
const SYSTEM_USER_ID
This file contains constants for PHPStan analyis, see: https://phpstan.org/config-reference#constants...
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)