ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilECSConnector Class Reference
+ Collaboration diagram for ilECSConnector:

Public Member Functions

 __construct ()
 Constructor.
 addAuth ($a_post)
 Add auth resource.
 getAuth ($a_hash)
 get auth resource
 getEventQueues ()
 get event queue
 getResources ($a_econtent_id=0)
 Get resources from ECS server.
 addResource ($a_post)
 Add resource.
 updateResource ($a_econtent_id, $a_post_string)
 update resource
 deleteResource ($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

Protected Attributes

 $path_postfix = ''
 $settings

Private Member Functions

 prepareConnection ()
 prepare connection
 call ()
 call peer

Detailed Description

Author
Stefan Meyer smeye.nosp@m.r@da.nosp@m.tabay.nosp@m..de
Version
$Id$

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

Constructor & Destructor Documentation

ilECSConnector::__construct ( )

Constructor.

public

Parameters

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

References ilECSSettings\_getInstance().

{
$this->settings = ilECSSettings::_getInstance();
}

+ Here is the call graph for this function:

Member Function Documentation

ilECSConnector::addAuth (   $a_post)

Add auth resource.

public

Parameters
stringpost data
Returns
int new econtent id
Exceptions
ilECSConnectorException

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

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

{
global $ilLog;
$ilLog->write(__METHOD__.': Add new Auth resource...');
$this->path_postfix = '/auths';
try
{
$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 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)');
return true;
}
{
throw new ilECSConnectorException('Error calling ECS service: '.$exc->getMessage());
}
}

+ Here is the call graph for this function:

ilECSConnector::addResource (   $a_post)

Add resource.

public

Parameters
stringpost data
Returns
int new econtent id
Exceptions
ilECSConnectorException

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

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

{
global $ilLog;
$ilLog->write(__METHOD__.': Add new EContent...');
$this->path_postfix = '/econtents';
try
{
$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)');
$result = new ilECSResult($res,true);
$headers = $result->getHeaders();
include_once('./Services/WebServices/ECS/classes/class.ilECSUtils.php');
}
{
throw new ilECSConnectorException('Error calling ECS service: '.$exc->getMessage());
}
}

+ Here is the call graph for this function:

ilECSConnector::call ( )
private

call peer

private

Exceptions
ilCurlConnectionException

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

References $res.

Referenced by addAuth(), addResource(), deleteResource(), getAuth(), getEventQueues(), getMemberships(), getResources(), and updateResource().

{
try
{
$res = $this->curl->exec();
return $res;
}
{
throw($exc);
}
}

+ Here is the caller graph for this function:

ilECSConnector::deleteResource (   $a_econtent_id)

Delete resource.

public

Parameters
stringecontent id
Exceptions
ilECSConnectorException

Definition at line 347 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 = '/econtents';
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)

get auth resource

public

Parameters
authhash (transfered via GET)
Exceptions
ilECSConnectorException

Definition at line 114 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 = '/auths/'.$a_hash;
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)');
return new ilECSResult($res);
}
{
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

Definition at line 158 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 389 of file class.ilECSConnector.php.

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

{
global $ilLog;
$ilLog->write(__METHOD__.': Get existing memberships');
$this->path_postfix = '/memberships';
if($a_mid)
{
$ilLog->write(__METHOD__.': Read membership with id: '.$a_mid);
$this->path_postfix .= ('/'.(int) $a_mid);
}
try
{
$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::getResources (   $a_econtent_id = 0)

Get resources from ECS server.

public

Parameters
inte-content id
Returns
object ECSResult
Exceptions
ilECSConnectorException

Definition at line 202 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 = '/econtents';
if($a_econtent_id)
{
$this->path_postfix .= ('/'.(int) $a_econtent_id);
}
try
{
$this->curl->setOpt(CURLOPT_HEADER,false);
$res = $this->call();
$info = $this->curl->getInfo(CURLINFO_HTTP_CODE);
$result->setHTTPCode($info);
return $result;
}
{
throw new ilECSConnectorException('Error calling ECS service: '.$exc->getMessage());
}
}

+ Here is the call graph for this function:

ilECSConnector::prepareConnection ( )
private

prepare connection

private

Exceptions
ilCurlConnectionException

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

References ilCurlConnection\init(), and ilECSSettings\PROTOCOL_HTTPS.

Referenced by addAuth(), addResource(), deleteResource(), getAuth(), getEventQueues(), getMemberships(), getResources(), and updateResource().

{
try
{
$this->curl = new ilCurlConnection($this->settings->getServerURI().$this->path_postfix);
$this->curl->init();
if($this->settings->getProtocol() == ilECSSettings::PROTOCOL_HTTPS)
{
$this->curl->setOpt(CURLOPT_HTTPHEADER,array(0 => 'Accept: application/json'));
$this->curl->setOpt(CURLOPT_SSL_VERIFYPEER,1);
$this->curl->setOpt(CURLOPT_SSL_VERIFYHOST,1);
$this->curl->setOpt(CURLOPT_RETURNTRANSFER,1);
$this->curl->setOpt(CURLOPT_VERBOSE,1);
$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());
}
}
{
throw($exc);
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilECSConnector::updateResource (   $a_econtent_id,
  $a_post_string 
)

update resource

public

Parameters
intecontent id
stringpost content
Exceptions
ilECSConnectorException

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

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

{
global $ilLog;
$ilLog->write(__METHOD__.': Update resource with id '.$a_econtent_id);
$this->path_postfix = '/econtents';
if($a_econtent_id)
{
$this->path_postfix .= ('/'.(int) $a_econtent_id);
}
else
{
throw new ilECSConnectorException('Error calling updateResource: No content id given.');
}
try
{
$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_POSTFIELDS,$a_post_string);
$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();
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::$path_postfix = ''
protected

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

ilECSConnector::$settings
protected

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

const ilECSConnector::HTTP_CODE_CREATED = 201

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

const ilECSConnector::HTTP_CODE_NOT_FOUND = 404

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

Referenced by ilECSEContentReader\read().

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: