ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilECSObjectSettings.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
13 abstract class ilECSObjectSettings
14 {
18  protected $content_obj; // [ilObj]
19 
23  private $logger = null;
24 
25  const MAIL_SENDER = 6;
26 
32  public function __construct(ilObject $a_content_object)
33  {
34  $this->logger = $GLOBALS['DIC']->logger()->obj();
35  $this->content_obj = $a_content_object;
36  }
37 
44  public static function getInstanceByObject(ilObject $a_content_obj)
45  {
46  switch ($a_content_obj->getType()) {
47  case 'crs':
48  include_once 'Modules/Course/classes/class.ilECSCourseSettings.php';
49  return new ilECSCourseSettings($a_content_obj);
50 
51  case 'cat':
52  include_once 'Modules/Category/classes/class.ilECSCategorySettings.php';
53  return new ilECSCategorySettings($a_content_obj);
54 
55  case 'file':
56  include_once 'Modules/File/classes/class.ilECSFileSettings.php';
57  return new ilECSFileSettings($a_content_obj);
58 
59  case 'glo':
60  include_once 'Modules/Glossary/classes/class.ilECSGlossarySettings.php';
61  return new ilECSGlossarySettings($a_content_obj);
62 
63  case 'grp':
64  include_once 'Modules/Group/classes/class.ilECSGroupSettings.php';
65  return new ilECSGroupSettings($a_content_obj);
66 
67  case 'lm':
68  include_once 'Modules/LearningModule/classes/class.ilECSLearningModuleSettings.php';
69  return new ilECSLearningModuleSettings($a_content_obj);
70 
71  case 'wiki':
72  include_once 'Modules/Wiki/classes/class.ilECSWikiSettings.php';
73  return new ilECSWikiSettings($a_content_obj);
74  }
75  }
76 
81  public function getContentObject()
82  {
83  return $this->content_obj;
84  }
85 
91  abstract protected function getECSObjectType();
92 
98  protected function isActive()
99  {
100  include_once('./Services/WebServices/ECS/classes/class.ilECSServerSettings.php');
101  if (ilECSServerSettings::getInstance()->activeServerExists()) {
102  // imported objects cannot be exported => why not
103  #include_once('./Services/WebServices/ECS/classes/class.ilECSImport.php');
104  #if(!ilECSImport::lookupServerId($this->content_obj->getId()))
105  {
106  return true;
107  }
108  }
109 
110  return false;
111  }
112 
120  public function addSettingsToForm(ilPropertyFormGUI $a_form, $a_type)
121  {
122  global $DIC;
123 
124  $lng = $DIC['lng'];
125 
126  $this->logger->debug('Show ecs settings.');
127  if (!$this->isActive($a_type)) {
128  $this->logger->debug('Object type is not active. => no settings.');
129  return;
130  }
131 
132  $obj_id = $this->content_obj->getId();
133 
134  // Return if no participant is enabled for export and the current object is not released
135  include_once './Services/WebServices/ECS/classes/class.ilECSExport.php';
136  include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSettings.php';
137 
138  if (!$this->getContentObject()->withReferences()) {
139  $this->logger->debug('Called withot references. => no settings.');
140  return true;
141  }
142 
144  if (!$exportablePart and !ilECSExport::_isExported($obj_id)) {
145  $this->logger->debug('Object type is not exportable. => no settings.');
146  return true;
147  }
148  if (
149  $GLOBALS['DIC']['tree']->checkForParentType($GLOBALS['DIC']['tree']->getParentId($this->getContentObject()->getRefId()), 'crs', false) or
150  $GLOBALS['DIC']['tree']->checkForParentType($GLOBALS['DIC']['tree']->getParentId($this->getContentObject()->getRefId()), 'grp', false)
151  ) {
152  $this->logger->debug('Parent crs/grp in path. => no settings.');
153  return true;
154  }
155 
156  $lng->loadLanguageModule('ecs');
157 
158  // show ecs property form section
159  $ecs = new ilFormSectionHeaderGUI();
160  $ecs->setTitle($lng->txt('ecs_' . $a_type . '_export'));
161  $a_form->addItem($ecs);
162 
163 
164  // release or not
165  $exp = new ilRadioGroupInputGUI($lng->txt('ecs_' . $a_type . '_export_obj_settings'), 'ecs_export');
166  $exp->setRequired(true);
167  $exp->setValue(ilECSExport::_isExported($obj_id) ? 1 : 0);
168  $off = new ilRadioOption($lng->txt('ecs_' . $a_type . '_export_disabled'), 0);
169  $exp->addOption($off);
170  $on = new ilRadioOption($lng->txt('ecs_' . $a_type . '_export_enabled'), 1);
171  $exp->addOption($on);
172  $a_form->addItem($exp);
173 
174  // Show all exportable participants
175  $publish_for = new ilCheckboxGroupInputGUI($lng->txt('ecs_publish_for'), 'ecs_sid');
176 
177  // @TODO: Active checkboxes for recipients
178  //$publish_for->setValue((array) $members);
179 
180  // Read receivers
181  $receivers = array();
182  include_once('./Services/WebServices/ECS/classes/class.ilECSEContentDetails.php');
183  foreach (ilECSExport::getExportServerIds($obj_id) as $sid) {
184  $exp = new ilECSExport($sid, $obj_id);
185 
186  $participants = null;
188  $sid,
189  $exp->getEContentId(),
190  $this->getECSObjectType()
191  );
192  if ($details instanceof ilECSEContentDetails) {
193  $participants = $details->getReceivers();
194  }
195  if ($participants) {
196  foreach ($participants as $mid) {
197  $receivers[] = $sid . '_' . $mid;
198  }
199  }
200  }
201  $publish_for->setValue($receivers);
202 
203  foreach ($exportablePart as $pInfo) {
204  include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSetting.php';
205  $partSetting = new ilECSParticipantSetting($pInfo['sid'], $pInfo['mid']);
206 
207  $com = new ilCheckboxInputGUI(
208  $partSetting->getCommunityName() . ': ' . $partSetting->getTitle(),
209  'sid_mid'
210  );
211  $com->setValue($pInfo['sid'] . '_' . $pInfo['mid']);
212  $publish_for->addOption($com);
213  }
214  $on->addSubItem($publish_for);
215  return true;
216  }
217 
226  public function handleSettingsUpdate()
227  {
228  if (!$this->isActive()) {
229  return true;
230  }
231 
232  // Parse post data
233  $mids = array();
234  foreach ((array) $_POST['ecs_sid'] as $sid_mid) {
235  $tmp = explode('_', $sid_mid);
236  $mids[$tmp[0]][] = $tmp[1];
237  }
238 
239  try {
240  include_once './Services/WebServices/ECS/classes/class.ilECSCommunitiesCache.php';
241  include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSettings.php';
242  include_once './Services/WebServices/ECS/classes/class.ilECSSetting.php';
243 
244  // Update for each server
245  foreach (ilECSParticipantSettings::getExportServers() as $server_id) {
247  if ($server->isEnabled()) {
248  // Export
249  $export = true;
250  if (!$_POST['ecs_export']) {
251  $export = false;
252  }
253  if (
254  !isset($mids[$server_id]) ||
255  !is_array($mids[$server_id]) ||
256  !count($mids[$server_id])) {
257  $export = false;
258  }
260  $server,
261  $export,
262  isset($mids[$server_id]) ? $mids[$server_id] : []
263  );
264  }
265  }
266  } catch (ilECSConnectorException $exc) {
267  ilUtil::sendFailure('Error exporting to ECS server: ' . $exc->getMessage());
268  return false;
269  }
270  return true;
271  }
272 
281  protected function handleSettingsForServer(ilECSSetting $a_server, $a_export, $a_mids)
282  {
283  try {
284  include_once('./Services/WebServices/ECS/classes/class.ilECSExport.php');
285  $export_settings = new ilECSExport($a_server->getServerId(), $this->content_obj->getId());
286 
287  // already exported?
288  if ($export_settings->isExported()) {
289  // still exportable: update ecs
290  if ((bool) $a_export) {
291  $this->doUpdate($a_server, $export_settings, $a_mids);
292  }
293  // not exportable anymore
294  else {
295  $this->doDelete($a_server, $export_settings);
296  }
297  }
298  // not exported yet
299  else {
300  // now to be exported
301  if ($a_export) {
302  $this->doAdd($a_server, $export_settings, $a_mids);
303  }
304  // was not and will not be exported
305  else {
306  }
307  }
308  } catch (ilECSConnectorException $exc) {
309  throw $exc;
310  }
311  }
312 
320  public function handleContentUpdate()
321  {
322  global $DIC;
323 
324  $ilLog = $DIC['ilLog'];
325 
326  if (!$this->isActive()) {
327  return true;
328  }
329 
330  include_once './Services/WebServices/ECS/classes/class.ilECSExport.php';
331  $export_servers = ilECSExport::getExportServerIds($this->content_obj->getId());
332  foreach ($export_servers as $server_id) {
333  include_once './Services/WebServices/ECS/classes/class.ilECSSetting.php';
335  if ($server->isEnabled()) {
336  try {
337  include_once('./Services/WebServices/ECS/classes/class.ilECSExport.php');
338  $export_settings = new ilECSExport($server_id, $this->content_obj->getId());
339 
340  // already exported, update ecs
341  if ($export_settings->isExported()) {
342  $this->doUpdate($server, $export_settings);
343  }
344  // not exported yet, nothing to do
345  else {
346  }
347  } catch (ilECSConnectorException $exc) {
348  $ilLog->write(__METHOD__ . ': Cannot handle ECS content update. ' . $exc->getMessage());
349  return false;
350  }
351  }
352  }
353  return true;
354  }
355 
363  protected function doAdd(ilECSSetting $a_server, ilECSExport $a_export_settings, array $a_mids)
364  {
365  global $DIC;
366 
367  $ilLog = $DIC['ilLog'];
368 
369  $ilLog->write(__METHOD__ . ': Starting ECS add resource...');
370 
371  $json = $this->buildJson($a_server);
372 
373  include_once 'Services/WebServices/ECS/classes/class.ilECSConnector.php';
374  $connector = new ilECSConnector($a_server);
375  $connector->addHeader(ilECSConnector::HEADER_MEMBERSHIPS, implode(',', $a_mids));
376  $econtent_id = $connector->addResource(
377  $this->getECSObjectType(),
378  json_encode($json)
379  );
380 
381  // status changed
382  $a_export_settings->setExported(true);
383  $a_export_settings->setEContentId($econtent_id);
384  $a_export_settings->save();
385 
386  $this->handlePermissionUpdate($a_server, true);
387 
388  // Send mail
389  $this->sendNewContentNotification($a_server, $econtent_id);
390  }
391 
400  protected function doUpdate(ilECSSetting $a_server, ilECSExport $a_export_settings, array $a_mids = null)
401  {
402  global $DIC;
403 
404  $ilLog = $DIC['ilLog'];
405 
406  include_once 'Services/WebServices/ECS/classes/class.ilECSConnector.php';
407 
408  $econtent_id = $a_export_settings->getEContentId();
409  if (!$econtent_id) {
410  $ilLog->write(__METHOD__ . ': Missing eid. Aborting.');
411  throw new ilECSConnectorException('Missing ECS content ID. Aborting.');
412  }
413  $connector = new ilECSConnector($a_server);
414 
415  if (!$a_mids) {
416  $a_mids = $this->getParticipants($a_server->getServerId(), $econtent_id);
417  }
418  $ilLog->write(__METHOD__ . ': Start updating ECS content - ' . print_r($a_mids, true));
419  $connector->addHeader(ilECSConnector::HEADER_MEMBERSHIPS, implode(',', (array) $a_mids));
420 
421  $json = $this->buildJson($a_server);
422  $connector->updateResource(
423  $this->getECSObjectType(),
424  $econtent_id,
425  json_encode($json)
426  );
427 
428  $this->handlePermissionUpdate($a_server, true);
429  }
430 
439  public function doDelete(ilECSSetting $a_server, ilECSExport $a_export_settings)
440  {
441  global $DIC;
442 
443  $ilLog = $DIC['ilLog'];
444 
445  // already exported?
446  if ($a_export_settings->isExported()) {
447  include_once './Services/WebServices/ECS/classes/class.ilECSSetting.php';
448  include_once './Services/WebServices/ECS/classes/class.ilECSConnector.php';
449 
450  $econtent_id = $a_export_settings->getEContentId();
451  if (!$econtent_id) {
452  $ilLog->write(__METHOD__ . ': Missing eid. Aborting.');
453  throw new ilECSConnectorException('Missing ECS content ID. Aborting.');
454  }
455  $connector = new ilECSConnector($a_server);
456 
457  $ilLog->write(__METHOD__ . ': Start deleting ECS content...');
458  $connector->deleteResource(
459  $this->getECSObjectType(),
460  $econtent_id
461  );
462 
463  // status changed
464  $a_export_settings->setExported(false);
465  $a_export_settings->save();
466  }
467  }
468 
476  public static function _handleDelete(array $a_subbtree_nodes)
477  {
478  // active?
479  include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
480  if (!ilECSServerSettings::getInstance()->activeServerExists()) {
481  return;
482  }
483 
484  include_once './Services/WebServices/ECS/classes/class.ilECSSetting.php';
485  include_once './Services/WebServices/ECS/classes/class.ilECSExport.php' ;
486  $exported = ilECSExport::getExportedIds();
487  foreach ($a_subbtree_nodes as $node) {
488  if (in_array($node['obj_id'], $exported)) {
489  if ($content_obj = ilObjectFactory::getInstanceByRefId($node['child'], false)) {
490  $settings = self::getInstanceByObject($content_obj);
491 
492  // Read export server ids
493  foreach (ilECSExport::getExportServerIds($node['obj_id']) as $sid) {
495  $export_settings = new ilECSExport($sid, $content_obj->getId());
496  $settings->doDelete($server, $export_settings);
497  }
498  }
499  }
500  }
501  }
502 
510  protected function getParticipants($a_server_id, $a_econtent_id)
511  {
512  $receivers = array();
513  include_once('./Services/WebServices/ECS/classes/class.ilECSEContentDetails.php');
514  foreach ((array) $a_server_id as $sid) {
515  $participants = null;
516  $details = ilECSEContentDetails::getInstance($sid, $a_econtent_id, $this->getECSObjectType());
517  if ($details instanceof ilECSEContentDetails) {
518  $participants = $details->getReceivers();
519  }
520  if ($participants) {
521  foreach ($participants as $mid) {
522  $receivers[] = $mid;
523  }
524  }
525  }
526  return (array) $receivers;
527  }
528 
534  protected function sendNewContentNotification(ilECSSetting $a_server, $a_econtent_id)
535  {
536  global $DIC;
537 
538  $ilLog = $DIC['ilLog'];
539 
540  if (!count($rcps = $a_server->getApprovalRecipients())) {
541  return true;
542  }
543 
544  include_once('./Services/Mail/classes/class.ilMail.php');
545  include_once('./Services/Language/classes/class.ilLanguageFactory.php');
546 
548  $lang->loadLanguageModule('ecs');
549 
550  // @TODO: read mail
551  $mail = new ilMail(self::MAIL_SENDER);
552  $message = $lang->txt('ecs_export_created_body_a') . "\n\n";
553  $message .= $lang->txt('title') . ': ' . $this->content_obj->getTitle() . "\n";
554  if (strlen($desc = $this->content_obj->getDescription())) {
555  $message .= $lang->txt('desc') . ': ' . $desc . "\n";
556  }
557 
558  // Participant info
559  $message .= ("\n" . $lang->txt('ecs_published_for'));
560 
561  try {
562  $found = false;
563 
564  $receivers = null;
565  include_once('./Services/WebServices/ECS/classes/class.ilECSEContentDetails.php');
567  $a_server->getServerId(),
568  $a_econtent_id,
569  $this->getECSObjectType()
570  );
571  if ($details instanceof ilECSEContentDetails) {
572  $receivers = $details->getReceivers();
573  }
574  if ($receivers) {
575  foreach ($receivers as $member) {
576  $found = true;
577 
578  include_once './Services/WebServices/ECS/classes/class.ilECSCommunityReader.php';
579  $part = ilECSCommunityReader::getInstanceByServerId($a_server->getServerId())->getParticipantByMID($member);
580 
581  $message .= ("\n\n" . $part->getParticipantName() . "\n");
582  $message .= ($part->getDescription());
583  }
584  }
585  if ($found) {
586  $message .= "\n\n";
587  } else {
588  $message .= (' ' . $lang->txt('ecs_not_published') . "\n\n");
589  }
590  } catch (ilECSConnectorException $e) {
591  $ilLog->write(__METHOD__ . ': Cannot read approvements.');
592  return false;
593  }
594 
595  include_once('./Services/Link/classes/class.ilLink.php');
596  $href = ilLink::_getStaticLink($this->content_obj->getRefId(), 'crs', true);
597  $message .= $lang->txt("perma_link") . ': ' . $href . "\n\n";
599 
600  $mail->sendMail(
601  $a_server->getApprovalRecipientsAsString(),
602  '',
603  '',
604  $lang->txt('ecs_new_approval_subject'),
605  $message,
606  array(),
607  array('normal')
608  );
609 
610  return true;
611  }
612 
618  {
619  if (
620  ($this->content_obj->getType() == 'crs') ||
621  ($this->content_obj->getType() == 'grp')
622  ) {
623  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': Permission update for courses/groups');
624  $GLOBALS['DIC']['rbacadmin']->grantPermission(
625  $server->getGlobalRole(),
626  ilRbacReview::_getOperationIdsByName(array('join','visible')),
627  $this->content_obj->getRefId()
628  );
629  }
630  }
631 
638  protected function getJsonCore($a_etype)
639  {
640  $json = new stdClass();
641  $json->lang = 'en_EN'; // :TODO: obsolet?
642  $json->id = 'il_' . IL_INST_ID . '_' . $this->getContentObject()->getType() . '_' . $this->getContentObject()->getId();
643  $json->etype = $a_etype;
644  $json->title = $this->content_obj->getTitle();
645  $json->abstract = $this->content_obj->getLongDescription();
646 
647  include_once('./Services/Link/classes/class.ilLink.php');
648  $json->url = ilLink::_getLink($this->content_obj->getRefId(), $this->content_obj->getType());
649 
650  return $json;
651  }
652 
660  protected function addMetadataToJson(&$a_json, ilECSSetting $a_server, array $a_definition)
661  {
662  include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
663  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
664  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
666 
667  include_once "Services/WebServices/ECS/classes/class.ilECSUtils.php";
668  $values = ilECSUtils::getAdvancedMDValuesForObjId($this->content_obj->getId());
669 
670  foreach ($a_definition as $id => $type) {
671  if (is_array($type)) {
672  $target = $type[1];
673  $type = $type[0];
674  } else {
675  $target = $id;
676  }
677 
678  if ($field = $mappings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_EXPORT, $id)) {
679  $value = isset($values[$field]) ? $values[$field] : '';
680 
681  switch ($type) {
683  $a_json->$target = explode(',', $value);
684  break;
685 
687  $a_json->$target = (int) $value;
688  break;
689 
691  $a_json->$target = (string) $value;
692  break;
693 
695  if (!isset($a_json->$target)) {
696  include_once('./Services/WebServices/ECS/classes/class.ilECSTimePlace.php');
697  $a_json->$target = new ilECSTimePlace();
698  }
699  $a_json->$target->{'set' . ucfirst($id)}($value);
700  break;
701  }
702  }
703  }
704  }
705 
712  abstract protected function buildJson(ilECSSetting $a_server);
713 }
Class ilECSFileSettings.
This class represents an option in a radio group.
static getInstanceByServerId($a_server_id)
Get singleton instance.
handleContentUpdate()
Update ECS Content.
static getInstanceByServerId($a_server_id)
Get singleton instance per server.
getParticipants($a_server_id, $a_econtent_id)
Get participants for server and ecs resource.
Representation of ECS EContent Time Place.
static _getOperationIdsByName($operations)
get ops_id&#39;s by name.
This class represents a property form user interface.
$type
getServerId()
Get current server id.
global $DIC
Definition: saml.php:7
static getExportableParticipants($a_type)
Get participants which are enabled and export is allowed.
Storage of ECS exported objects.
This class represents a section header in a property form.
doUpdate(ilECSSetting $a_server, ilECSExport $a_export_settings, array $a_mids=null)
Update ECS resource.
isActive()
Is ECS (for current object) active?
getApprovalRecipientsAsString()
get approval recipients as string
static _handleDelete(array $a_subbtree_nodes)
handle delete Objects that are moved to the trash call ECS-Remove
setExported($a_status)
Set exported.
static getInstance()
Get singleton instance.
if(!array_key_exists('StateId', $_REQUEST)) $id
This class represents a checkbox property in a property form.
addItem($a_item)
Add Item (Property, SectionHeader).
handleSettingsForServer(ilECSSetting $a_server, $a_export, $a_mids)
Save ECS settings (add- update- deleteResource)
Presentation of ecs content details (http://...campusconnect/courselinks/id/details) ...
getECSObjectType()
Get ECS resource identifier, e.g.
__construct(ilObject $a_content_object)
Constructor.
$server
Definition: sabredav.php:48
const TYPE_TIMEPLACE
Class ilECSLearningModuleSettings.
static getInstanceByServerId($a_server_id)
Get instance by server id.
getContentObject()
Get content object.
$a_type
Definition: workflow.php:92
Class ilECSWikiSettings.
static _getLanguage($a_lang_key='')
Get langauge object.
static getExportedIds()
Get exported ids ilDB $ilDB.
catch(Exception $e) $message
static getExportServerIds($a_obj_id)
lookup server ids of exported materials ilDB $ilDB
This class represents a property in a property form.
static getInstanceByObject(ilObject $a_content_obj)
Get settings handler for repository object.
addMetadataToJson(&$a_json, ilECSSetting $a_server, array $a_definition)
Add advanced metadata to json (export)
sendNewContentNotification(ilECSSetting $a_server, $a_econtent_id)
send notifications about new EContent
$lng
isExported()
check if an object is exported or not
getEContentId()
get econtent id
$values
static getAdvancedMDValuesForObjId($a_obj_id)
Get advanced metadata values for object id.
Class ilECSGroupSettings.
setValue($a_value)
Set Value.
handlePermissionUpdate(ilECSSetting $server)
Handle permission update.
doAdd(ilECSSetting $a_server, ilECSExport $a_export_settings, array $a_mids)
Add resource to ECS.
This class represents a property in a property form.
static _isExported($a_obj_id)
Check if object is exported.
buildJson(ilECSSetting $a_server)
Build resource-specific json.
getType()
get object type public
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
getGlobalRole()
get global role
handleSettingsUpdate()
Update ECS Export Settings.
getJsonCore($a_etype)
Build core json structure.
static _getAutoGeneratedMessageString(ilLanguage $lang=null)
Get auto generated info string.
for($i=1; $i<=count($kw_cases_sel); $i+=1) $lang
Definition: langwiz.php:349
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
setEContentId($a_id)
set econtent id
Class ilECSCategorySettings.
getApprovalRecipients()
get approval recipients
Handles object exports to ECS.
addSettingsToForm(ilPropertyFormGUI $a_form, $a_type)
Fill ECS export settings "multiple servers".
$target
Definition: test.php:19
static getInstance($a_server_id, $a_econtent_id, $a_resource_type)
Get data from server.
$_POST["username"]
doDelete(ilECSSetting $a_server, ilECSExport $a_export_settings)
Delete ECS resource.
setRequired($a_required)
Set Required.
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
Class ilECSGlossarySettings.
static getExportServers()
Get server ids which allow an export <type> $ilDB.
Class ilECSCourseSettings.