/** * 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; }
/** * Update course settings */ protected function cUpdateSettings() { $form = $this->initFormCSettings(); if ($form->checkInput()) { include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingSettings.php'; $settings = ilECSNodeMappingSettings::getInstanceByServerMid($this->getServer()->getServerId(), $this->getMid()); $settings->enableCourseAllocation($form->getInput('enabled')); $settings->setDefaultCourseCategory($form->getInput('default_cat')); $settings->enableAllInOne($form->getInput('allinone')); $settings->setAllInOneCategory($form->getInput('allinone_cat')); $settings->enableAttributeMapping($form->getInput('multiple')); $role_mappings = array(); foreach (ilECSMappingUtils::getRoleMappingInfo() as $name => $info) { $role_mappings[$name] = $form->getInput($name); } $settings->setRoleMappings($role_mappings); $settings->update(); // store attribute settings include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseAttributes.php'; $attributes = new ilECSCourseAttributes($this->getServer()->getServerId(), $this->getMid()); $attributes->delete(); $form_atts = $form->getInput('atts'); foreach ($form_atts as $name) { if (!$name) { continue; } $att = new ilECSCourseAttribute(); $att->setServerId($this->getServer()->getServerId()); $att->setMid($this->getMid()); $att->setName($name); $att->save(); } //$att = new ilECSCourseAttribute(); //$att->setName($a_name) ilUtil::sendSuccess($this->lng->txt('settings_saved'), true); $GLOBALS['ilCtrl']->redirect($this, 'cSettings'); } ilUtil::sendFailure($this->lng->txt('err_check_input')); $form->setValuesByPost(); $this->cSettings($form); }