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

Public Member Functions

 __construct (ilECSSetting $settings=null)
 Constructor.
 addHeader ($a_name, $a_value)
 Add Header.
 getHeader ()
 getServer ()
 Get current server setting.
 addAuth ($a_post, $a_target_mid)
 Add auth resource.
 getAuth ($a_hash)
 get auth resource
 getEventQueues ()
 get event queue
 readEventFifo ($a_delete=false)
 Read event fifo.
 getResourceList ()
 getResource ($a_econtent_id, $a_details_only=false)
 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
const HEADER_MEMBERSHIPS = 'X-EcsReceiverMemberships'
const HEADER_COMMUNITIES = 'X-EcsReceiverCommunities'

Protected Attributes

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

Private Member Functions

 prepareConnection ()
 prepare connection
 call ()
 call peer

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

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

ilECSConnector::addAuth (   $a_post,
  $a_target_mid 
)

Add auth resource.

public

Parameters
stringpost data
Returns
int new econtent id
Exceptions
ilECSConnectorException

Definition at line 113 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)');
$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 
)

Add Header.

Parameters
string$a_name
string$a_value

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

Referenced by addAuth(), addResource(), readEventFifo(), and updateResource().

{
$this->header_strings[] = ($a_name.': '.$a_value);
}

+ Here is the caller graph for this function:

ilECSConnector::addResource (   $a_post)

Add resource.

public

Parameters
stringpost data
Returns
int new econtent id
Exceptions
ilECSConnectorException

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

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

{
global $ilLog;
$ilLog->write(__METHOD__.': Add new EContent...');
$this->path_postfix = '/campusconnect/courselinks';
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)');
include_once('./Services/WebServices/ECS/classes/class.ilECSUtils.php');
$eid = ilECSUtils::_fetchEContentIdFromHeader($this->curl->getResponseHeaderArray());
return $eid;
}
{
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 615 of file class.ilECSConnector.php.

References $res.

Referenced by addAuth(), addResource(), deleteResource(), getAuth(), getEventQueues(), getMemberships(), getResource(), getResourceList(), readEventFifo(), 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 490 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 = '/campusconnect/courselinks';
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 167 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;
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
Deprecated:

Definition at line 211 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::getHeader ( )

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

References $header_strings.

Referenced by addAuth(), addResource(), getResourceList(), and updateResource().

{
return (array) $this->header_strings;
}

+ Here is the caller graph for this function:

ilECSConnector::getMemberships (   $a_mid = 0)

public

Parameters
intmembership id
Exceptions
ilECSConnectorException

Definition at line 532 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();
// 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_econtent_id,
  $a_details_only = false 
)

Get resources from ECS server.

public

Parameters
inte-content id
Returns
object ECSResult
Exceptions
ilECSConnectorException

Definition at line 329 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 = '/campusconnect/courselinks';
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 ( )

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

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

{
global $ilLog;
$this->path_postfix = '/campusconnect/courselinks';
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 94 of file class.ilECSConnector.php.

References $settings.

Referenced by prepareConnection().

{
}

+ Here is the caller graph for this function:

ilECSConnector::prepareConnection ( )
private

prepare connection

private

Exceptions
ilCurlConnectionException

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

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

Referenced by addAuth(), addResource(), deleteResource(), getAuth(), 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);
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);
$this->curl->setOpt(CURLOPT_SSL_VERIFYHOST,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());
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 248 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)');
return $result;
}
{
throw new ilECSConnectorException('Error calling ECS service: '.$exc->getMessage());
}
}

+ Here is the call 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 436 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 = '/campusconnect/courselinks';
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();
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.

ilECSConnector::$settings
protected

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

Referenced by __construct(), and getServer().

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

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: