ILIAS  trunk Revision v11.0_alpha-1866-gfa368f7776e
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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 24 of file class.ilECSCategoryMapping.php.

Member Function Documentation

◆ getActiveRules()

static ilECSCategoryMapping::getActiveRules ( )
static

get active rules

Returns
ilECSCategoryMappingRule[]

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

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

Referenced by ilECSSettingsGUI\showRulesTable().

33  : array
34  {
35  global $DIC;
36 
37  $ilDB = $DIC['ilDB'];
38  $rules = [];
39  $res = $ilDB->query('SELECT mapping_id FROM ecs_container_mapping');
40  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
41  $rules[] = new ilECSCategoryMappingRule((int) $row->mapping_id);
42  }
43  return $rules;
44  }
$res
Definition: ltiservices.php:66
Defines a rule for the assignment of ECS remote courses to categories.
global $DIC
Definition: shib_login.php:22
+ 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 49 of file class.ilECSCategoryMapping.php.

References $DIC, and ilECSSetting\getInstanceByServerId().

Referenced by ilRemoteObjectBase\createFromECSEContent().

49  : ?int
50  {
51  global $DIC;
52 
53  $logger = $DIC->logger()->wsrv();
54 
55  if (is_null(self::$cached_active_rules)) {
56  self::$cached_active_rules = self::getActiveRules();
57  }
58  foreach (self::$cached_active_rules as $rule) {
59  if ($rule->matches($a_matchable_content)) {
60  $logger->info(__METHOD__ . ': Found assignment for field type: ' . $rule->getFieldName());
61  return $rule->getContainerId();
62  }
63  $logger->error(__METHOD__ . ': Category assignment failed for field: ' . $rule->getFieldName());
64  }
65  // Return default container
66  $logger->info(__METHOD__ . ': Using default container');
67 
68  return ilECSSetting::getInstanceByServerId($a_server_id)->getImportId();
69  }
static getInstanceByServerId(int $a_server_id)
Get singleton instance per server.
global $DIC
Definition: shib_login.php:22
+ 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 142 of file class.ilECSCategoryMapping.php.

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

Referenced by ilECSSettingsGUI\initCategoryMappingForm().

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

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

Referenced by ilRemoteObjectBase\updateFromECSContent().

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

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

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

Field Documentation

◆ $cached_active_rules

array ilECSCategoryMapping::$cached_active_rules = null
staticprivate

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


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