ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilECSContentWriter Class Reference

Handles request like update delete addEContent. More...

+ Collaboration diagram for ilECSContentWriter:

Public Member Functions

 __construct ($a_cont_obj, $a_server_id)
 Constructor.
 getServerId ()
 Get current server id.
 setExportable ($a_status)
 set exportable
 isExportable ()
 is exportable
 setOwnerId ($a_id)
 set owner mid
 getOwnerId ()
 get owner id
 setParticipantIds ($a_mids)
 set participant ids
 getParticipantIds ()
 get participant ids
 refresh ()
 Refresh (add- update- delete Econtent)
 refreshSettings ()
 Refresh Settings.
 deleteECSContent ()
 delete ecs content
 addECSContent ()
 Add ECSContent.
 updateECSContent ()
 update ECS content

Static Public Member Functions

static _handleDelete ($a_subbtree_nodes)
 handle delete Objects that are moved to the trash call ECS-Remove

Data Fields

const UPDATE_ALL = 1
const UPDATE_SETTINGS_ONLY = 2

Protected Attributes

 $log
 $content_obj = null
 $export_settings = null
 $server_id = 0
 $exportable = true
 $owner = 0
 $mids = null

Private Member Functions

 sendNewContentNotification ()
 send notifications about new EContent
 createJSON ()
 Create new JSON object.
 updateJSON ()
 update json object (read settings from content object)

Private Attributes

 $mode = 0

Detailed Description

Handles request like update delete addEContent.

Author
Stefan Meyer smeye.nosp@m.r.il.nosp@m.ias@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 36 of file class.ilECSContentWriter.php.

Constructor & Destructor Documentation

ilECSContentWriter::__construct (   $a_cont_obj,
  $a_server_id 
)

Constructor.

public

Parameters
objectcontent obj (e.g course_obj)

Definition at line 60 of file class.ilECSContentWriter.php.

References $ilLog, and getServerId().

{
global $ilLog;
$this->log = $ilLog;
$this->content_obj = $a_cont_obj;
$this->server_id = $a_server_id;
include_once('./Services/WebServices/ECS/classes/class.ilECSExport.php');
$this->export_settings = new ilECSExport($this->getServerId(),$this->content_obj->getId());
}

+ Here is the call graph for this function:

Member Function Documentation

static ilECSContentWriter::_handleDelete (   $a_subbtree_nodes)
static

handle delete Objects that are moved to the trash call ECS-Remove

public

Parameters
intobj_id
Returns
bool

Definition at line 82 of file class.ilECSContentWriter.php.

References $content_obj, ilECSExport\getExportedIds(), ilECSExport\getExportServerIds(), ilECSServerSettings\getInstance(), and ilObjectFactory\getInstanceByRefId().

Referenced by ilRepUtil\deleteObjects().

