ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilECSConnector Class Reference
+ Inheritance diagram for ilECSConnector:
+ Collaboration diagram for ilECSConnector:

Public Member Functions

 __construct (ilECSSetting $settings=null)
 Constructor.
 addHeader ($a_name, $a_value)
 Add Header.
 getHeader ()
 setHeader ($a_header_strings)
 getServer ()
 Get current server setting.
 addAuth ($a_post, $a_target_mid)
 Add auth resource.
 getAuth ($a_hash, $a_details_only=FALSE)
 get auth resource
 getEventQueues ()
 get event queue
 readEventFifo ($a_delete=false)
 Read event fifo.
 getResourceList ($a_path)
 getResource ($a_path, $a_econtent_id, $a_details_only=false)
 Get resources from ECS server.
 addResource ($a_path, $a_post)
 Add resource.
 updateResource ($a_path, $a_econtent_id, $a_post_string)
 update resource
 deleteResource ($a_path, $a_econtent_id)
 Delete resource.
 getMemberships ($a_mid=0)
 public

Data Fields

const HTTP_CODE_CREATED = 201
const HTTP_CODE_OK = 200
const HTTP_CODE_NOT_FOUND = 404
const HEADER_MEMBERSHIPS = 'X-EcsReceiverMemberships'
const HEADER_COMMUNITIES = 'X-EcsReceiverCommunities'

Protected Member Functions

 prepareConnection ()
 prepare connection
 call ()
 call peer

Static Protected Member Functions

static _fetchEContentIdFromHeader ($a_header)
 fetch new econtent id from location header

Protected Attributes

 $path_postfix = ''
 $settings
 $header_strings = array()

Detailed Description

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

Definition at line 38 of file class.ilECSConnector.php.

Constructor & Destructor Documentation

ilECSConnector::__construct ( ilECSSetting  $settings = null)

Constructor.

public

Parameters

Reimplemented in ilECSEnrolmentStatusConnector, ilECSCourseConnector, ilECSCourseMemberConnector, ilECSDirectoryTreeConnector, and ilECSCourseUrlConnector.

Definition at line 61 of file class.ilECSConnector.php.

References $GLOBALS, and $settings.

{
if($settings)
{
$this->settings = $settings;
}
else
{
$GLOBALS['ilLog']->write(__METHOD__.': Using deprecated call');
$GLOBALS['ilLog']->logStack();
}
}

Member Function Documentation

static ilECSConnector::_fetchEContentIdFromHeader (   $a_header)
staticprotected

fetch new econtent id from location header

public

Parameters
arrayheader array

Definition at line 673 of file class.ilECSConnector.php.

References $ilLog.

Referenced by addResource().

{
global $ilLog;
if(!isset($a_header['Location']))
{
return false;
}
$end_path = strrpos($a_header['Location'],"/");
if($end_path === false)
{
$ilLog->write(__METHOD__.': Cannot find path seperator.');
return false;
}
$econtent_id = substr($a_header['Location'],$end_path + 1);
$ilLog->write(__METHOD__.': Received EContentId '.$econtent_id);
return (int) $econtent_id;
}

+ Here is the caller graph for this function:

ilECSConnector::addAuth (   $a_post,
  $a_target_mid 
)

Add auth resource.

public

Parameters
stringpost data
Returns
int new econtent id
Exceptions
ilECSConnectorException

Definition at line 118 of file class.ilECSConnector.php.

References $auth, $ilLog, $result, $ret, addHeader(), call(), getHeader(), HEADER_MEMBERSHIPS, and prepareConnection().

{
global $ilLog;
$ilLog->write(__METHOD__.': Add new Auth resource...');
$this->path_postfix = '/sys/auths';
try
{
$this->addHeader('Content-Type', 'application/json');
$this->addHeader('Accept', 'application/json');
#$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)');
$ilLog->write(__METHOD__.': POST was: '.$a_post);
$auth = $result->getResult();
$ilLog->write(__METHOD__.': ... got hash: '.$auth->hash);
return $auth->hash;
}
{
throw new ilECSConnectorException('Error calling ECS service: '.$exc->getMessage());
}
}

+ Here is the call graph for this function:

ilECSConnector::addHeader (   $a_name,
  $a_value 
)
ilECSConnector::addResource (   $a_path,
  $a_post 
)

Add resource.

public

Parameters
stringresource "path"
stringpost data
Returns
int new econtent id
Exceptions
ilECSConnectorException

Definition at line 415 of file class.ilECSConnector.php.

References $ilLog, $res, _fetchEContentIdFromHeader(), addHeader(), call(), getHeader(), and prepareConnection().

{
global $ilLog;
$ilLog->write(__METHOD__.': Add new EContent...');
$this->path_postfix = $a_path;
try
{
$this->addHeader('Content-Type', 'application/json');
$this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader());
$this->curl->setOpt(CURLOPT_HEADER,true);
$this->curl->setOpt(CURLOPT_POST,true);
$this->curl->setOpt(CURLOPT_POSTFIELDS,$a_post);
$res = $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 econtent, did not receive HTTP 201. ');
throw new ilECSConnectorException('Received HTTP status code: '.$info);
}
$ilLog->write(__METHOD__.': ... got HTTP 201 (created)');
$eid = self::_fetchEContentIdFromHeader($this->curl->getResponseHeaderArray());
return $eid;
}
{
throw new ilECSConnectorException('Error calling ECS service: '.$exc->getMessage());
}
}

+ Here is the call graph for this function:

ilECSConnector::deleteResource (   $a_path,
  $a_econtent_id 
)

Delete resource.

public

Parameters
stringresource "path"
stringecontent id
Exceptions
ilECSConnectorException

Definition at line 521 of file class.ilECSConnector.php.

References $ilLog, $res, call(), and prepareConnection().

{
global $ilLog;
$ilLog->write(__METHOD__.': Delete resource with id '.$a_econtent_id);
$this->path_postfix = $a_path;
if($a_econtent_id)
{
$this->path_postfix .= ('/'.(int) $a_econtent_id);
}
else
{
throw new ilECSConnectorException('Error calling deleteResource: No content id given.');
}
try
{
$this->curl->setOpt(CURLOPT_CUSTOMREQUEST,'DELETE');
$res = $this->call();
return new ilECSResult($res);
}
{
throw new ilECSConnectorException('Error calling ECS service: '.$exc->getMessage());
}
}

+ Here is the call graph for this function:

ilECSConnector::getAuth (   $a_hash,
  $a_details_only = FALSE 
)

get auth resource

public

Parameters
authhash (transfered via GET)
Exceptions
ilECSConnectorException

Definition at line 173 of file class.ilECSConnector.php.

References $ilLog, $res, call(), and prepareConnection().

{
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
{
$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;
}
{
throw new ilECSConnectorException('Error calling ECS service: '.$exc->getMessage());
}
}

+ Here is the call graph for this function:

ilECSConnector::getEventQueues ( )

get event queue

public

Exceptions
ilECSConnectorException
Deprecated:

Definition at line 233 of file class.ilECSConnector.php.

References $ilLog, $res, call(), and prepareConnection().

{
global $ilLog;
$this->path_postfix = '/eventqueues';
try
{
$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 event queue, did not receive HTTP 200. ');
throw new ilECSConnectorException('Received HTTP status code: '.$info);
}
$ilLog->write(__METHOD__.': ... got HTTP 200 (ok)');
return new ilECSResult($res);
}
{
throw new ilECSConnectorException('Error calling ECS service: '.$exc->getMessage());
}
}

+ Here is the call graph for this function:

ilECSConnector::getMemberships (   $a_mid = 0)

public

Parameters
intmembership id
Exceptions
ilECSConnectorException

Definition at line 563 of file class.ilECSConnector.php.

References $ilLog, $res, call(), and prepareConnection().

{
global $ilLog;
$ilLog->write(__METHOD__.': Get existing memberships');
$this->path_postfix = '/sys/memberships';
if($a_mid)
{
$ilLog->write(__METHOD__.': Read membership with id: '.$a_mid);
$this->path_postfix .= ('/'.(int) $a_mid);
}
try
{
$res = $this->call();
$this->curl->setOpt(CURLOPT_HTTPHEADER,array(0 => 'X-EcsQueryStrings: sender=true'));
// Checking status code
$info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
if($info != self::HTTP_CODE_OK)
{
$ilLog->write(__METHOD__.': Cannot get memberships, did not receive HTTP 200. ');
throw new ilECSConnectorException('Received HTTP status code: '.$info);
}
return new ilECSResult($res);
}
{
throw new ilECSConnectorException('Error calling ECS service: '.$exc->getMessage());
}
}

+ Here is the call graph for this function:

ilECSConnector::getResource (   $a_path,
  $a_econtent_id,
  $a_details_only = false 
)

Get resources from ECS server.

public

Parameters
stringresource "path"
inte-content id
Returns
object ECSResult
Exceptions
ilECSConnectorException

Definition at line 355 of file class.ilECSConnector.php.

References $ilLog, $res, $result, call(), and prepareConnection().

{
global $ilLog;
if($a_econtent_id)
{
$ilLog->write(__METHOD__.': Get resource with ID: '.$a_econtent_id);
}
else
{
$ilLog->write(__METHOD__.': Get all resources ...');
}
$this->path_postfix = $a_path;
if($a_econtent_id)
{
$this->path_postfix .= ('/'.(int) $a_econtent_id);
}
if($a_details_only)
{
$this->path_postfix .= ('/details');
}
try
{
$res = $this->call();
// Checking status code
$info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
$ilLog->write(__METHOD__.': Checking HTTP status...');
if($info != self::HTTP_CODE_OK)
{
$ilLog->write(__METHOD__.': Cannot get ressource, did not receive HTTP 200. ');
throw new ilECSConnectorException('Received HTTP status code: '.$info);
}
$ilLog->write(__METHOD__.': ... got HTTP 200 (ok)');
$result->setHeaders($this->curl->getResponseHeaderArray());
$result->setHTTPCode($info);
return $result;
}
{
throw new ilECSConnectorException('Error calling ECS service: '.$exc->getMessage());
}
}

+ Here is the call graph for this function:

ilECSConnector::getResourceList (   $a_path)

Definition at line 314 of file class.ilECSConnector.php.

References $ilLog, $res, call(), getHeader(), prepareConnection(), and ilECSResult\RESULT_TYPE_URL_LIST.

{
global $ilLog;
$this->path_postfix = $a_path;
try {
$this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader());
$res = $this->call();
// Checking status code
$info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
$ilLog->write(__METHOD__.': Checking HTTP status...');
if($info != self::HTTP_CODE_OK)
{
$ilLog->write(__METHOD__.': Cannot get ressource list, did not receive HTTP 200. ');
throw new ilECSConnectorException('Received HTTP status code: '.$info);
}
$ilLog->write(__METHOD__.': ... got HTTP 200 (ok)');
}
throw new ilECSConnectorException('Error calling ECS service: '.$exc->getMessage());
}
}

+ Here is the call graph for this function:

ilECSConnector::getServer ( )

Get current server setting.

Returns
ilECSSetting

Definition at line 99 of file class.ilECSConnector.php.

References $settings.

Referenced by prepareConnection().

{
}

+ Here is the caller graph for this function:

ilECSConnector::prepareConnection ( )
protected

prepare connection

private

Exceptions
ilCurlConnectionException

Definition at line 604 of file class.ilECSConnector.php.

References ilECSSetting\AUTH_APACHE, ilECSSetting\AUTH_CERTIFICATE, getServer(), and ilCurlConnection\init().

Referenced by addAuth(), ilECSEnrolmentStatusConnector\addEnrolmentStatus(), addResource(), ilECSCourseUrlConnector\addUrl(), deleteResource(), getAuth(), ilECSCourseConnector\getCourse(), ilECSCourseMemberConnector\getCourseMember(), ilECSDirectoryTreeConnector\getDirectoryTree(), ilECSDirectoryTreeConnector\getDirectoryTrees(), ilECSEnrolmentStatusConnector\getEnrolmentStatus(), getEventQueues(), getMemberships(), getResource(), getResourceList(), readEventFifo(), and updateResource().

