ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilECSCourseCreationHandler Class Reference

Description of class. More...

+ Collaboration diagram for ilECSCourseCreationHandler:

Public Member Functions

 __construct (ilECSSetting $server, $a_mid)
 Constructor More...
 
 getServer ()
 Get server settings. More...
 
 getMapping ()
 Get mapping settings. More...
 
 getCourseUrl ()
 Get course url. More...
 
 isObjectCreated ()
 Check if an object (course / group) has been created. More...
 
 setObjectCreated ($a_status)
 Set object created status. More...
 
 getMid ()
 Get mid of course event. More...
 
 handle ($a_content_id, $course)
 Handle sync request. More...
 

Protected Member Functions

 getCreatedCourses ()
 get created courses More...
 
 doAttributeMapping ($a_content_id, $course)
 Sync attribute mapping. More...
 
 createCourseReferenceObjects ($a_parent_ref_id)
 Create course reference objects. More...
 
 syncParentContainer ($a_content_id, $course)
 Sync parent container. More...
 
 syncNodeToTop ($tree_id, $cms_id)
 Sync node to top. More...
 
 syncCategory ($tobj_id, $parent_ref_id)
 Sync category. More...
 
 doSync ($a_content_id, $course, $a_parent_obj_id)
 Handle all in one setting. More...
 
 createParallelCourses ($a_content_id, $course, $parent_ref)
 Create parallel courses. More...
 
 createParallelCourse ($a_content_id, $course, $group, $parent_ref)
 Create parallel course. More...
 
 updateParallelCourses ($a_content_id, $course, $parent_obj)
 Update parallel group data. More...
 
 createParallelGroups ($a_content_id, $course, $parent_ref)
 This create parallel groups. More...
 
 createParallelGroup ($a_content_id, $course, $group, $parent_ref)
 Create parallel group. More...
 
 updateParallelGroups ($a_content_id, $course, $parent_obj)
 Update parallel group data. More...
 
 getImportId ($a_content_id, $a_sub_id=null)
 Get import id of remote course Return 0 if object isn't imported. More...
 
 updateCourseData ($course, $obj_id)
 Update course data. More...
 
 createCourseData ($course)
 Create course data from json. More...
 
 createCourseReference ($crs, $a_parent_obj_id)
 Create course reference. More...
 
 setImported ($a_content_id, $object, $a_ecs_id=0, $a_sub_id=null)
 Set new course object imported. More...
 
 addUrlEntry ($a_obj_id)
 Add an url entry. More...
 
 handleCourseUrlUpdate ()
 Update course url. More...
 

Protected Attributes

 $log
 

Private Attributes

 $server = null
 
 $mapping = null
 
 $course_url = null
 
 $object_created = false
 
 $courses_created = array()
 
 $mid
 

Detailed Description

Description of class.

Author
Stefan Meyer smeye.nosp@m.r.il.nosp@m.ias@g.nosp@m.mx.d.nosp@m.e

Definition at line 14 of file class.ilECSCourseCreationHandler.php.

Constructor & Destructor Documentation

◆ __construct()

ilECSCourseCreationHandler::__construct ( ilECSSetting  $server,
  $a_mid 
)

Constructor

Definition at line 35 of file class.ilECSCourseCreationHandler.php.

References $GLOBALS, $server, ilECSNodeMappingSettings\getInstanceByServerMid(), getMid(), and getServer().

36  {
37  $this->log = $GLOBALS['DIC']->logger()->wsrv();
38 
39  $this->server = $server;
40  $this->mid = $a_mid;
41  $this->mapping = ilECSNodeMappingSettings::getInstanceByServerMid($this->getServer()->getServerId(), $this->getMid());
42 
43  include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseUrl.php';
44  $this->course_url = new ilECSCourseUrl();
45  }
static getInstanceByServerMid($a_server_id, $a_mid)
Get instance.
Represents a ecs course url.
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
+ Here is the call graph for this function:

Member Function Documentation

◆ addUrlEntry()

ilECSCourseCreationHandler::addUrlEntry (   $a_obj_id)
protected

Add an url entry.

Parameters
type$a_obj_id

Definition at line 715 of file class.ilECSCourseCreationHandler.php.

References ilObject\_getAllReferences(), ilLink\_getLink(), ilObject\_lookupTitle(), and getCourseUrl().

Referenced by createCourseReference(), updateParallelCourses(), and updateParallelGroups().

716  {
717  $refs = ilObject::_getAllReferences($a_obj_id);
718  $ref_id = end($refs);
719 
720  if (!$ref_id) {
721  return false;
722  }
723  include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseLmsUrl.php';
724  $lms_url = new ilECSCourseLmsUrl();
725  $lms_url->setTitle(ilObject::_lookupTitle($a_obj_id));
726 
727  include_once './Services/Link/classes/class.ilLink.php';
728  $lms_url->setUrl(ilLink::_getLink($ref_id));
729  $this->getCourseUrl()->addLmsCourseUrls($lms_url);
730  }
static _lookupTitle($a_id)
lookup object title
static _getAllReferences($a_id)
get all reference ids of object
Represents a ecs course lms url.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createCourseData()

