ILIAS  release_8 Revision v8.24
ilECSCategoryMapping Class Reference
+ Collaboration diagram for ilECSCategoryMapping:

Static Public Member Functions

static getActiveRules ()
 get active rules More...
 
static getMatchingCategory (int $a_server_id, array $a_matchable_content)
 get matching category More...
 
static handleUpdate (int $a_obj_id, int $a_server_id, array $a_matchable_content)
 Handle update of ecs content and create references. More...
 
static lookupHandledCategories ()
 
static getPossibleFields ()
 

Static Private Attributes

static array $cached_active_rules = null
 

Detailed Description

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 23 of file class.ilECSCategoryMapping.php.

Member Function Documentation

◆ getActiveRules()

static ilECSCategoryMapping::getActiveRules ( )
static

get active rules

Returns
ilECSCategoryMappingRule[]

Definition at line 32 of file class.ilECSCategoryMapping.php.

32 : array
33 {
34 global $DIC;
35
36 $ilDB = $DIC['ilDB'];
37 $rules = [];
38 $res = $ilDB->query('SELECT mapping_id FROM ecs_container_mapping');
39 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
40 $rules[] = new ilECSCategoryMappingRule((int) $row->mapping_id);
41 }
42 return $rules;
43 }
Defines a rule for the assignment of ECS remote courses to categories.
global $DIC
Definition: feed.php:28
$res
Definition: ltiservices.php:69

References $DIC, $ilDB, $res, and ilDBConstants\FETCHMODE_OBJECT.

Referenced by getMatchingCategory(), and ilECSSettingsGUI\showRulesTable().

+ Here is the caller graph for this function:

◆ getMatchingCategory()

static ilECSCategoryMapping::getMatchingCategory ( int  $a_server_id,
array  $a_matchable_content 
)
static

get matching category

Definition at line 48 of file class.ilECSCategoryMapping.php.

48 : ?int
49 {
50 global $DIC;
51
52 $logger = $DIC->logger()->wsrv();
53
54 if (is_null(self::$cached_active_rules)) {
55 self::$cached_active_rules = self::getActiveRules();
56 }
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();
61 }
62 $logger->error(__METHOD__ . ': Category assignment failed for field: ' . $rule->getFieldName());
63 }
64 // Return default container
65 $logger->info(__METHOD__ . ': Using default container');
66
67 return ilECSSetting::getInstanceByServerId($a_server_id)->getImportId();
68 }
static getActiveRules()
get active rules
static getInstanceByServerId(int $a_server_id)
Get singleton instance per server.

References $DIC, getActiveRules(), and ilECSSetting\getInstanceByServerId().

Referenced by ilRemoteObjectBase\createFromECSEContent(), and handleUpdate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getPossibleFields()

static ilECSCategoryMapping::getPossibleFields ( )
static
Returns
array<string,string> tthe possible fields with translation

Definition at line 141 of file class.ilECSCategoryMapping.php.

141 : array
142 {
143 global $DIC;
144
145 $lng = $DIC['lng'];
146
147 $options = array(
148 "community" => $lng->txt("ecs_field_community"),
149 "part_id" => $lng->txt("ecs_field_part_id"),
150 "type" => $lng->txt("type")
151 );
152
153 // will be handled by server soon?
154
155 // only courses for now
156 $course_fields = ilECSUtils::_getOptionalECourseFields();
157 foreach ($course_fields as $field) {
158 $options[$field] = $lng->txt("obj_rcrs") . " - " . $lng->txt("ecs_field_" . $field);
159 }
160
161 return $options;
162 }
static _getOptionalECourseFields()
get optional econtent fields These fields might be mapped against AdvancedMetaData field definitions
$lng

References $DIC, $lng, and ilECSUtils\_getOptionalECourseFields().

Referenced by ilECSSettingsGUI\initCategoryMappingForm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handleUpdate()

static ilECSCategoryMapping::handleUpdate ( int  $a_obj_id,
int  $a_server_id,
array  $a_matchable_content 
)
static

Handle update of ecs content and create references.

Definition at line 73 of file class.ilECSCategoryMapping.php.

73 : bool
74 {
75 global $DIC;
76
77 $tree = $DIC->repositoryTree();
78 $logger = $DIC->logger()->wsrv();
79
80 $cat = self::getMatchingCategory($a_server_id, $a_matchable_content);
81
82 $a_ref_id = current(ilObject::_getAllReferences($a_obj_id));
85
86 $exists = false;
87 foreach (array_keys($references) as $ref_id) {
88 if ($tree->getParentId($ref_id) === $cat) {
89 $exists = true;
90 }
91 }
92 $logger->info(__METHOD__ . ': Creating/Deleting references...');
93
94 if (!$exists) {
95 $logger->info(__METHOD__ . ': Add new reference. STEP 1');
96
97 if ($obj_data = ilObjectFactory::getInstanceByRefId($a_ref_id, false)) {
98 $obj_data->createReference();
99 $obj_data->putInTree($cat);
100 $obj_data->setPermissions($cat);
101 $logger->info(__METHOD__ . ': Add new reference.');
102 }
103 }
104 // Now delete old references
105 foreach (array_keys($references) as $ref_id) {
106 $parent = $tree->getParentId($ref_id);
107 if ($parent === $cat) {
108 continue;
109 }
110 if (!in_array($parent, $all_cats, true)) {
111 continue;
112 }
114 $to_delete->delete();
115 $logger->write(__METHOD__ . ': Deleted deprecated reference.');
116 }
117 }
118 return true;
119 }
static getMatchingCategory(int $a_server_id, array $a_matchable_content)
get matching category
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupObjId(int $ref_id)
$ref_id
Definition: ltiauth.php:67

References $DIC, $ref_id, ilObject\_getAllReferences(), ilObject\_lookupObjId(), ilObjectFactory\getInstanceByRefId(), getMatchingCategory(), and lookupHandledCategories().

Referenced by ilRemoteObjectBase\updateFromECSContent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lookupHandledCategories()

static ilECSCategoryMapping::lookupHandledCategories ( )
static
Returns
int[] the container ids for the ecs container mapping

Definition at line 124 of file class.ilECSCategoryMapping.php.

124 : array
125 {
126 global $DIC;
127
128 $ilDB = $DIC->database();
129
130 $ref_ids = [];
131 $res = $ilDB->query("SELECT container_id FROM ecs_container_mapping ");
132 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
133 $ref_ids[] = $row->container_id;
134 }
135 return $ref_ids;
136 }

References $DIC, $ilDB, $res, and ilDBConstants\FETCHMODE_OBJECT.

Referenced by handleUpdate().

+ Here is the caller graph for this function:

Field Documentation

◆ $cached_active_rules

array ilECSCategoryMapping::$cached_active_rules = null
staticprivate

Definition at line 25 of file class.ilECSCategoryMapping.php.


The documentation for this class was generated from the following file: