/** * Get single directory tree * @return array an array of ecs cms directory tree entries */ public function getCourse($course_id, $a_details = false) { $this->path_postfix = '/campusconnect/courses/' . (int) $course_id; if ($a_details and $course_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(); $details->loadFromJson($ecs_result->getResult()); return $details; } // Return json result return $ecs_result->getResult(); } catch (ilCurlConnectionException $e) { throw new ilECSConnectorException('Error calling ECS service: ' . $e->getMessage()); } }
/** * Get directory tree * @global ilLog $ilLog * @return ilECSResult * @throws ilECSConnectorException */ public function getDirectoryTrees($a_mid = 0) { global $ilLog; $this->path_postfix = '/campusconnect/directory_trees'; try { $this->prepareConnection(); $this->setHeader(array()); $this->addHeader('Accept', 'text/uri-list'); $this->addHeader('X-EcsQueryStrings', 'all=true'); if ($a_mid) { $this->addHeader('X-EcsReceiverMemberships', $a_mid); } $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader()); $res = $this->call(); $ecsResult = new ilECSResult($res, false, ilECSResult::RESULT_TYPE_URL_LIST); return $ecsResult->getResult(); } catch (ilCurlConnectionException $exc) { throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage()); } }
/** * Get single directory tree * @return array an array of ecs cms directory tree entries */ public function getCourse($course_id, $a_details = false) { $this->path_postfix = '/campusconnect/courses/' . (int) $course_id; if ($a_details and $course_id) { $this->path_postfix .= '/details'; } try { $this->prepareConnection(); $this->setHeader(array()); $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 $ecs_result->getResult(); } catch (ilCurlConnectionException $e) { throw new ilECSConnectorException('Error calling ECS service: ' . $e->getMessage()); } }
/** * get auth resource * * @access public * @param auth hash (transfered via GET) * @throws ilECSConnectorException */ public function getAuth($a_hash, $a_details_only = FALSE) { global $ilLog; if (!strlen($a_hash)) { $ilLog->write(__METHOD__ . ': No auth hash given. Aborting.'); throw new ilECSConnectorException('No auth hash given.'); } $this->path_postfix = '/sys/auths/' . $a_hash; if ($a_details_only) { $this->path_postfix .= '/details'; } try { $this->prepareConnection(); $res = $this->call(); $info = $this->curl->getInfo(CURLINFO_HTTP_CODE); $ilLog->write(__METHOD__ . ': Checking HTTP status...'); if ($info != self::HTTP_CODE_OK) { $ilLog->write(__METHOD__ . ': Cannot get auth resource, did not receive HTTP 200. '); throw new ilECSConnectorException('Received HTTP status code: ' . $info); } $ilLog->write(__METHOD__ . ': ... got HTTP 200 (ok)'); $ecs_result = new ilECSResult($res); // Return ECSEContentDetails for details switch if ($a_details_only) { include_once './Services/WebServices/ECS/classes/class.ilECSEContentDetails.php'; $details = new ilECSEContentDetails(); $details->loadFromJson($ecs_result->getResult()); return $details; } return $ecs_result; } catch (ilCurlConnectionException $exc) { throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage()); } }
/** * Add auth resource * * @access public * @param string post data * @return int new econtent id * @throws ilECSConnectorException * */ public function addAuth($a_post, $a_target_mid) { global $ilLog; $ilLog->write(__METHOD__ . ': Add new Auth resource...'); $this->path_postfix = '/sys/auths'; try { $this->prepareConnection(); $this->addHeader('Content-Type', 'application/json'); $this->addHeader('Accept', 'application/json'); $this->addHeader(ilECSConnector::HEADER_MEMBERSHIPS, $a_target_mid); #$this->addHeader(ilECSConnector::HEADER_MEMBERSHIPS, 1); $this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader()); $this->curl->setOpt(CURLOPT_POST, true); $this->curl->setOpt(CURLOPT_POSTFIELDS, $a_post); $ret = $this->call(); $info = $this->curl->getInfo(CURLINFO_HTTP_CODE); $ilLog->write(__METHOD__ . ': Checking HTTP status...'); if ($info != self::HTTP_CODE_CREATED) { $ilLog->write(__METHOD__ . ': Cannot create auth resource, did not receive HTTP 201. '); $ilLog->write(__METHOD__ . ': POST was: ' . $a_post); $ilLog->write(__METHOD__ . ': HTTP code: ' . $info); throw new ilECSConnectorException('Received HTTP status code: ' . $info); } $ilLog->write(__METHOD__ . ': ... got HTTP 201 (created)'); $result = new ilECSResult($ret); $auth = $result->getResult(); $ilLog->write(__METHOD__ . ': ... got hash: ' . $auth->hash); return $auth->hash; } catch (ilCurlConnectionException $exc) { throw new ilECSConnectorException('Error calling ECS service: ' . $exc->getMessage()); } }