/** * Get single directory tree * @return mixed object of EContentDetails or object of ECSEnrolmentStatus */ public function getEnrolmentStatus($a_enrole_id = 0, $a_details = false) { if ($a_enrole_id) { $this->path_postfix = '/campusconnect/member_status/' . (int) $a_enrole_id; } if ($a_details and $a_enrole_id) { $this->path_postfix .= '/details'; } try { $this->prepareConnection(); $this->setHeader(array()); if ($a_details) { $this->addHeader('Accept', 'application/json'); } else { #$this->addHeader('Accept', 'text/uri-list'); } $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader()); $res = $this->call(); if (substr($res, 0, 4) == 'http') { $json = file_get_contents($res); $ecs_result = new ilECSResult($json); } else { $ecs_result = new ilECSResult($res); } // Return ECSEContentDetails for details switch if ($a_details) { include_once './Services/WebServices/ECS/classes/class.ilECSEContentDetails.php'; $details = new ilECSEContentDetails(); $GLOBALS['ilLog']->write(print_r($res, true)); $details->loadFromJson($ecs_result->getResult()); return $details; } else { include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php'; $enrolment = new ilECSEnrolmentStatus(); $enrolment->loadFromJson($ecs_result->getResult()); return $enrolment; } } catch (ilCurlConnectionException $e) { throw new ilECSConnectorException('Error calling ECS service: ' . $e->getMessage()); } }
/** * Update enrolment status * @param type $a_obj_id * @param ilObjUser $user * @param type $a_status * @return boolean */ protected static function updateEnrolmentStatus($a_obj_id, ilObjUser $user, $a_status) { include_once './Services/WebServices/ECS/classes/class.ilECSRemoteUser.php'; $remote = ilECSRemoteUser::factory($user->getId()); if (!$remote instanceof ilECSRemoteUser) { return FALSE; } include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatus.php'; $enrol = new ilECSEnrolmentStatus(); $enrol->setId('il_' . $GLOBALS['ilSetting']->get('inst_id', 0) . '_' . ilObject::_lookupType($a_obj_id) . '_' . $a_obj_id); $enrol->setPersonId($remote->getRemoteUserId()); $enrol->setPersonIdType(ilECSEnrolmentStatus::ID_UID); $enrol->setStatus($a_status); try { include_once './Services/WebServices/ECS/classes/Connectors/class.ilECSEnrolmentStatusConnector.php'; $con = new ilECSEnrolmentStatusConnector(ilECSSetting::getInstanceByServerId(1)); $con->addEnrolmentStatus($enrol, $remote->getMid()); } catch (ilECSConnectorException $e) { $GLOBALS['ilLog']->write(__METHOD__ . ': update enrolment status faild with message: ' . $e->getMessage()); return false; } }
/** * Perform update * @param type $a_content_id * @param type $course */ protected function doUpdate($a_usr_id, ilECSEnrolmentStatus $status) { include_once './Services/WebServices/ECS/classes/class.ilECSImport.php'; $obj_ids = ilECSImport::lookupObjIdsByContentId($status->getId()); $obj_id = end($obj_ids); $ref_ids = ilObject::_getAllReferences($obj_id); $ref_id = end($ref_ids); if (!$ref_id) { // Remote object not found return TRUE; } switch ($status->getStatus()) { case ilECSEnrolmentStatus::STATUS_PENDING: // nothing todo in the moment: maybe send mail break; case ilECSEnrolmentStatus::STATUS_ACTIVE: $GLOBALS['ilLog']->write(__METHOD__ . ': Add desktop item: ' . $a_usr_id . ' ' . $ref_id . ' ' . $obj_id); ilObjUser::_addDesktopItem($a_usr_id, $ref_id, ilObject::_lookupType($obj_id)); break; case ilECSEnrolmentStatus::STATUS_ACCOUNT_DEACTIVATED: case ilECSEnrolmentStatus::STATUS_DENIED: case ilECSEnrolmentStatus::STATUS_REJECTED: case ilECSEnrolmentStatus::STATUS_UNSUBSCRIBED: $GLOBALS['ilLog']->write(__METHOD__ . ': Remove desktop item: ' . $a_usr_id . ' ' . $ref_id . ' ' . $obj_id); ilObjUser::_dropDesktopItem($a_usr_id, $ref_id, ilObject::_lookupType($obj_id)); break; } return TRUE; }