ilECSCourseCreationHandler::createCourseData (   $course)
protected

Create course data from json.

Returns
ilObjCourse

Definition at line 652 of file class.ilECSCourseCreationHandler.php.

References $GLOBALS, and $title.

Referenced by doSync().

653  {
654  include_once './Modules/Course/classes/class.ilObjCourse.php';
655  $course_obj = new ilObjCourse();
656  $course_obj->setOwner(SYSTEM_USER_ID);
657  $title = $course->title;
658  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': Creating new course instance from ecs : ' . $title);
659  $course_obj->setTitle($title);
660  $course_obj->setOfflineStatus(true);
661  $course_obj->create();
662  return $course_obj;
663  }
Class ilObjCourse.
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
+ Here is the caller graph for this function:

◆ createCourseReference()

ilECSCourseCreationHandler::createCourseReference (   $crs,
  $a_parent_obj_id 
)
protected

Create course reference.

Parameters
ilObjCourse$crs_obj
int$a_parent_obj_id
Returns
ilObjCourse

Definition at line 671 of file class.ilECSCourseCreationHandler.php.

References ilObject\_getAllReferences(), addUrlEntry(), and setObjectCreated().

Referenced by createParallelCourse(), and doSync().

672  {
673  $ref_ids = ilObject::_getAllReferences($a_parent_obj_id);
674  $ref_id = end($ref_ids);
675 
676  $crs->createReference();
677  $crs->putInTree($ref_id);
678  $crs->setPermissions($ref_id);
679 
680  $this->setObjectCreated(true);
681  $this->addUrlEntry($crs->getId());
682 
683  $this->courses_created[] = $crs->getRefId();
684 
685  return $crs;
686  }
addUrlEntry($a_obj_id)
Add an url entry.
static _getAllReferences($a_id)
get all reference ids of object
setObjectCreated($a_status)
Set object created status.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createCourseReferenceObjects()

ilECSCourseCreationHandler::createCourseReferenceObjects (   $a_parent_ref_id)
protected

Create course reference objects.

Parameters
type$a_parent_ref_id

Definition at line 237 of file class.ilECSCourseCreationHandler.php.

References ilObject\_lookupObjId(), ilObject\_lookupTitle(), and getCreatedCourses().

Referenced by doAttributeMapping().

