/**
  * 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;
 }
 /**
  * Init form settings
  */
 protected function dInitFormTreeSettings(ilPropertyFormGUI $form = null)
 {
     include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSMappingUtils.php';
     include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTree.php';
     if ($form instanceof ilPropertyFormGUI) {
         return $form;
     }
     include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingAssignment.php';
     $assignment = new ilECSNodeMappingAssignment($this->getServer()->getServerId(), $this->getMid(), (int) $_REQUEST['tid'], 0);
     include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
     $form = new ilPropertyFormGUI();
     $form->setFormAction($this->ctrl->getFormAction($this, 'dEditTree'));
     $form->setTitle($this->lng->txt('general_settings'));
     $form->addCommandButton('dUpdateTreeSettings', $this->lng->txt('save'));
     $form->addCommandButton('dTrees', $this->lng->txt('cancel'));
     $form->setTableWidth('30%');
     // CMS id (readonly)
     include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php';
     $cmsid = new ilNumberInputGUI($this->lng->txt('ecs_cms_id'), 'cmsid');
     $cmsid->setValue(ilECSCmsData::lookupCmsId(ilECSCmsTree::lookupRootId((int) $_REQUEST['tid'])));
     $cmsid->setDisabled(true);
     $cmsid->setSize(7);
     $cmsid->setMaxLength(12);
     $form->addItem($cmsid);
     $mapping_status = ilECSMappingUtils::lookupMappingStatus($this->getServer()->getServerId(), $this->getMid(), (int) $_REQUEST['tid']);
     $mapping_advanced = $mapping_status != ilECSMappingUtils::MAPPED_MANUAL ? true : false;
     // Status (readonly)
     $status = new ilNonEditableValueGUI($this->lng->txt('status'), '');
     $status->setValue(ilECSMappingUtils::mappingStatusToString($mapping_status));
     $form->addItem($status);
     // title update
     $title = new ilCheckboxInputGUI($this->lng->txt('ecs_title_updates'), 'title');
     $title->setValue(1);
     $title->setChecked($assignment->isTitleUpdateEnabled());
     #$title->setInfo($this->lng->txt('ecs_title_update_info'));
     $form->addItem($title);
     $position = new ilCheckboxInputGUI($this->lng->txt('ecs_position_updates'), 'position');
     $position->setDisabled(!$mapping_advanced);
     $position->setChecked($mapping_advanced && $assignment->isPositionUpdateEnabled());
     $position->setValue(1);
     #$position->setInfo($this->lng->txt('ecs_position_update_info'));
     $form->addItem($position);
     $tree = new ilCheckboxInputGUI($this->lng->txt('ecs_tree_updates'), 'tree');
     $tree->setDisabled(!$mapping_advanced);
     $tree->setChecked($mapping_advanced && $assignment->isTreeUpdateEnabled());
     $tree->setValue(1);
     #$tree->setInfo($this->lng->txt('ecs_tree_update_info'));
     $form->addItem($tree);
     return $form;
 }
 /**
  * Parse campusconnect
  */
 public function parse()
 {
     include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSMappingUtils.php';
     include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php';
     include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTree.php';
     $data = array();
     $counter = 0;
     foreach (ilECSCmsData::lookupTreeIds($this->getServer()->getServerId(), $this->getMid()) as $tree_id) {
         $root = new ilECSCmsTree($tree_id);
         $node = new ilECSCmsData($root->getRootId());
         $data[$counter]['id'] = $tree_id;
         $data[$counter]['status'] = ilECSMappingUtils::lookupMappingStatus($this->getServer()->getServerId(), $this->getMid(), $tree_id);
         $data[$counter]['title'] = $node->getTitle();
         $data[$counter]['term'] = ilECSCmsData::lookupTopTerm($this->getServer()->getServerId(), $this->getMid(), $tree_id);
         $counter++;
     }
     $this->setData($data);
 }
 /**
  * Check if rule matches
  * @param type $course
  * @return boolean
  */
 public function matches($course)
 {
     if ($this->isFilterEnabled()) {
         include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSMappingUtils.php';
         $value = ilECSMappingUtils::getCourseValueByMappingAttribute($course, $this->getAttribute());
         $GLOBALS['ilLog']->write(__METHOD__ . ': Comparing ' . $value . ' with ' . $this->getFilter());
         return strcmp($value, $this->getFilter()) === 0;
     }
     return true;
 }