{
try
{
$this->curl = new ilCurlConnection($this->settings->getServerURI().$this->path_postfix);
$this->curl->init();
$this->curl->setOpt(CURLOPT_HTTPHEADER,array(0 => 'Accept: application/json'));
$this->curl->setOpt(CURLOPT_RETURNTRANSFER,1);
$this->curl->setOpt(CURLOPT_VERBOSE,1);
$this->curl->setOpt(CURLOPT_TIMEOUT_MS,2000);
switch($this->getServer()->getAuthType())
{
$this->curl->setOpt(CURLOPT_SSL_VERIFYPEER,0);
#$this->curl->setOpt(CURLOPT_SSL_VERIFYHOST,0);
$this->curl->setOpt(CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$this->curl->setOpt(CURLOPT_USERPWD,
$this->getServer()->getAuthUser().':'.$this->getServer()->getAuthPass()
);
break;
$this->curl->setOpt(CURLOPT_SSL_VERIFYPEER,1);
// use default 2 for libcurl 7.28.1 support
$this->curl->setOpt(CURLOPT_SSL_VERIFYHOST,2);
$this->curl->setOpt(CURLOPT_CAINFO,$this->settings->getCACertPath());
$this->curl->setOpt(CURLOPT_SSLCERT,$this->settings->getClientCertPath());
$this->curl->setOpt(CURLOPT_SSLKEY,$this->settings->getKeyPath());
$this->curl->setOpt(CURLOPT_SSLKEYPASSWD,$this->settings->getKeyPassword());
break;
}
}
{
throw($exc);
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilECSConnector::readEventFifo (   $a_delete = false)

Read event fifo.

Parameters
boolset to true for deleting the current element
Exceptions
ilECSConnectorException

Definition at line 270 of file class.ilECSConnector.php.

References $ilLog, $res, $result, addHeader(), call(), and prepareConnection().

{
global $ilLog;
$this->path_postfix = '/sys/events/fifo';
try {
$this->addHeader('Content-Type', 'application/json');
$this->addHeader('Accept', 'application/json');
if($a_delete)
{
$this->curl->setOpt(CURLOPT_POST,true);
$this->curl->setOpt(CURLOPT_POSTFIELDS, '');
}
$res = $this->call();
// Checking status code
$info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
#$ilLog->write(__METHOD__.': Checking HTTP status...');
if($info != self::HTTP_CODE_OK)
{
$ilLog->write(__METHOD__.': Cannot read event fifo, did not receive HTTP 200. ');
throw new ilECSConnectorException('Received HTTP status code: '.$info);
}
#$ilLog->write(__METHOD__.': ... got HTTP 200 (ok)');
#$GLOBALS['ilLog']->write(__METHOD__.':------------------------------------- FIFO content'. print_r($result,true));
return $result;
}
{
throw new ilECSConnectorException('Error calling ECS service: '.$exc->getMessage());
}
}

+ Here is the call graph for this function:

ilECSConnector::setHeader (   $a_header_strings)
ilECSConnector::updateResource (   $a_path,
  $a_econtent_id,
  $a_post_string 
)

update resource

public

Parameters
stringresource "path"
intecontent id
stringpost content
Exceptions
ilECSConnectorException

Definition at line 463 of file class.ilECSConnector.php.

References $ilLog, $res, addHeader(), call(), getHeader(), ilUtil\ilTempnam(), and prepareConnection().

{
global $ilLog;
$ilLog->write(__METHOD__.': Update resource with id '.$a_econtent_id);
$this->path_postfix = $a_path;
if($a_econtent_id)
{
$this->path_postfix .= ('/'.(int) $a_econtent_id);
}
else
{
throw new ilECSConnectorException('Error calling updateResource: No content id given.');
}
try
{
$this->addHeader('Content-Type', 'application/json');
$this->addHeader('Accept', 'application/json');
$this->curl->setOpt(CURLOPT_HTTPHEADER, $this->getHeader());
$this->curl->setOpt(CURLOPT_HEADER,true);
$this->curl->setOpt(CURLOPT_PUT,true);
$tempfile = ilUtil::ilTempnam();
$ilLog->write(__METHOD__.': Created new tempfile: '.$tempfile);
$fp = fopen($tempfile,'w');
fwrite($fp,$a_post_string);
fclose($fp);
$this->curl->setOpt(CURLOPT_UPLOAD,true);
$this->curl->setOpt(CURLOPT_INFILESIZE,filesize($tempfile));
$fp = fopen($tempfile,'r');
$this->curl->setOpt(CURLOPT_INFILE,$fp);
$res = $this->call();
fclose($fp);
unlink($tempfile);
return new ilECSResult($res);
}
{
throw new ilECSConnectorException('Error calling ECS service: '.$exc->getMessage());
}
}

+ Here is the call graph for this function:

Field Documentation

ilECSConnector::$header_strings = array()
protected

Definition at line 52 of file class.ilECSConnector.php.

Referenced by getHeader().

ilECSConnector::$path_postfix = ''
protected

Definition at line 48 of file class.ilECSConnector.php.

const ilECSConnector::HEADER_COMMUNITIES = 'X-EcsReceiverCommunities'

Definition at line 45 of file class.ilECSConnector.php.

const ilECSConnector::HEADER_MEMBERSHIPS = 'X-EcsReceiverMemberships'
const ilECSConnector::HTTP_CODE_CREATED = 201

Definition at line 40 of file class.ilECSConnector.php.

const ilECSConnector::HTTP_CODE_NOT_FOUND = 404
const ilECSConnector::HTTP_CODE_OK = 200

Definition at line 41 of file class.ilECSConnector.php.


The documentation for this class was generated from the following file: