public function performCrsGrpTrigger()
 {
     ignore_user_abort(true);
     @set_time_limit(0);
     $response = new stdClass();
     $response->succcess = false;
     $this->pluginObj->includeClass('class.ilAdobeConnectServer.php');
     if ((int) ilAdobeConnectServer::getSetting('allow_crs_grp_trigger') == 0) {
         echo json_encode($response);
         exit;
     }
     $this->pluginObj->includeClass('class.ilXAVCMembers.php');
     if (count($this->object->getParticipantsObject()->getParticipants()) > 0) {
         $sco_id = ilObjAdobeConnect::_lookupScoId(ilObject::_lookupObjectId($this->object->getRefId()));
         $current_member_ids = ilXAVCMembers::getMemberIds($this->object->getRefId());
         $crs_grp_member_ids = $this->object->getParticipantsObject()->getParticipants();
         if (count($current_member_ids) == 0 && count($crs_grp_member_ids) > 0) {
             $this->object->addCrsGrpMembers($this->object->getRefId(), $sco_id);
         } else {
             $new_member_ids = array_diff($crs_grp_member_ids, $current_member_ids);
             $delete_member_ids = array_diff($current_member_ids, $crs_grp_member_ids);
             if (is_array($new_member_ids) && count($new_member_ids) > 0) {
                 $this->object->addCrsGrpMembers($this->object->getRefId(), $sco_id, $new_member_ids);
             }
             if (is_array($delete_member_ids) && count($delete_member_ids) > 0) {
                 $this->object->deleteCrsGrpMembers($sco_id, $delete_member_ids);
             }
         }
     }
     $response->succcess = true;
     echo json_encode($response);
     exit;
 }
 public function performCrsGrpTrigger()
 {
     ignore_user_abort(true);
     @set_time_limit(0);
     $response = new stdClass();
     $response->succcess = false;
     $this->pluginObj->includeClass('class.ilAdobeConnectServer.php');
     if ((int) ilAdobeConnectServer::getSetting('allow_crs_grp_trigger') == 0) {
         echo json_encode($response);
         exit;
     }
     global $tree;
     $this->pluginObj->includeClass('class.ilXAVCMembers.php');
     $parent_crs_ref = $tree->checkForParentType($this->object->getRefId(), 'crs');
     $parent_grp_ref = $tree->checkForParentType($this->object->getRefId(), 'grp');
     $ok = false;
     if ($parent_crs_ref && empty($parent_grp_ref)) {
         $ok = true;
         $obj_id = ilObject::_lookupObjectId($parent_crs_ref);
         include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
         $oParticipants = ilCourseParticipants::_getInstanceByObjId($obj_id);
     } else {
         if ($parent_grp_ref) {
             $ok = true;
             $obj_id = ilObject::_lookupObjectId($parent_grp_ref);
             include_once 'Modules/Group/classes/class.ilGroupParticipants.php';
             $oParticipants = ilGroupParticipants::_getInstanceByObjId($obj_id);
         }
     }
     if ($ok) {
         $sco_id = ilObjAdobeConnect::_lookupScoId(ilObject::_lookupObjectId($this->object->getRefId()));
         $current_member_ids = ilXAVCMembers::getMemberIds($this->object->getRefId());
         $crs_grp_member_ids = $oParticipants->getParticipants();
         if (count($current_member_ids) == 0 && count($crs_grp_member_ids) > 0) {
             $this->object->addCrsGrpMembers($this->object->getRefId(), $sco_id);
         } else {
             $new_member_ids = array_diff($crs_grp_member_ids, $current_member_ids);
             $delete_member_ids = array_diff($current_member_ids, $crs_grp_member_ids);
             $ongoing_member_ids = array_intersect($current_member_ids, $crs_grp_member_ids);
             if (is_array($new_member_ids) && count($new_member_ids) > 0) {
                 $this->object->addCrsGrpMembers($this->object->getRefId(), $sco_id, $new_member_ids);
             }
             if (is_array($delete_member_ids) && count($delete_member_ids) > 0) {
                 $this->object->deleteCrsGrpMembers($sco_id, $delete_member_ids);
             }
             //This is necessary to assure consistency between Ilias Roles on Group/Course and on the Adobe Connect Room.
             //Excemption granted for none Switch Server Types, as there is no way to test this for us.
             $this->pluginObj->includeClass('class.ilAdobeConnectRoles.php');
             $xavc_role = new ilAdobeConnectRoles($this->object->getRefId());
             $settings = ilAdobeConnectServer::_getInstance();
             if ($settings->getAuthMode() == ilAdobeConnectServer::AUTH_MODE_SWITCHAAI) {
                 foreach ($ongoing_member_ids as $member_id) {
                     $is_admin = $xavc_role->isAdministrator($member_id);
                     if ($oParticipants->isAdmin($member_id) && !$is_admin) {
                         $xavc_role->detachMemberRole($member_id);
                         $xavc_role->addAdministratorRole($member_id);
                     } else {
                         if ($oParticipants->isMember($member_id) && $is_admin) {
                             $xavc_role->detachAdministratorRole($member_id);
                             $xavc_role->addMemberRole($member_id);
                         }
                     }
                 }
             }
         }
     }
     $response->succcess = true;
     echo json_encode($response);
     exit;
 }