/**
  * Refresh status of course member assignments
  * @param object $course_member
  * @param int $obj_id
  */
 protected function refreshAssignmentStatus($course_member, $obj_id, $sub_id, $assigned)
 {
     include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseMemberAssignment.php';
     $type = ilObject::_lookupType($obj_id);
     if ($type == 'crs') {
         include_once './Modules/Course/classes/class.ilCourseParticipants.php';
         $part = ilCourseParticipants::_getInstanceByObjId($obj_id);
     } else {
         include_once './Modules/Group/classes/class.ilGroupParticipants.php';
         $part = ilGroupParticipants::_getInstanceByObjId($obj_id);
     }
     $course_id = (int) $course_member->lectureID;
     $usr_ids = ilECSCourseMemberAssignment::lookupUserIds($course_id, $sub_id, $obj_id);
     // Delete remote deleted
     foreach ((array) $usr_ids as $usr_id) {
         if (!isset($assigned[$usr_id])) {
             $ass = ilECSCourseMemberAssignment::lookupAssignment($course_id, $sub_id, $obj_id, $usr_id);
             if ($ass instanceof ilECSCourseMemberAssignment) {
                 $acc = ilObjUser::_checkExternalAuthAccount(ilECSSetting::lookupAuthMode(), (string) $usr_id);
                 if ($il_usr_id = ilObjUser::_lookupId($acc)) {
                     // this removes also admin, tutor roles
                     $part->delete($il_usr_id);
                     $GLOBALS['ilLog']->write(__METHOD__ . ': Deassigning user ' . $usr_id . ' ' . 'from course ' . ilObject::_lookupTitle($obj_id));
                 } else {
                     $GLOBALS['ilLog']->write(__METHOD__ . ': Deassigning unknown ILIAS user ' . $usr_id . ' ' . 'from course ' . ilObject::_lookupTitle($obj_id));
                 }
                 $ass->delete();
             }
         }
     }
     // Assign new participants
     foreach ((array) $assigned as $person_id => $person) {
         $role = $this->lookupRole($person['role']);
         $role_info = ilECSMappingUtils::getRoleMappingInfo($role);
         $acc = ilObjUser::_checkExternalAuthAccount(ilECSSetting::lookupAuthMode(), (string) $person_id);
         $GLOBALS['ilLog']->write(__METHOD__ . ': Handling user ' . (string) $person_id);
         if (in_array($person_id, $usr_ids)) {
             if ($il_usr_id = ilObjUser::_lookupId($acc)) {
                 $GLOBALS['ilLog']->write(__METHOD__ . ': ' . print_r($role, true));
                 $part->updateRoleAssignments($il_usr_id, array($role));
                 // Nothing to do, user is member or is locally deleted
             }
         } else {
             if ($il_usr_id = ilObjUser::_lookupId($acc)) {
                 if ($role) {
                     // Add user
                     $GLOBALS['ilLog']->write(__METHOD__ . ': Assigning new user ' . $person_id . ' ' . 'to ' . ilObject::_lookupTitle($obj_id));
                     $part->add($il_usr_id, $role);
                 }
             } else {
                 if ($role_info['create']) {
                     $this->createMember($person_id);
                     $GLOBALS['ilLog']->write(__METHOD__ . ': Added new user ' . $person_id);
                 }
             }
             $assignment = new ilECSCourseMemberAssignment();
             $assignment->setServer($this->getServer()->getServerId());
             $assignment->setMid($this->mid);
             $assignment->setCmsId($course_id);
             $assignment->setCmsSubId($sub_id);
             $assignment->setObjId($obj_id);
             $assignment->setUid($person_id);
             $assignment->save();
         }
     }
     return true;
 }
 /**
  * Assign mmissing course/groups to new user accounts
  * @param ilObjUser $user
  */
 protected static function handleMembership(ilObjUser $user)
 {
     $GLOBALS['ilLog']->write(__METHOD__ . ': Handling ECS assignments ');
     include_once './Services/WebServices/ECS/classes/class.ilECSSetting.php';
     if ($user->getAuthMode() != ilECSSetting::lookupAuthMode()) {
         $GLOBALS['ilLog']->write(__METHOD__ . ': Not user with authmode ' . ilECSSetting::lookupAuthMode());
         return TRUE;
     }
     include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseMemberAssignment.php';
     $assignment_ids = ilECSCourseMemberAssignment::lookupMissingAssignmentsOfUser($user->getExternalAccount());
     foreach ($assignment_ids as $obj_id) {
         include_once './Services/Membership/classes/class.ilParticipants.php';
         $part = ilParticipants::getInstanceByObjId($obj_id);
         $part->add($user->getId(), IL_CRS_MEMBER);
     }
 }