238  {
239  foreach ($this->getCreatedCourses() as $ref_id) {
240  include_once './Modules/CourseReference/classes/class.ilObjCourseReference.php';
241  $crsr = new ilObjCourseReference();
242  $crsr->setOwner(SYSTEM_USER_ID);
243  $crsr->setTargetRefId($ref_id);
244  $crsr->setTargetId(ilObject::_lookupObjId($ref_id));
245  $crsr->create();
246  $crsr->update();
247  $crsr->createReference();
248  $crsr->putInTree($a_parent_ref_id);
249  $crsr->setPermissions($a_parent_ref_id);
250 
251  $this->log->debug('Created new course reference in : ' . ilObject::_lookupTitle(ilObject::_lookupObjId($a_parent_ref_id)));
252  $this->log->debug('Created new course reference for : ' . ilObject::_lookupTitle(ilObject::_lookupObjId($ref_id)));
253  }
254  }
static _lookupTitle($a_id)
lookup object title
static _lookupObjId($a_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createParallelCourse()

ilECSCourseCreationHandler::createParallelCourse (   $a_content_id,
  $course,
  $group,
  $parent_ref 
)
protected

Create parallel course.

Parameters
type$course
type$group
type$parent_ref

Definition at line 479 of file class.ilECSCourseCreationHandler.php.

References $title, ilObject\_lookupObjId(), createCourseReference(), getImportId(), setImported(), and setObjectCreated().

Referenced by createParallelCourses(), and updateParallelCourses().

480  {
481  if ($this->getImportId($course->lectureID, $group->id)) {
482  $this->log->debug('Parallel course already created');
483  return false;
484  }
485 
486  include_once './Modules/Course/classes/class.ilObjCourse.php';
487  $course_obj = new ilObjCourse();
488  $course_obj->setOwner(SYSTEM_USER_ID);
489  $title = $course->title;
490  if (strlen($group->title)) {
491  $title .= ' (' . $group->title . ')';
492  }
493  $this->log->debug('Creating new parallel course instance from ecs : ' . $title);
494  $course_obj->setTitle($title);
495  $course_obj->setSubscriptionMaxMembers((int) $group->maxParticipants);
496  $course_obj->setOfflineStatus(true);
497  $course_obj->create();
498 
499  $this->createCourseReference($course_obj, ilObject::_lookupObjId($parent_ref));
500  $this->setImported($course->lectureID, $course_obj, $a_content_id, $group->id);
501  $this->setObjectCreated(true);
502  return true;
503  }
getImportId($a_content_id, $a_sub_id=null)
Get import id of remote course Return 0 if object isn't imported.
Class ilObjCourse.
createCourseReference($crs, $a_parent_obj_id)
Create course reference.
static _lookupObjId($a_id)
setObjectCreated($a_status)
Set object created status.
setImported($a_content_id, $object, $a_ecs_id=0, $a_sub_id=null)
Set new course object imported.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createParallelCourses()

ilECSCourseCreationHandler::createParallelCourses (   $a_content_id,
  $course,
  $parent_ref 
)
protected

Create parallel courses.

Parameters
intecontent id
type$course
type$parent_ref

Definition at line 465 of file class.ilECSCourseCreationHandler.php.

References createParallelCourse().

Referenced by doSync().

466  {
467  foreach ((array) $course->groups as $group) {
468  $this->createParallelCourse($a_content_id, $course, $group, $parent_ref);
469  }
470  return true;
471  }
createParallelCourse($a_content_id, $course, $group, $parent_ref)
Create parallel course.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createParallelGroup()

ilECSCourseCreationHandler::createParallelGroup (   $a_content_id,
  $course,
  $group,
  $parent_ref 
)
protected

Create parallel group.

Parameters
type$course
type$group

Definition at line 559 of file class.ilECSCourseCreationHandler.php.

References $title, GRP_TYPE_CLOSED, setImported(), and setObjectCreated().

Referenced by createParallelGroups(), and updateParallelGroups().

560  {
561  include_once './Modules/Group/classes/class.ilObjGroup.php';
562  $group_obj = new ilObjGroup();
563  $group_obj->setOwner(SYSTEM_USER_ID);
564  $title = strlen($group->title) ? $group->title : $course->title;
565  $group_obj->setTitle($title);
566  $group_obj->setMaxMembers((int) $group->maxParticipants);
567  $group_obj->create();
568  $group_obj->createReference();
569  $group_obj->putInTree($parent_ref);
570  $group_obj->setPermissions($parent_ref);
571  $group_obj->updateGroupType(GRP_TYPE_CLOSED);
572  $this->setImported($course->lectureID, $group_obj, $a_content_id, $group->id);
573  $this->setObjectCreated(true);
574  }
const GRP_TYPE_CLOSED
setObjectCreated($a_status)
Set object created status.
setImported($a_content_id, $object, $a_ecs_id=0, $a_sub_id=null)
Set new course object imported.
Class ilObjGroup.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createParallelGroups()

ilECSCourseCreationHandler::createParallelGroups (   $a_content_id,
  $course,
  $parent_ref 
)
protected

This create parallel groups.

Parameters
type$course
ilObjCourse

Definition at line 546 of file class.ilECSCourseCreationHandler.php.

References createParallelGroup().

Referenced by doSync().

547  {
548  foreach ((array) $course->groups as $group) {
549  $this->createParallelGroup($a_content_id, $course, $group, $parent_ref);
550  }
551  return true;
552  }
createParallelGroup($a_content_id, $course, $group, $parent_ref)
Create parallel group.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ doAttributeMapping()

ilECSCourseCreationHandler::doAttributeMapping (   $a_content_id,
  $course 
)
protected

Sync attribute mapping.

Parameters
type$a_content_id
type$course

Definition at line 152 of file class.ilECSCourseCreationHandler.php.

References $GLOBALS, ilObject\_getAllReferences(), ilObject\_lookupObjId(), createCourseReferenceObjects(), ilLogLevel\DEBUG, ilECSCourseMappingRule\doMappings(), doSync(), getImportId(), getMapping(), getMid(), ilECSCourseMappingRule\getRuleRefIds(), getServer(), and ilECSCourseMappingRule\isMatching().

Referenced by handle().

153  {
154  // Check if course is already created
155  $course_id = $course->lectureID;
156  $obj_id = $this->getImportId($course_id);
157 
158  if ($obj_id) {
159  // do update
160  $this->log->debug('Performing update of already imported course.');
161 
162  $refs = ilObject::_getAllReferences($obj_id);
163  $ref = end($refs);
164 
165  $this->doSync(
166  $a_content_id,
167  $course,
168  ilObject::_lookupObjId($GLOBALS['DIC']['tree']->getParentId($ref))
169  );
170  return true;
171  }
172 
173  // Get all rules
174  $matching_rules = [];
175  include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseMappingRule.php';
176  foreach (ilECSCourseMappingRule::getRuleRefIds($this->getServer()->getServerId(), $this->getMid()) as $ref_id) {
177  $matching_index = ilECSCourseMappingRule::isMatching(
178  $course,
179  $this->getServer()->getServerId(),
180  $this->getMid(),
181  $ref_id
182  );
183  if (strcmp($matching_index, '0') !== 0) {
184  $matching_rules[$matching_index] = $ref_id;
185  }
186  }
187  ksort($matching_rules);
188 
189  $this->log->dump($matching_rules);
190 
191  if (!count($matching_rules)) {
192  // Put course in default category
193  $this->log->debug('No matching attribute mapping rule found.');
194  $this->log->info('Using course default category');
195  $this->doSync($a_content_id, $course, ilObject::_lookupObjId($this->getMapping()->getDefaultCourseCategory()));
196  return true;
197  }
198 
199  $this->log->debug('Matching rules:');
200  $this->log->dump($matching_rules, ilLogLevel::DEBUG);
201 
202  $all_parent_refs = [];
203  foreach ($matching_rules as $matching_rule) {
204  $this->log->debug('Handling matching rule: ' . $matching_rule);
205  $parent_refs = ilECSCourseMappingRule::doMappings($course, $this->getServer()->getServerId(), $this->getMid(), $matching_rule);
206  // map according mapping rules
207  $this->log->debug('Adding parent references: ');
208  $this->log->dump($parent_refs);
209 
210  if (count($parent_refs)) {
211  $all_parent_refs = array_unique(array_merge($all_parent_refs, $parent_refs));
212  }
213  }
214 
215  // parent refs are an array of created categories
216  // the first ref should contain the main course or parallel courses.
217  // all other refs wil contain course references.
218  $first = true;
219  foreach ($all_parent_refs as $category_ref) {
220  if ($first) {
221  $this->log->debug('Creating new course instance in: ' . $category_ref);
222  $this->doSync($a_content_id, $course, ilObject::_lookupObjId($category_ref));
223  $first = false;
224  continue;
225  } else {
226  $this->log->debug('Creating new course reference instance in: ' . $category_ref);
227  $this->createCourseReferenceObjects($category_ref);
228  }
229  }
230  return true;
231  }
static doMappings($course, $a_sid, $a_mid, $a_ref_id)
static isMatching($course, $a_sid, $a_mid, $a_ref_id)
Check if rule matches.
static _getAllReferences($a_id)
get all reference ids of object
getImportId($a_content_id, $a_sub_id=null)
Get import id of remote course Return 0 if object isn't imported.
static _lookupObjId($a_id)
static getRuleRefIds($a_sid, $a_mid)
createCourseReferenceObjects($a_parent_ref_id)
Create course reference objects.
doSync($a_content_id, $course, $a_parent_obj_id)
Handle all in one setting.
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ doSync()

ilECSCourseCreationHandler::doSync (   $a_content_id,
  $course,
  $a_parent_obj_id 
)
protected

Handle all in one setting.

Parameters
type$a_content_id
type$course
Returns
array created course reference references

Definition at line 378 of file class.ilECSCourseCreationHandler.php.

References ilObject\_getAllReferences(), createCourseData(), createCourseReference(), createParallelCourses(), createParallelGroups(), getCourseUrl(), getImportId(), handleCourseUrlUpdate(), ilECSMappingUtils\PARALLEL_ALL_COURSES, ilECSMappingUtils\PARALLEL_COURSES_FOR_LECTURERS, ilECSMappingUtils\PARALLEL_GROUPS_IN_COURSE, ilECSMappingUtils\PARALLEL_ONE_COURSE, setImported(), updateCourseData(), updateParallelCourses(), and updateParallelGroups().

Referenced by doAttributeMapping(), and handle().

379  {
380  // Check if course is already created
381  $course_id = $course->lectureID;
382  $this->getCourseUrl()->setCmsLectureId($course_id);
383 
384  $obj_id = $this->getImportId($course_id);
385 
386  $this->log->debug('Found obj_id ' . $obj_id . ' for course_id ' . $course_id);
387 
388  // Handle parallel groups
389  if ($obj_id) {
390  // update multiple courses/groups according to parallel scenario
391  $this->log->debug('Group scenario ' . $course->groupScenario);
392  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSMappingUtils.php';
393  switch ((int) $course->groupScenario) {
395  $this->log->debug('Performing update for parallel groups in course.');
396  $this->updateParallelGroups($a_content_id, $course, $obj_id);
397  break;
398 
400  $this->log->debug('Performing update for parallel courses.');
401  $this->updateParallelCourses($a_content_id, $course, $a_parent_obj_id);
402  break;
403 
405  default:
406  // nothing to do
407  break;
408 
409  }
410 
411  // do update
412  $this->updateCourseData($course, $obj_id);
413  } else {
414  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSMappingUtils.php';
415  switch ((int) $course->groupScenario) {
417  $this->log->debug('Parallel scenario "groups in courses".');
418  $crs = $this->createCourseData($course);
419  $crs = $this->createCourseReference($crs, $a_parent_obj_id);
420  $this->setImported($course_id, $crs, $a_content_id);
421 
422  // Create parallel groups under crs
423  $this->createParallelGroups($a_content_id, $course, $crs->getRefId());
424  break;
425 
427  $this->log->debug('Parallel scenario "Courses foreach Lecturer".');
428  // Import empty to store the ecs ressource id (used for course member update).
429  $this->setImported($course_id, null, $a_content_id);
430  break;
431 
433  $this->log->debug('Parallel scenario "Many courses".');
434  $refs = ilObject::_getAllReferences($a_parent_obj_id);
435  $ref = end($refs);
436  // do not create master course for this scenario
437  //$crs = $this->createCourseData($course);
438  //$this->createCourseReference($crs, $a_parent_obj_id);
439  //$this->setImported($course_id, $crs, $a_content_id);
440  $this->createParallelCourses($a_content_id, $course, $ref);
441  break;
442 
443  default:
445  $this->log->debug('Parallel scenario "One Course".');
446  $crs = $this->createCourseData($course);
447  $this->createCourseReference($crs, $a_parent_obj_id);
448  $this->setImported($course_id, $crs, $a_content_id);
449  break;
450 
451 
452  }
453  }
454  // finally update course urls
455  $this->handleCourseUrlUpdate();
456  return true;
457  }
updateParallelCourses($a_content_id, $course, $parent_obj)
Update parallel group data.
createParallelCourses($a_content_id, $course, $parent_ref)
Create parallel courses.
static _getAllReferences($a_id)
get all reference ids of object
getImportId($a_content_id, $a_sub_id=null)
Get import id of remote course Return 0 if object isn't imported.
createCourseReference($crs, $a_parent_obj_id)
Create course reference.
updateParallelGroups($a_content_id, $course, $parent_obj)
Update parallel group data.
setImported($a_content_id, $object, $a_ecs_id=0, $a_sub_id=null)
Set new course object imported.
updateCourseData($course, $obj_id)
Update course data.
createParallelGroups($a_content_id, $course, $parent_ref)
This create parallel groups.
createCourseData($course)
Create course data from json.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCourseUrl()

ilECSCourseCreationHandler::getCourseUrl ( )

Get course url.

Returns
ilECSCourseUrl Description

Definition at line 70 of file class.ilECSCourseCreationHandler.php.

References $course_url.

Referenced by addUrlEntry(), doSync(), handle(), and handleCourseUrlUpdate().

+ Here is the caller graph for this function:

◆ getCreatedCourses()

ilECSCourseCreationHandler::getCreatedCourses ( )
protected

get created courses

Returns
array

Definition at line 97 of file class.ilECSCourseCreationHandler.php.

References $courses_created.

Referenced by createCourseReferenceObjects().

+ Here is the caller graph for this function:

◆ getImportId()

ilECSCourseCreationHandler::getImportId (   $a_content_id,
  $a_sub_id = null 
)
protected

Get import id of remote course Return 0 if object isn't imported.

Searches for the (hopefully) unique content id of an imported object

Parameters
type$a_content_id
Returns
type

Definition at line 613 of file class.ilECSCourseCreationHandler.php.

References getMid(), getServer(), and ilECSImport\lookupObjIdByContentId().

Referenced by createParallelCourse(), doAttributeMapping(), doSync(), syncNodeToTop(), updateParallelCourses(), and updateParallelGroups().

614  {
615  include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
617  $this->getServer()->getServerId(),
618  $this->getMid(),
619  $a_content_id,
620  $a_sub_id
621  );
622  }
static lookupObjIdByContentId($a_server_id, $a_mid, $a_content_id, $a_sub_id=null)
Lookup obj_id by content id.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMapping()

ilECSCourseCreationHandler::getMapping ( )

Get mapping settings.

Returns
ilECSNodeMappingSettings

Definition at line 61 of file class.ilECSCourseCreationHandler.php.

References $mapping.

Referenced by doAttributeMapping(), and handle().

+ Here is the caller graph for this function:

◆ getMid()

ilECSCourseCreationHandler::getMid ( )

Get mid of course event.

Returns
type

Definition at line 106 of file class.ilECSCourseCreationHandler.php.

References $mid.

Referenced by __construct(), doAttributeMapping(), getImportId(), handleCourseUrlUpdate(), setImported(), syncCategory(), syncNodeToTop(), and syncParentContainer().

+ Here is the caller graph for this function:

◆ getServer()

ilECSCourseCreationHandler::getServer ( )

Get server settings.

Returns
ilECSSetting

Definition at line 52 of file class.ilECSCourseCreationHandler.php.

References $server.

Referenced by __construct(), doAttributeMapping(), getImportId(), handleCourseUrlUpdate(), setImported(), syncCategory(), syncNodeToTop(), and syncParentContainer().

+ Here is the caller graph for this function:

◆ handle()

ilECSCourseCreationHandler::handle (   $a_content_id,
  $course 
)

Handle sync request.

Parameters
intecs content id
type$course

