18 declare(strict_types=1);
38 $res =
$ilDB->query(
'SELECT mapping_id FROM ecs_container_mapping');
52 $logger = $DIC->logger()->wsrv();
54 if (is_null(self::$cached_active_rules)) {
55 self::$cached_active_rules = self::getActiveRules();
57 foreach (self::$cached_active_rules as $rule) {
58 if ($rule->matches($a_matchable_content)) {
59 $logger->info(__METHOD__ .
': Found assignment for field type: ' . $rule->getFieldName());
60 return $rule->getContainerId();
62 $logger->error(__METHOD__ .
': Category assignment failed for field: ' . $rule->getFieldName());
65 $logger->info(__METHOD__ .
': Using default container');
73 public static function handleUpdate(
int $a_obj_id,
int $a_server_id, array $a_matchable_content): bool
77 $tree = $DIC->repositoryTree();
78 $logger = $DIC->logger()->wsrv();
80 $cat = self::getMatchingCategory($a_server_id, $a_matchable_content);
84 $all_cats = self::lookupHandledCategories();
87 foreach (array_keys($references) as
$ref_id) {
88 if ($tree->getParentId($ref_id) === $cat) {
92 $logger->info(__METHOD__ .
': Creating/Deleting references...');
95 $logger->info(__METHOD__ .
': Add new reference. STEP 1');
98 $obj_data->createReference();
99 $obj_data->putInTree($cat);
100 $obj_data->setPermissions($cat);
101 $logger->info(__METHOD__ .
': Add new reference.');
105 foreach (array_keys($references) as $ref_id) {
106 $parent = $tree->getParentId($ref_id);
107 if ($parent === $cat) {
110 if (!in_array($parent, $all_cats,
true)) {
114 $to_delete->delete();
115 $logger->write(__METHOD__ .
': Deleted deprecated reference.');
128 $ilDB = $DIC->database();
131 $res =
$ilDB->query(
"SELECT container_id FROM ecs_container_mapping ");
133 $ref_ids[] = $row->container_id;
148 "community" =>
$lng->txt(
"ecs_field_community"),
149 "part_id" =>
$lng->txt(
"ecs_field_part_id"),
150 "type" =>
$lng->txt(
"type")
157 foreach ($course_fields as $field) {
158 $options[$field] =
$lng->txt(
"obj_rcrs") .
" - " .
$lng->txt(
"ecs_field_" . $field);
static _getAllReferences(int $id)
get all reference ids for object ID
Defines a rule for the assignment of ECS remote courses to categories.
static _lookupObjId(int $ref_id)
static getPossibleFields()
static getActiveRules()
get active rules
static getInstanceByServerId(int $a_server_id)
Get singleton instance per server.
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
static array $cached_active_rules
static getMatchingCategory(int $a_server_id, array $a_matchable_content)
get matching category
static lookupHandledCategories()
static handleUpdate(int $a_obj_id, int $a_server_id, array $a_matchable_content)
Handle update of ecs content and create references.
static _getOptionalECourseFields()
get optional econtent fields These fields might be mapped against AdvancedMetaData field definitions ...