{
include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
if(!ilECSServerSettings::getInstance()->activeServerExists())
{
return false;
}
include_once('./Services/WebServices/ECS/classes/class.ilECSExport.php');
foreach($a_subbtree_nodes as $node)
{
if(in_array($node['obj_id'],$exported))
{
{
try
{
// Read export server ids
foreach(ilECSExport::getExportServerIds($node['obj_id']) as $sid)
{
$writer = new ilECSContentWriter($content_obj, $sid);
$writer->deleteECSContent();
}
}
{
continue;
}
}
}
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilECSContentWriter::addECSContent ( )

Add ECSContent.

public

Exceptions
ilConnectorException,ilECSContentWriterException

Definition at line 319 of file class.ilECSContentWriter.php.

References createJSON(), ilECSSetting\getInstanceByServerId(), getParticipantIds(), getServerId(), ilECSConnector\HEADER_MEMBERSHIPS, sendNewContentNotification(), and updateJSON().

Referenced by refresh().

{
include_once('./Services/WebServices/ECS/classes/class.ilECSConnector.php');
include_once('./Services/WebServices/ECS/classes/class.ilECSConnectorException.php');
try
{
$this->log->write(__METHOD__.': Starting course export...');
// construct new json object and set settings from content obj
$this->createJSON();
$this->updateJSON();
$connector->addHeader(ilECSConnector::HEADER_MEMBERSHIPS, implode(',',$this->getParticipantIds()));
#$connector->addHeader(ilECSConnector::HEADER_COMMUNITIES, )
$econtent_id = $connector->addResource(json_encode($this->json));
$this->export_settings->setExported(true);
$this->export_settings->setEContentId($econtent_id);
$this->export_settings->save();
// Send mail
}
{
throw $exc;
}
{
throw $exc;
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilECSContentWriter::createJSON ( )
private

Create new JSON object.

private

Definition at line 493 of file class.ilECSContentWriter.php.

Referenced by addECSContent().

{
include_once('./Services/WebServices/ECS/classes/class.ilECSEContent.php');
$this->json = new ilECSEContent();
return true;
}

+ Here is the caller graph for this function:

ilECSContentWriter::deleteECSContent ( )

delete ecs content

public

Exceptions
ilECSContentWriterException

Definition at line 287 of file class.ilECSContentWriter.php.

References ilECSSetting\getInstanceByServerId(), and getServerId().

Referenced by refresh().

{
include_once('./Services/WebServices/ECS/classes/class.ilECSConnector.php');
include_once('./Services/WebServices/ECS/classes/class.ilECSConnectorException.php');
try
{
$this->log->write(__METHOD__.': Start deleting ECS content...');
if(!$this->export_settings->getEContentId())
{
$this->log->write(__METHOD__.': Missing eid. Aborting.');
throw new ilECSContentWriterException('Missing ECS content ID. Aborting.');
}
$connector->deleteResource($this->export_settings->getEContentId());
$this->export_settings->setExported(false);
$this->export_settings->save();
}
{
throw $exc;
}
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilECSContentWriter::getOwnerId ( )

get owner id

public

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

References $owner.

Referenced by updateJSON().

{
return $this->owner;
}

+ Here is the caller graph for this function:

ilECSContentWriter::getParticipantIds ( )

get participant ids

public

Definition at line 192 of file class.ilECSContentWriter.php.

References $mids.

Referenced by addECSContent(), and updateECSContent().

{
return $this->mids;
}

+ Here is the caller graph for this function:

ilECSContentWriter::getServerId ( )

Get current server id.

Returns
int

Definition at line 122 of file class.ilECSContentWriter.php.

References $server_id.

Referenced by __construct(), addECSContent(), deleteECSContent(), sendNewContentNotification(), updateECSContent(), and updateJSON().

{
}

+ Here is the caller graph for this function:

ilECSContentWriter::isExportable ( )

is exportable

public

Parameters

Definition at line 146 of file class.ilECSContentWriter.php.

References $exportable.

Referenced by refresh().

{
}

+ Here is the caller graph for this function:

ilECSContentWriter::refresh ( )

Refresh (add- update- delete Econtent)

public

Exceptions
ilConnectorException,ilECSContentWriterException

Definition at line 203 of file class.ilECSContentWriter.php.

References addECSContent(), deleteECSContent(), isExportable(), UPDATE_ALL, and updateECSContent().

{
$this->mode = self::UPDATE_ALL;
try
{
if($this->export_settings->isExported())
{
if($this->isExportable())
{
// Update Econtent
return $this->updateECSContent();
}
else
{
// Delete EContent
return $this->deleteECSContent();
}
}
else
{
if($this->isExportable())
{
// Add Econtent
return $this->addECSContent();
}
else
{
// Nothing to do
}
}
return true;
}
{
$this->log->write(__METHOD__.': Error connecting to ECS server. '.$exc->getMessage());
throw $exc;
}
{
$this->log->write(__METHOD__.': Cannot update ECS content. '.$exc->getMessage());
throw $exc;
}
}

+ Here is the call graph for this function:

ilECSContentWriter::refreshSettings ( )

Refresh Settings.

public

Exceptions
il

Definition at line 253 of file class.ilECSContentWriter.php.

References UPDATE_SETTINGS_ONLY, and updateECSContent().

{
try
{
if($this->export_settings->isExported())
{
// Update Econtent
return $this->updateECSContent();
}
else
{
// Nothing to do
return true;
}
}
{
$this->log->write(__METHOD__.': Error connecting to ECS server. '.$exc->getMessage());
throw $exc;
}
{
$this->log->write(__METHOD__.': Cannot update ECS content. '.$exc->getMessage());
throw $exc;
}
}

+ Here is the call graph for this function:

ilECSContentWriter::sendNewContentNotification ( )
private

send notifications about new EContent

private

Returns
bool

Definition at line 405 of file class.ilECSContentWriter.php.

References $GLOBALS, $lang, $reader, ilMail\_getAutoGeneratedMessageString(), ilLanguageFactory\_getLanguage(), ilLink\_getStaticLink(), ilECSCommunityReader\getInstanceByServerId(), ilECSSetting\getInstanceByServerId(), and getServerId().

Referenced by addECSContent().

{
include_once('Services/WebServices/ECS/classes/class.ilECSSetting.php');
if(!count($rcps = $settings->getApprovalRecipients()))
{
return true;
}
include_once('./Services/Mail/classes/class.ilMail.php');
include_once('./Services/Language/classes/class.ilLanguageFactory.php');
$lang->loadLanguageModule('ecs');
// @TODO: read mail
$mail = new ilMail(6);
$message = $lang->txt('ecs_export_created_body_a')."\n\n";
$message .= $lang->txt('title').': '.$this->content_obj->getTitle()."\n";
if(strlen($desc = $this->content_obj->getDescription()))
{
$message .= $lang->txt('desc').': '.$desc."\n";
}
// Participant info
$message .= ("\n".$lang->txt('ecs_published_for'));
$export = new ilECSExport($this->getServerId(),$this->content_obj->getId());
try
{
include_once './Services/WebServices/ECS/classes/class.ilECSEContentReader.php';
$reader = new ilECSEContentReader($this->getServerId(),$export->getEContentId());
$reader->read(true);
$found = false;
if($reader->getEContentDetails() instanceof ilECSEContentDetails)
{
foreach($reader->getEContentDetails()->getReceivers() as $member)
{
$found = true;
include_once './Services/WebServices/ECS/classes/class.ilECSCommunityReader.php';
$part = ilECSCommunityReader::getInstanceByServerId($this->getServerId())->getParticipantByMID($member);
$message .= ("\n\n".$part->getParticipantName()."\n");
$message .= ($part->getDescription());
}
}
if($found)
{
$message .= "\n\n";
}
else
{
$message .= (' '.$lang->txt('ecs_not_published')."\n\n");
}
}
{
$GLOBALS['ilLog']->write(__METHOD__.': Cannot read approvements.');
return false;
}
{
$GLOBALS['ilLog']->write(__METHOD__.': Cannot read approvements.');
return false;
}
include_once('classes/class.ilLink.php');
$href = ilLink::_getStaticLink($this->content_obj->getRefId(),'crs',true);
$message .= $lang->txt("perma_link").': '.$href."\n\n";
$error = $mail->sendMail($settings->getApprovalRecipientsAsString(),
'','',
$lang->txt('ecs_new_approval_subject'),
$message,array(),array('normal'));
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilECSContentWriter::setExportable (   $a_status)

set exportable

public

Parameters
boolstatus

Definition at line 134 of file class.ilECSContentWriter.php.

{
$this->exportable = $a_status;
}
ilECSContentWriter::setOwnerId (   $a_id)

set owner mid

public

Parameters
intowner mid

Definition at line 158 of file class.ilECSContentWriter.php.

{
$this->owner = $a_id;
}
ilECSContentWriter::setParticipantIds (   $a_mids)

set participant ids

public

Parameters
arrayarray of participant mids

Definition at line 181 of file class.ilECSContentWriter.php.

{
$this->mids = $a_mids;
}
ilECSContentWriter::updateECSContent ( )

update ECS content

public

Exceptions
ilECSConnectorException,ilECSContentWriterException

Definition at line 361 of file class.ilECSContentWriter.php.

References $reader, ilECSSetting\getInstanceByServerId(), getParticipantIds(), getServerId(), ilECSConnector\HEADER_MEMBERSHIPS, and updateJSON().

Referenced by refresh(), and refreshSettings().

{
try
{
include_once('./Services/WebServices/ECS/classes/class.ilECSEContentReader.php');
$reader = new ilECSEContentReader($this->getServerId(),$this->export_settings->getEContentId());
$reader->read();
$reader->read(true);
$content = $reader->getEContent();
$details = $reader->getEContentDetails();
if(!$content instanceof ilECSEContent or !$details instanceof ilECSEContentDetails)
{
$this->log->write(__METHOD__.': Error reading EContent with id: '.$this->export_settings->getEContentId());
include_once('./Services/WebServices/ECS/classes/class.ilECSContentWriterException.php');
throw new ilECSContentWriterException('Error reading E-Content. Aborting');
}
$this->json = $content;
$this->updateJSON();
#$connector->addHeader(ilECSConnector::HEADER_MEMBERSHIPS, implode(',',$this->getParticipantIds()));
if($this->getParticipantIds() == null)
{
$connector->addHeader(ilECSConnector::HEADER_MEMBERSHIPS, implode(',',$details->getReceivers()));
}
else
{
$connector->addHeader(ilECSConnector::HEADER_MEMBERSHIPS, implode(',',$this->getParticipantIds()));
}
$connector->updateResource($this->export_settings->getEContentId(),json_encode($this->json));
}
{
throw $exc;
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilECSContentWriter::updateJSON ( )
private

update json object (read settings from content object)

private

Exceptions
ilECSContentWriterException

Definition at line 506 of file class.ilECSContentWriter.php.

References $GLOBALS, $reader, ilLink\_getLink(), ilAdvancedMDValues\_getValuesByObjId(), ilMDLanguage\_lookupFirstLanguage(), ilECSDataMappingSettings\getInstanceByServerId(), ilECSCommunityReader\getInstanceByServerId(), getOwnerId(), getServerId(), and ilECSDataMappingSetting\MAPPING_EXPORT.

Referenced by addECSContent(), and updateECSContent().

{
// General fields
######################################################
include_once('./classes/class.ilLink.php');
$this->json->setURL(ilLink::_getLink($this->content_obj->getRefId(),$this->content_obj->getType()));
$this->json->setTitle($this->content_obj->getTitle());
// Ownership EligibleMembers
######################################################
if($this->mode == self::UPDATE_ALL)
{
// Eligible members [0] is owner
if(!$this->getOwnerId())
{
throw new ilECSContentWriterException('Missing ECS owner id.');
}
}
// Add organisation
// todo: this must be cached in ecs_part_settings
if($this->mode == self::UPDATE_ALL)
{
try {
include_once './Services/WebServices/ECS/classes/class.ilECSCommunityReader.php';
$part = $reader->getParticipantByMID($this->getOwnerId());
$this->json->organisation = $part->getOrganisation()->getName();
}
catch(Exception $e)
{
$GLOBALS['ilLog']->write(__METHOD__.': '.$e->getMessage());
}
}
// meta language
include_once('./Services/MetaData/classes/class.ilMDLanguage.php');
$this->json->setLanguage(ilMDLanguage::_lookupFirstLanguage($this->content_obj->getId(),$this->content_obj->getId(),$this->content_obj->getType()));
$this->json->setStatus($this->content_obj->isActivated() ? 'online' : 'offline');
$this->json->setInfo($this->content_obj->getDescription());
// Optional fields
######################################################
include_once('./Services/WebServices/ECS/classes/class.ilECSUtils.php');
include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
$values = ilAdvancedMDValues::_getValuesByObjId($this->content_obj->getId());
// Study courses
if($field = $mappings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_EXPORT, 'study_courses'))
{
$value = isset($values[$field]) ? $values[$field] : '';
$this->json->setStudyCourses($value);
}
// Lecturer
if($field = $mappings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_EXPORT, 'lecturer'))
{
$value = isset($values[$field]) ? $values[$field] : '';
$this->json->setLecturers($value);
}
// CourseType
if($field = $mappings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_EXPORT, 'courseType'))
{
$value = isset($values[$field]) ? $values[$field] : '';
$this->json->setCourseType($value);
}
// Course ID
if($field = $mappings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_EXPORT,'courseID'))
{
$value = isset($values[$field]) ? $values[$field] : '';
$this->json->setCourseID($value);
}
// Credits
if($field = $mappings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_EXPORT,'credits'))
{
$value = isset($values[$field]) ? $values[$field] : '';
$this->json->setCredits($value);
}
// SWS
if($field = $mappings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_EXPORT,'semester_hours'))
{
$value = isset($values[$field]) ? $values[$field] : '';
$this->json->setSemesterHours($value);
}
// Term
if($field = $mappings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_EXPORT,'term'))
{
$value = isset($values[$field]) ? $values[$field] : '';
$this->json->setTerm($value);
}
// TIME PLACE OBJECT ########################
if($field = $mappings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_EXPORT,'begin'))
{
$value = isset($values[$field]) ? $values[$field] : '';
$this->json->getTimePlace()->setBegin($value);
}
if($field = $mappings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_EXPORT,'end'))
{
$value = isset($values[$field]) ? $values[$field] : '';
$this->json->getTimePlace()->setEnd($value);
}
if($field = $mappings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_EXPORT,'room'))
{
$value = isset($values[$field]) ? $values[$field] : '';
$this->json->getTimePlace()->setRoom($value);
}
if($field = $mappings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_EXPORT,'cycle'))
{
$value = isset($values[$field]) ? $values[$field] : '';
$this->json->getTimePlace()->setCycle($value);
}
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

ilECSContentWriter::$content_obj = null
protected

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

Referenced by _handleDelete().

ilECSContentWriter::$export_settings = null
protected

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

ilECSContentWriter::$exportable = true
protected

Definition at line 49 of file class.ilECSContentWriter.php.

Referenced by isExportable().

ilECSContentWriter::$log
protected

Definition at line 43 of file class.ilECSContentWriter.php.

ilECSContentWriter::$mids = null
protected

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

Referenced by getParticipantIds().

ilECSContentWriter::$mode = 0
private

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

ilECSContentWriter::$owner = 0
protected

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

Referenced by getOwnerId().

ilECSContentWriter::$server_id = 0
protected

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

Referenced by getServerId().

const ilECSContentWriter::UPDATE_ALL = 1

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

Referenced by refresh().

const ilECSContentWriter::UPDATE_SETTINGS_ONLY = 2

Definition at line 39 of file class.ilECSContentWriter.php.

Referenced by refreshSettings().


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