Definition at line 116 of file class.ilECSCourseCreationHandler.php.

References ilObject\_lookupObjId(), ilObject\_lookupTitle(), doAttributeMapping(), doSync(), getCourseUrl(), getMapping(), setObjectCreated(), and syncParentContainer().

117  {
118  // prepare course url
119  // if any object (course group) will be created, a list of all course urls
120  // will be sent to ecs.
121  $this->setObjectCreated(false);
122  $this->getCourseUrl()->setECSId($a_content_id);
123 
124 
125  if ($this->getMapping()->isAttributeMappingEnabled()) {
126  $this->log->debug('Handling advanced attribute mapping');
127  return $this->doAttributeMapping($a_content_id, $course);
128  }
129 
130  if ($this->getMapping()->isAllInOneCategoryEnabled()) {
131  $this->log->debug('Handling course all in one category setting');
132  $this->doSync($a_content_id, $course, ilObject::_lookupObjId($this->getMapping()->getAllInOneCategory()));
133  return true;
134  }
135 
136  $parent_obj_id = $this->syncParentContainer($a_content_id, $course);
137  if ($parent_obj_id) {
138  $this->log->info('Using already mapped category: ' . ilObject::_lookupTitle($parent_obj_id));
139  $this->doSync($a_content_id, $course, $parent_obj_id);
140  return true;
141  }
142  $this->log->info('Using course default category');
143  $this->doSync($a_content_id, $course, ilObject::_lookupObjId($this->getMapping()->getDefaultCourseCategory()));
144  return true;
145  }
static _lookupTitle($a_id)
lookup object title
static _lookupObjId($a_id)
setObjectCreated($a_status)
Set object created status.
doAttributeMapping($a_content_id, $course)
Sync attribute mapping.
doSync($a_content_id, $course, $a_parent_obj_id)
Handle all in one setting.
syncParentContainer($a_content_id, $course)
Sync parent container.
+ Here is the call graph for this function:

