Public Member Functions | Protected Attributes | Private Member Functions

ilECSConnector Class Reference

Public Member Functions

 __construct ()
 Constructor.
 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.

Protected Attributes

 $path_postfix = ''
 $settings

Private Member Functions

 prepareConnection ()
 prepare connection
 call ()
 call peer

Detailed Description

Author:
Stefan Meyer <smeyer@databay.de>
Version:
$Id$

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


Constructor & Destructor Documentation

ilECSConnector::__construct (  ) 

Constructor.

public

Parameters:
 

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

References ilECSSettings::_getInstance().

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

Here is the call graph for this function:


Member Function Documentation

ilECSConnector::addResource ( a_post  ) 

Add resource.

public

Parameters:
string post data
Exceptions:
ECSConnectorException 

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

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

        {
                $this->path_postfix = '/econtents';
                
                try 
                {
                        $this->prepareConnection();
                        $this->curl->setOpt(CURLOPT_POST,true);
                        $this->curl->setOpt(CURLOPT_POSTFIELDS,$a_post);
                        $res = $this->call();
                        
                        return new ilECSResult($res);
                }
                catch(ilCurlConnectionException $exc)
                {
                        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 235 of file class.ilECSConnector.php.

References $res.

Referenced by addResource(), deleteResource(), getResources(), and updateResource().

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

Here is the caller graph for this function:

ilECSConnector::deleteResource ( a_econtent_id  ) 

Delete resource.

public

Parameters:
string econtent id
Exceptions:
ECSConnectorException 

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

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

        {
                $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->prepareConnection();
                        $this->curl->setOpt(CURLOPT_CUSTOMREQUEST,'DELETE');
                        $res = $this->call();
                        
                        return new ilECSResult($res);
                }
                catch(ilCurlConnectionException $exc)
                {
                        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:
int e-content id
Returns:
object ECSResult
Exceptions:
ECSConnectorException 

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

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

        {
                $this->path_postfix = '/econtents';
                if($a_econtent_id)
                {
                        $this->path_postfix .= ('/'.(int) $a_econtent_id);
                }
                
                try 
                {
                        $this->prepareConnection();
                        $res = $this->call();
                        
                        return new ilECSResult($res);
                }
                catch(ilCurlConnectionException $exc)
                {
                        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 203 of file class.ilECSConnector.php.

References ilECSSettings::PROTOCOL_HTTPS.

Referenced by addResource(), deleteResource(), 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,0);
                                $this->curl->setOpt(CURLOPT_SSL_VERIFYHOST,1);
                                $this->curl->setOpt(CURLOPT_VERBOSE,1);
                                $this->curl->setOpt(CURLOPT_RETURNTRANSFER,true);
                                $this->curl->setOpt(CURLE_SSL_PEER_CERTIFICATE,$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());
                                
                        }
                }
                catch(ilCurlConnectionException $exc)
                {
                        throw($exc);
                }
        }

Here is the caller graph for this function:

ilECSConnector::updateResource ( a_econtent_id,
a_post_string 
)

update resource

public

Parameters:
int econtent id
string post content
Exceptions:
ECSConnectorException 

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

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

        {
                $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->prepareConnection();
                        $this->curl->setOpt(CURLOPT_PUT,true);
                        
                        $fp = fopen('ecs_content.txt','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('ecs_content.txt'));
                        $fp = fopen('ecs_content.txt','r');
                        $this->curl->setOpt(CURLOPT_INFILE,$fp);
                        #fclose($fp);
                        
                        $res = $this->call();
                        
                        return new ilECSResult($res);
                }
                catch(ilCurlConnectionException $exc)
                {
                        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 40 of file class.ilECSConnector.php.

ilECSConnector::$settings [protected]

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


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