18 declare(strict_types=1);
42 $this->
logger = $DIC->logger()->wsrv();
43 $this->
lng = $DIC->language();
44 $this->tree = $DIC->repositoryTree();
93 $this->object_created = $a_status;
116 public function handle(
int $a_content_id, $course): bool
122 $this->course_url->setECSId($a_content_id);
125 if ($this->
getMapping()->isAttributeMappingEnabled()) {
126 $this->
logger->debug(
'Handling advanced attribute mapping');
130 if ($this->
getMapping()->isAllInOneCategoryEnabled()) {
131 $this->
logger->debug(
'Handling course all in one category setting');
137 if ($parent_obj_id) {
139 $this->
doSync($a_content_id, $course, $parent_obj_id);
142 $this->
logger->info(
'Using course default category');
153 $course_id = $course->lectureID;
158 $this->
logger->debug(
'Performing update of already imported course.');
172 $matching_rules = [];
180 if (strcmp($matching_index,
'0') !== 0) {
181 $matching_rules[$matching_index] =
$ref_id;
184 ksort($matching_rules);
186 $this->
logger->dump($matching_rules);
188 if (!count($matching_rules)) {
190 $this->
logger->debug(
'No matching attribute mapping rule found.');
191 $this->
logger->info(
'Using course default category');
196 $this->
logger->debug(
'Matching rules:');
199 $all_parent_refs = [];
200 foreach ($matching_rules as $matching_rule) {
201 $this->
logger->debug(
'Handling matching rule: ' . $matching_rule);
209 $this->
logger->debug(
'Adding parent references: ' . print_r($parent_refs,
true));
210 if (count($parent_refs)) {
211 $all_parent_refs = array_unique(array_merge($all_parent_refs, $parent_refs));
219 foreach ($all_parent_refs as $category_ref) {
221 $this->
logger->debug(
'Creating new course instance in: ' . $category_ref);
226 $this->
logger->debug(
'Creating new course reference instance in: ' . $category_ref);
241 $crsr->setTargetRefId($ref_id);
245 $crsr->createReference();
246 $crsr->putInTree($a_parent_ref_id);
247 $crsr->setPermissions($a_parent_ref_id);
258 if (!is_array($course->allocations)) {
259 $this->
logger->debug(
'No allocation in course defined.');
262 if (!$course->allocations[0]->parentID) {
263 $this->
logger->debug(
'No allocation parent in course defined.');
266 $parent_id = $course->allocations[0]->parentID;
269 return $this->syncNodetoTop($parent_tid, $parent_id);
292 $this->
logger->debug(
'ecs node with id ' . $cms_id .
' is not imported for mid ' . $this->
getMid() .
' tree_id ' . $tree_id);
302 if ($ass->isMapped()) {
303 $this->
logger->debug(
'node is mapped');
309 $parent_tobj_id = $tree->getParentId($tobj_id);
310 if ($parent_tobj_id) {
332 $cat->setTitle(
$data->getTitle());
334 $cat->createReference();
335 $cat->putInTree($parent_ref_id);
336 $cat->setPermissions($parent_ref_id);
337 $cat->deleteTranslation($this->
lng->getDefaultLanguage());
338 $cat->addTranslation(
340 $cat->getLongDescription(),
341 $this->
lng->getDefaultLanguage(),
342 $this->
lng->getDefaultLanguage()
351 $import->setContentId(
$data->getCmsId());
352 $import->setImported(
true);
355 return $cat->getId();
363 protected function doSync($a_content_id, $course, $a_parent_obj_id): bool
366 $course_id = $course->lectureID;
367 $this->course_url->setCmsLectureId((
string) $course_id);
371 $this->
logger->debug(
'Found obj_id ' . $obj_id .
' for course_id ' . $course_id);
376 $this->
logger->debug(
'Group scenario ' . $course->groupScenario);
377 switch ((
int) $course->groupScenario) {
379 $this->
logger->debug(
'Performing update for parallel groups in course.');
384 $this->
logger->debug(
'Performing update for parallel courses.');
398 switch ((
int) $course->groupScenario) {
400 $this->
logger->debug(
'Parallel scenario "groups in courses".');
403 $this->
setImported((
int) $course_id, $crs, $a_content_id);
410 $this->
logger->debug(
'Parallel scenario "Courses foreach Lecturer".');
412 $this->
setImported((
int) $course_id, null, $a_content_id);
416 $this->
logger->debug(
'Parallel scenario "Many courses".');
428 $this->
logger->debug(
'Parallel scenario "One Course".');
431 $this->
setImported((
int) $course_id, $crs, $a_content_id);
447 foreach ((array) $course->groups as $group) {
458 if ($this->
getImportId((
int) $course->lectureID, (
string) $group->id)) {
459 $this->
logger->debug(
'Parallel course already created');
465 $title = $course->title;
466 if ($group->title !==
'') {
467 $title .=
' (' . $group->title .
')';
469 $this->
logger->debug(
'Creating new parallel course instance from ecs : ' . $title);
470 $course_obj->setTitle($title);
471 $course_obj->setSubscriptionMaxMembers((
int) $group->maxParticipants);
472 $course_obj->setOfflineStatus(
true);
473 $course_obj->create();
476 $this->
setImported((
int) $course->lectureID, $course_obj, $a_content_id, $group->id);
487 $parent_ref = end($parent_refs);
489 foreach ((array) $course->groups as $group) {
490 $title = $course->title;
491 if ($group->title !==
'') {
492 $title .=
' (' . $group->title .
')';
495 $obj_id = $this->
getImportId((
int) $course->lectureID, (
string) $group->id);
496 $this->
logger->debug(
'Imported obj id is ' . $obj_id);
502 $this->
logger->debug(
'New title is ' . $title);
503 $course_obj->setTitle($title);
504 if(!is_null($group->maxParticipants)) {
505 $course_obj->setSubscriptionMaxMembers($group->maxParticipants);
507 $course_obj->update();
522 foreach ((array) $course->groups as $group) {
535 $title = $group->title !==
'' ? $group->title : $course->title;
536 $group_obj->setTitle($title);
537 $group_obj->setMaxMembers((
int) $group->maxParticipants);
538 $group_obj->create();
539 $group_obj->createReference();
540 $group_obj->putInTree($parent_ref);
541 $group_obj->setPermissions($parent_ref);
543 $this->
setImported((
int) $course->lectureID, $group_obj, $a_content_id, $group->id);
554 $parent_ref = end($parent_refs);
556 foreach ((array) $course->groups as $group) {
557 $obj_id = $this->
getImportId((
int) $course->lectureID, (
string) $group->id);
558 $this->
logger->debug(
'Imported obj id is ' . $obj_id);
564 $title = $group->title !==
'' ? $group->title : $course->title;
565 $this->
logger->debug(
'New title is ' . $title);
566 $group_obj->setTitle($title);
567 if(!is_null($group->maxParticipants)) {
568 $group_obj->setMaxMembers((
int) $group->maxParticipants);
570 $group_obj->update();
601 if (!$crs_obj instanceof
ilObject) {
602 $this->
logger->debug(
'Cannot instantiate course instance');
607 $title = $course->title;
608 $this->
logger->debug(
'new title is : ' . $title);
610 $crs_obj->setTitle($title);
622 $title = $course->title;
623 $this->
logger->debug(
'Creating new course instance from ecs : ' . $title);
624 $course_obj->setTitle($title);
625 $course_obj->setOfflineStatus(
true);
626 $course_obj->create();
645 $this->courses_created[] = $crs->
getRefId();
653 protected function setImported(
int $a_content_id, $object, $a_ecs_id = 0, $a_sub_id = null): bool
657 is_object($object) ? $object->getId() : 0
661 $import->
setSubId((
string) $a_sub_id);
662 $import->setMID($this->
getMid());
663 $import->setEContentId((
string) $a_ecs_id);
664 $import->setContentId((
string) $a_content_id);
665 $import->setImported(
true);
685 $this->course_url->addLmsCourseUrls($lms_url);
694 $this->
logger->debug(
'Starting course url update');
696 $this->
logger->debug(
'Sending new course group url');
699 $this->
logger->debug(
'No courses groups created. Aborting');
ilECSNodeMappingSettings $mapping
updateParallelCourses($a_content_id, $course, $parent_obj)
Update parallel group data.
syncNodeToTop($tree_id, $cms_id)
Sync node to top.
getCourseUrl()
Get course url.
static getInstanceByServerMid(int $a_server_id, int $a_mid)
Get instance.
handleCourseUrlUpdate()
Update course url.
const SYSTEM_USER_ID
This file contains constants for PHPStan analyis, see: https://phpstan.org/config-reference#constants...
static _getAllReferences(int $id)
get all reference ids for object ID
getImportId(int $a_content_id, string $a_sub_id=null)
Get import id of remote course Return 0 if object isn't imported.
__construct(ilECSSetting $server, int $a_mid)
syncCategory($tobj_id, $parent_ref_id)
Sync category.
putInTree(int $parent_ref_id)
updateParallelGroups($a_content_id, $course, int $parent_obj)
Update parallel group data.
static lookupObjId(int $a_server_id, int $a_mid, int $a_tree_id, string $cms_id)
const PARALLEL_ONE_COURSE
setPermissions(int $parent_ref_id)
static _lookupObjId(int $ref_id)
static isMatching($course, int $a_sid, int $a_mid, int $a_ref_id)
Check if rule matches.
createReference()
creates reference for object
static lookupFirstTreeOfNode($a_server_id, $a_mid, $cms_id)
Lookup first obj_id of cms node.
createCourseReferenceObjects(int $a_parent_ref_id)
Create course reference objects.
static getInstance()
Get the singleton instance of this ilECSImportManager.
createParallelCourse($a_content_id, $course, $group, $parent_ref)
Create parallel course.
static _lookupTitle(int $obj_id)
createParallelGroup($a_content_id, $course, $group, $parent_ref)
Create parallel group.
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
ilECSCourseUrl $course_url
Represents a ecs course lms url.
setObjectCreated(bool $a_status)
Set object created status.
Storage of ECS imported objects.
static getRuleRefIds(int $a_sid, int $a_mid)
const PARALLEL_COURSES_FOR_LECTURERS
doAttributeMapping($a_content_id, $course)
Sync attribute mapping.
static lookupCmsIds(array $a_obj_ids)
static _getLink(?int $a_ref_id, string $a_type='', array $a_params=array(), string $append="")
getCreatedCourses()
get created courses
getMid()
Get mid of course event.
handle(int $a_content_id, $course)
Handle sync request.
const PARALLEL_ALL_COURSES
addUrlEntry(int $a_obj_id)
Add an url entry.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
isObjectCreated()
Check if an object (course / group) has been created.
Represents a ecs course url.
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
static doMappings($course, int $a_sid, int $a_mid, int $a_ref_id)
doSync($a_content_id, $course, $a_parent_obj_id)
Handle all in one setting.
createCourseReference(ilObjCourse $crs, int $a_parent_obj_id)
Create course reference.
updateCourseData($course, $obj_id)
Update course data.
createParallelCourses(int $a_content_id, $course, $parent_ref)
Create parallel courses.
const PARALLEL_GROUPS_IN_COURSE
createParallelGroups($a_content_id, $course, $parent_ref)
This create parallel groups.
createCourseData($course)
Create course data from json.
syncParentContainer($a_content_id, $course)
Sync parent container.
setImported(int $a_content_id, $object, $a_ecs_id=0, $a_sub_id=null)
Set new course object imported.
getMapping()
Get mapping settings.
getServer()
Get server settings.