◆ handleCourseUrlUpdate()

ilECSCourseCreationHandler::handleCourseUrlUpdate ( )
protected

Update course url.

Definition at line 735 of file class.ilECSCourseCreationHandler.php.

References $GLOBALS, getCourseUrl(), getMid(), getServer(), and isObjectCreated().

Referenced by doSync().

736  {
737  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': Starting course url update');
738  if ($this->isObjectCreated()) {
739  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': Sending new course group url');
740  $this->getCourseUrl()->send($this->getServer(), $this->getMid());
741  } else {
742  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': No courses groups created. Aborting');
743  }
744  }
isObjectCreated()
Check if an object (course / group) has been created.
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isObjectCreated()

ilECSCourseCreationHandler::isObjectCreated ( )

Check if an object (course / group) has been created.

Returns
bool

Definition at line 79 of file class.ilECSCourseCreationHandler.php.

References $object_created.

Referenced by handleCourseUrlUpdate().

+ Here is the caller graph for this function:

◆ setImported()

ilECSCourseCreationHandler::setImported (   $a_content_id,
  $object,
  $a_ecs_id = 0,
  $a_sub_id = null 
)
protected

Set new course object imported.

Parameters
int$a_content_id
ilObjCourse$crs

Definition at line 693 of file class.ilECSCourseCreationHandler.php.

References getMid(), getServer(), and ilECSImport\setSubId().

Referenced by createParallelCourse(), createParallelGroup(), and doSync().

694  {
695  include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
696  $import = new ilECSImport(
697  $this->getServer()->getServerId(),
698  is_object($object) ? $object->getId() : 0
699  );
700 
701 
702  $import->setSubId($a_sub_id);
703  $import->setMID($this->getMid());
704  $import->setEContentId($a_ecs_id);
705  $import->setContentId($a_content_id);
706  $import->setImported(true);
707  $import->save();
708  return true;
709  }
Storage of ECS imported objects.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setObjectCreated()

ilECSCourseCreationHandler::setObjectCreated (   $a_status)

Set object created status.

Parameters
bool$a_status

Definition at line 88 of file class.ilECSCourseCreationHandler.php.

Referenced by createCourseReference(), createParallelCourse(), createParallelGroup(), and handle().

89  {
90  $this->object_created = $a_status;
91  }
+ Here is the caller graph for this function:

◆ syncCategory()

ilECSCourseCreationHandler::syncCategory (   $tobj_id,
  $parent_ref_id 
)
protected

Sync category.

Parameters
type$tobj_id
type$parent_ref_id

Definition at line 338 of file class.ilECSCourseCreationHandler.php.

References $data, $GLOBALS, getMid(), getServer(), and ilECSImport\setMID().

Referenced by syncNodeToTop().

339  {
340  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php';
341  $data = new ilECSCmsData($tobj_id);
342 
343  include_once './Modules/Category/classes/class.ilObjCategory.php';
344  $cat = new ilObjCategory();
345  $cat->setOwner(SYSTEM_USER_ID);
346  $cat->setTitle($data->getTitle());
347  $cat->create(); // true for upload
348  $cat->createReference();
349  $cat->putInTree($parent_ref_id);
350  $cat->setPermissions($parent_ref_id);
351  $cat->deleteTranslation($GLOBALS['DIC']['lng']->getDefaultLanguage());
352  $cat->addTranslation(
353  $data->getTitle(),
354  $cat->getLongDescription(),
355  $GLOBALS['DIC']['lng']->getDefaultLanguage(),
356  1
357  );
358 
359  // set imported
360  $import = new ilECSImport(
361  $this->getServer()->getServerId(),
362  $cat->getId()
363  );
364  $import->setMID($this->getMid());
365  $import->setContentId($data->getCmsId());
366  $import->setImported(true);
367  $import->save();
368 
369  return $cat->getId();
370  }
Storage of ECS imported objects.
Class ilObjCategory.
setMID($a_mid)
set mid
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
$data
Definition: bench.php:6
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ syncNodeToTop()

ilECSCourseCreationHandler::syncNodeToTop (   $tree_id,
  $cms_id 
)
protected

Sync node to top.

Parameters
type$tree_id
type$parent_id
Returns
int obj_id of container

Definition at line 284 of file class.ilECSCourseCreationHandler.php.

References $GLOBALS, $tree, ilObject\_getAllReferences(), getImportId(), getMid(), getServer(), ilECSCmsData\lookupCmsIds(), ilECSCmsData\lookupObjId(), and syncCategory().

285  {
286  $obj_id = $this->getImportId($cms_id);
287  if ($obj_id) {
288  // node already imported
289  return $obj_id;
290  }
291 
292  $tobj_id = ilECSCmsData::lookupObjId(
293  $this->getServer()->getServerId(),
294  $this->getMid(),
295  $tree_id,
296  $cms_id
297  );
298 
299  // node is not imported
300  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': ecs node with id ' . $cms_id . ' is not imported for mid ' . $this->getMid() . ' tree_id ' . $tree_id);
301 
302  // check for mapping: if mapping is available create category
303  include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingAssignment.php';
304  $ass = new ilECSNodeMappingAssignment(
305  $this->getServer()->getServerId(),
306  $this->getMid(),
307  $tree_id,
308  $tobj_id
309  );
310 
311  if ($ass->isMapped()) {
312  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': node is mapped');
313  return $this->syncCategory($tobj_id, $ass->getRefId());
314  }
315 
316  // Start recursion to top
317  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTree.php';
318  $tree = new ilECSCmsTree($tree_id);
319  $parent_tobj_id = $tree->getParentId($tobj_id);
320  if ($parent_tobj_id) {
321  $cms_ids = ilECSCmsData::lookupCmsIds(array($parent_tobj_id));
322  $obj_id = $this->syncNodeToTop($tree_id, $cms_ids[0]);
323  }
324 
325  if ($obj_id) {
326  $refs = ilObject::_getAllReferences($obj_id);
327  $ref_id = end($refs);
328  return $this->syncCategory($tobj_id, $ref_id);
329  }
330  return 0;
331  }
syncNodeToTop($tree_id, $cms_id)
Sync node to top.
static lookupObjId($a_server_id, $a_mid, $a_tree_id, $cms_id)
syncCategory($tobj_id, $parent_ref_id)
Sync category.
static _getAllReferences($a_id)
get all reference ids of object
getImportId($a_content_id, $a_sub_id=null)
Get import id of remote course Return 0 if object isn't imported.
static lookupCmsIds($a_obj_ids)
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
+ Here is the call graph for this function:

◆ syncParentContainer()

ilECSCourseCreationHandler::syncParentContainer (   $a_content_id,
  $course 
)
protected

Sync parent container.

Parameters
type$a_content_id
type$course

Definition at line 261 of file class.ilECSCourseCreationHandler.php.

References $GLOBALS, getMid(), getServer(), and ilECSCmsData\lookupFirstTreeOfNode().

Referenced by handle().

262  {
263  if (!is_array($course->allocations)) {
264  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': No allocation in course defined.');
265  return 0;
266  }
267  if (!$course->allocations[0]->parentID) {
268  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': No allocation parent in course defined.');
269  return 0;
270  }
271  $parent_id = $course->allocations[0]->parentID;
272 
273  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php';
274  $parent_tid = ilECSCmsData::lookupFirstTreeOfNode($this->getServer()->getServerId(), $this->getMid(), $parent_id);
275  return $this->syncNodetoTop($parent_tid, $parent_id);
276  }
static lookupFirstTreeOfNode($a_server_id, $a_mid, $cms_id)
Lookup first obj_id of cms node $ilDB $ilDB.
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updateCourseData()

ilECSCourseCreationHandler::updateCourseData (   $course,
  $obj_id 
)
protected

Update course data.

Parameters
type$course

Definition at line 628 of file class.ilECSCourseCreationHandler.php.

References $GLOBALS, $title, ilObject\_getAllReferences(), and ilObjectFactory\getInstanceByRefId().

Referenced by doSync().

629  {
630  // do update
631  $refs = ilObject::_getAllReferences($obj_id);
632  $ref_id = end($refs);
633  $crs_obj = ilObjectFactory::getInstanceByRefId($ref_id, false);
634  if (!$crs_obj instanceof ilObject) {
635  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': Cannot instantiate course instance');
636  return true;
637  }
638 
639  // Update title
640  $title = $course->title;
641  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': new title is : ' . $title);
642 
643  $crs_obj->setTitle($title);
644  $crs_obj->update();
645  return true;
646  }
static _getAllReferences($a_id)
get all reference ids of object
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updateParallelCourses()

ilECSCourseCreationHandler::updateParallelCourses (   $a_content_id,
  $course,
  $parent_obj 
)
protected

Update parallel group data.

Parameters
type$course
type$parent_obj

Definition at line 510 of file class.ilECSCourseCreationHandler.php.

References $title, ilObject\_getAllReferences(), addUrlEntry(), createParallelCourse(), getImportId(), and ilObjectFactory\getInstanceByObjId().

Referenced by doSync().

511  {
512  $parent_refs = ilObject::_getAllReferences($parent_obj);
513  $parent_ref = end($parent_refs);
514 
515  foreach ((array) $course->groups as $group) {
516  $title = $course->title;
517  if (strlen($group->title)) {
518  $title .= ' (' . $group->title . ')';
519  }
520 
521  $obj_id = $this->getImportId($course->lectureID, $group->id);
522  $this->log->debug('Imported obj id is ' . $obj_id);
523  if (!$obj_id) {
524  $this->createParallelCourse($a_content_id, $course, $group, $parent_ref);
525  } else {
526  $course_obj = ilObjectFactory::getInstanceByObjId($obj_id, false);
527  if ($course_obj instanceof ilObjCourse) {
528  $this->log->debug('New title is ' . $title);
529  $course_obj->setTitle($title);
530  $course_obj->setSubscriptionMaxMembers($group->maxParticipants);
531  $course_obj->update();
532  }
533  }
534  $this->addUrlEntry($this->getImportId($course->lectureID, $group->ID));
535  }
536  return true;
537  }
addUrlEntry($a_obj_id)
Add an url entry.
static _getAllReferences($a_id)
get all reference ids of object
getImportId($a_content_id, $a_sub_id=null)
Get import id of remote course Return 0 if object isn't imported.
createParallelCourse($a_content_id, $course, $group, $parent_ref)
Create parallel course.
Class ilObjCourse.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updateParallelGroups()

ilECSCourseCreationHandler::updateParallelGroups (   $a_content_id,
  $course,
  $parent_obj 
)
protected

Update parallel group data.

Parameters
type$course
type$parent_obj

Definition at line 582 of file class.ilECSCourseCreationHandler.php.

References $GLOBALS, $title, ilObject\_getAllReferences(), addUrlEntry(), createParallelGroup(), getImportId(), and ilObjectFactory\getInstanceByObjId().

Referenced by doSync().

583  {
584  $parent_refs = ilObject::_getAllReferences($parent_obj);
585  $parent_ref = end($parent_refs);
586 
587  foreach ((array) $course->groups as $group) {
588  $obj_id = $this->getImportId($course->lectureID, $group->id);
589  $this->log->debug('Imported obj id is ' . $obj_id);
590  if (!$obj_id) {
591  $this->createParallelGroup($a_content_id, $course, $group, $parent_ref);
592  } else {
593  $group_obj = ilObjectFactory::getInstanceByObjId($obj_id, false);
594  if ($group_obj instanceof ilObjGroup) {
595  $title = strlen($group->title) ? $group->title : $course->title;
596  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': New title is ' . $title);
597  $group_obj->setTitle($title);
598  $group_obj->setMaxMembers((int) $group->maxParticipants);
599  $group_obj->update();
600  }
601  }
602  $this->addUrlEntry($this->getImportId($course->lectureID, $group->id));
603  }
604  }
addUrlEntry($a_obj_id)
Add an url entry.
static _getAllReferences($a_id)
get all reference ids of object
getImportId($a_content_id, $a_sub_id=null)
Get import id of remote course Return 0 if object isn't imported.
createParallelGroup($a_content_id, $course, $group, $parent_ref)
Create parallel group.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
Class ilObjGroup.
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $course_url

ilECSCourseCreationHandler::$course_url = null
private

Definition at line 24 of file class.ilECSCourseCreationHandler.php.

Referenced by getCourseUrl().

◆ $courses_created

ilECSCourseCreationHandler::$courses_created = array()
private

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

Referenced by getCreatedCourses().

◆ $log

ilECSCourseCreationHandler::$log
protected

Definition at line 19 of file class.ilECSCourseCreationHandler.php.

◆ $mapping

ilECSCourseCreationHandler::$mapping = null
private

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

Referenced by getMapping().

◆ $mid

ilECSCourseCreationHandler::$mid
private

Definition at line 28 of file class.ilECSCourseCreationHandler.php.

Referenced by getMid().

◆ $object_created

ilECSCourseCreationHandler::$object_created = false
private

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

Referenced by isObjectCreated().

◆ $server

ilECSCourseCreationHandler::$server = null
private

Definition at line 22 of file class.ilECSCourseCreationHandler.php.

Referenced by __construct(), and getServer().


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