ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
13abstract 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
121 {
122 global $lng;
123
124 $this->logger->debug('Show ecs settings.');
125 if (!$this->isActive($a_type)) {
126 $this->logger->debug('Object type is not active. => no settings.');
127 return;
128 }
129
130 $obj_id = $this->content_obj->getId();
131
132 // Return if no participant is enabled for export and the current object is not released
133 include_once './Services/WebServices/ECS/classes/class.ilECSExport.php';
134 include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSettings.php';
135
136 if (!$this->getContentObject()->withReferences()) {
137 $this->logger->debug('Called withot references. => no settings.');
138 return true;
139 }
140
142 if (!$exportablePart and !ilECSExport::_isExported($obj_id)) {
143 $this->logger->debug('Object type is not exportable. => no settings.');
144 return true;
145 }
146 if (
147 $GLOBALS['tree']->checkForParentType($GLOBALS['tree']->getParentId($this->getContentObject()->getRefId()), 'crs', false) or
148 $GLOBALS['tree']->checkForParentType($GLOBALS['tree']->getParentId($this->getContentObject()->getRefId()), 'grp', false)
149 ) {
150 $this->logger->debug('Parent crs/grp in path. => no settings.');
151 return true;
152 }
153
154 $lng->loadLanguageModule('ecs');
155
156 // show ecs property form section
157 $ecs = new ilFormSectionHeaderGUI();
158 $ecs->setTitle($lng->txt('ecs_' . $a_type . '_export'));
159 $a_form->addItem($ecs);
160
161
162 // release or not
163 $exp = new ilRadioGroupInputGUI($lng->txt('ecs_' . $a_type . '_export_obj_settings'), 'ecs_export');
164 $exp->setRequired(true);
165 $exp->setValue(ilECSExport::_isExported($obj_id) ? 1 : 0);
166 $off = new ilRadioOption($lng->txt('ecs_' . $a_type . '_export_disabled'), 0);
167 $exp->addOption($off);
168 $on = new ilRadioOption($lng->txt('ecs_' . $a_type . '_export_enabled'), 1);
169 $exp->addOption($on);
170 $a_form->addItem($exp);
171
172 // Show all exportable participants
173 $publish_for = new ilCheckboxGroupInputGUI($lng->txt('ecs_publish_for'), 'ecs_sid');
174
175 // @TODO: Active checkboxes for recipients
176 //$publish_for->setValue((array) $members);
177
178 // Read receivers
179 $receivers = array();
180 include_once('./Services/WebServices/ECS/classes/class.ilECSEContentDetails.php');
181 foreach (ilECSExport::getExportServerIds($obj_id) as $sid) {
182 $exp = new ilECSExport($sid, $obj_id);
183
184 $participants = null;
186 $sid,
187 $exp->getEContentId(),
188 $this->getECSObjectType()
189 );
190 if ($details instanceof ilECSEContentDetails) {
191 $participants = $details->getReceivers();
192 }
193 if ($participants) {
194 foreach ($participants as $mid) {
195 $receivers[] = $sid . '_' . $mid;
196 }
197 }
198 }
199 $publish_for->setValue($receivers);
200
201 foreach ($exportablePart as $pInfo) {
202 include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSetting.php';
203 $partSetting = new ilECSParticipantSetting($pInfo['sid'], $pInfo['mid']);
204
205 $com = new ilCheckboxInputGUI(
206 $partSetting->getCommunityName() . ': ' . $partSetting->getTitle(),
207 'sid_mid'
208 );
209 $com->setValue($pInfo['sid'] . '_' . $pInfo['mid']);
210 $publish_for->addOption($com);
211 }
212 $on->addSubItem($publish_for);
213 return true;
214 }
215
224 public function handleSettingsUpdate()
225 {
226 if (!$this->isActive()) {
227 return true;
228 }
229
230 // Parse post data
231 $mids = array();
232 foreach ((array) $_POST['ecs_sid'] as $sid_mid) {
233 $tmp = explode('_', $sid_mid);
234 $mids[$tmp[0]][] = $tmp[1];
235 }
236
237 try {
238 include_once './Services/WebServices/ECS/classes/class.ilECSCommunitiesCache.php';
239 include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSettings.php';
240 include_once './Services/WebServices/ECS/classes/class.ilECSSetting.php';
241
242 // Update for each server
243 foreach (ilECSParticipantSettings::getExportServers() as $server_id) {
245 if ($server->isEnabled()) {
246 // Export
247 $export = true;
248 if (!$_POST['ecs_export']) {
249 $export = false;
250 }
251 if (!count($mids[$server_id])) {
252 $export = false;
253 }
255 $server,
256 $export,
257 $mids[$server_id]
258 );
259 }
260 }
261 } catch (ilECSConnectorException $exc) {
262 ilUtil::sendFailure('Error exporting to ECS server: ' . $exc->getMessage());
263 return false;
264 }
265 return true;
266 }
267
276 protected function handleSettingsForServer(ilECSSetting $a_server, $a_export, $a_mids)
277 {
278 try {
279 include_once('./Services/WebServices/ECS/classes/class.ilECSExport.php');
280 $export_settings = new ilECSExport($a_server->getServerId(), $this->content_obj->getId());
281
282 // already exported?
283 if ($export_settings->isExported()) {
284 // still exportable: update ecs
285 if ((bool) $a_export) {
286 $this->doUpdate($a_server, $export_settings, $a_mids);
287 }
288 // not exportable anymore
289 else {
290 $this->doDelete($a_server, $export_settings);
291 }
292 }
293 // not exported yet
294 else {
295 // now to be exported
296 if ($a_export) {
297 $this->doAdd($a_server, $export_settings, $a_mids);
298 }
299 // was not and will not be exported
300 else {
301 }
302 }
303 } catch (ilECSConnectorException $exc) {
304 throw $exc;
305 }
306 }
307
315 public function handleContentUpdate()
316 {
317 global $ilLog;
318
319 if (!$this->isActive()) {
320 return true;
321 }
322
323 include_once './Services/WebServices/ECS/classes/class.ilECSExport.php';
324 $export_servers = ilECSExport::getExportServerIds($this->content_obj->getId());
325 foreach ($export_servers as $server_id) {
326 include_once './Services/WebServices/ECS/classes/class.ilECSSetting.php';
328 if ($server->isEnabled()) {
329 try {
330 include_once('./Services/WebServices/ECS/classes/class.ilECSExport.php');
331 $export_settings = new ilECSExport($server_id, $this->content_obj->getId());
332
333 // already exported, update ecs
334 if ($export_settings->isExported()) {
335 $this->doUpdate($server, $export_settings);
336 }
337 // not exported yet, nothing to do
338 else {
339 }
340 } catch (ilECSConnectorException $exc) {
341 $ilLog->write(__METHOD__ . ': Cannot handle ECS content update. ' . $exc->getMessage());
342 return false;
343 }
344 }
345 }
346 return true;
347 }
348
356 protected function doAdd(ilECSSetting $a_server, ilECSExport $a_export_settings, array $a_mids)
357 {
358 global $ilLog;
359
360 $ilLog->write(__METHOD__ . ': Starting ECS add resource...');
361
362 $json = $this->buildJson($a_server);
363
364 include_once 'Services/WebServices/ECS/classes/class.ilECSConnector.php';
365 $connector = new ilECSConnector($a_server);
366 $connector->addHeader(ilECSConnector::HEADER_MEMBERSHIPS, implode(',', $a_mids));
367 $econtent_id = $connector->addResource(
368 $this->getECSObjectType(),
369 json_encode($json)
370 );
371
372 // status changed
373 $a_export_settings->setExported(true);
374 $a_export_settings->setEContentId($econtent_id);
375 $a_export_settings->save();
376
377 $this->handlePermissionUpdate($a_server, true);
378
379 // Send mail
380 $this->sendNewContentNotification($a_server, $econtent_id);
381 }
382
391 protected function doUpdate(ilECSSetting $a_server, ilECSExport $a_export_settings, array $a_mids = null)
392 {
393 global $ilLog;
394
395 include_once 'Services/WebServices/ECS/classes/class.ilECSConnector.php';
396
397 $econtent_id = $a_export_settings->getEContentId();
398 if (!$econtent_id) {
399 $ilLog->write(__METHOD__ . ': Missing eid. Aborting.');
400 throw new ilECSConnectorException('Missing ECS content ID. Aborting.');
401 }
402 $connector = new ilECSConnector($a_server);
403
404 if (!$a_mids) {
405 $a_mids = $this->getParticipants($a_server->getServerId(), $econtent_id);
406 }
407 $ilLog->write(__METHOD__ . ': Start updating ECS content - ' . print_r($a_mids, true));
408 $connector->addHeader(ilECSConnector::HEADER_MEMBERSHIPS, implode(',', (array) $a_mids));
409
410 $json = $this->buildJson($a_server);
411 $connector->updateResource(
412 $this->getECSObjectType(),
413 $econtent_id,
414 json_encode($json)
415 );
416
417 $this->handlePermissionUpdate($a_server, true);
418 }
419
428 public function doDelete(ilECSSetting $a_server, ilECSExport $a_export_settings)
429 {
430 global $ilLog;
431
432 // already exported?
433 if ($a_export_settings->isExported()) {
434 include_once './Services/WebServices/ECS/classes/class.ilECSSetting.php';
435 include_once './Services/WebServices/ECS/classes/class.ilECSConnector.php';
436
437 $econtent_id = $a_export_settings->getEContentId();
438 if (!$econtent_id) {
439 $ilLog->write(__METHOD__ . ': Missing eid. Aborting.');
440 throw new ilECSConnectorException('Missing ECS content ID. Aborting.');
441 }
442 $connector = new ilECSConnector($a_server);
443
444 $ilLog->write(__METHOD__ . ': Start deleting ECS content...');
445 $connector->deleteResource(
446 $this->getECSObjectType(),
447 $econtent_id
448 );
449
450 // status changed
451 $a_export_settings->setExported(false);
452 $a_export_settings->save();
453 }
454 }
455
463 public static function _handleDelete(array $a_subbtree_nodes)
464 {
465 // active?
466 include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
467 if (!ilECSServerSettings::getInstance()->activeServerExists()) {
468 return;
469 }
470
471 include_once './Services/WebServices/ECS/classes/class.ilECSSetting.php';
472 include_once './Services/WebServices/ECS/classes/class.ilECSExport.php' ;
473 $exported = ilECSExport::getExportedIds();
474 foreach ($a_subbtree_nodes as $node) {
475 if (in_array($node['obj_id'], $exported)) {
476 if ($content_obj = ilObjectFactory::getInstanceByRefId($node['child'], false)) {
478
479 // Read export server ids
480 foreach (ilECSExport::getExportServerIds($node['obj_id']) as $sid) {
482 $export_settings = new ilECSExport($sid, $content_obj->getId());
483 $settings->doDelete($server, $export_settings);
484 }
485 }
486 }
487 }
488 }
489
497 protected function getParticipants($a_server_id, $a_econtent_id)
498 {
499 $receivers = array();
500 include_once('./Services/WebServices/ECS/classes/class.ilECSEContentDetails.php');
501 foreach ((array) $a_server_id as $sid) {
502 $participants = null;
503 $details = ilECSEContentDetails::getInstance($sid, $a_econtent_id, $this->getECSObjectType());
504 if ($details instanceof ilECSEContentDetails) {
505 $participants = $details->getReceivers();
506 }
507 if ($participants) {
508 foreach ($participants as $mid) {
509 $receivers[] = $mid;
510 }
511 }
512 }
513 return (array) $receivers;
514 }
515
521 protected function sendNewContentNotification(ilECSSetting $a_server, $a_econtent_id)
522 {
523 global $ilLog;
524
525 if (!count($rcps = $a_server->getApprovalRecipients())) {
526 return true;
527 }
528
529 include_once('./Services/Mail/classes/class.ilMail.php');
530 include_once('./Services/Language/classes/class.ilLanguageFactory.php');
531
533 $lang->loadLanguageModule('ecs');
534
535 // @TODO: read mail
536 $mail = new ilMail(self::MAIL_SENDER);
537 $message = $lang->txt('ecs_export_created_body_a') . "\n\n";
538 $message .= $lang->txt('title') . ': ' . $this->content_obj->getTitle() . "\n";
539 if (strlen($desc = $this->content_obj->getDescription())) {
540 $message .= $lang->txt('desc') . ': ' . $desc . "\n";
541 }
542
543 // Participant info
544 $message .= ("\n" . $lang->txt('ecs_published_for'));
545
546 try {
547 $found = false;
548
549 $receivers = null;
550 include_once('./Services/WebServices/ECS/classes/class.ilECSEContentDetails.php');
552 $a_server->getServerId(),
553 $a_econtent_id,
554 $this->getECSObjectType()
555 );
556 if ($details instanceof ilECSEContentDetails) {
557 $receivers = $details->getReceivers();
558 }
559 if ($receivers) {
560 foreach ($receivers as $member) {
561 $found = true;
562
563 include_once './Services/WebServices/ECS/classes/class.ilECSCommunityReader.php';
564 $part = ilECSCommunityReader::getInstanceByServerId($a_server->getServerId())->getParticipantByMID($member);
565
566 $message .= ("\n\n" . $part->getParticipantName() . "\n");
567 $message .= ($part->getDescription());
568 }
569 }
570 if ($found) {
571 $message .= "\n\n";
572 } else {
573 $message .= (' ' . $lang->txt('ecs_not_published') . "\n\n");
574 }
575 } catch (ilECSConnectorException $e) {
576 $ilLog->write(__METHOD__ . ': Cannot read approvements.');
577 return false;
578 }
579
580 include_once('./Services/Link/classes/class.ilLink.php');
581 $href = ilLink::_getStaticLink($this->content_obj->getRefId(), 'crs', true);
582 $message .= $lang->txt("perma_link") . ': ' . $href . "\n\n";
584
585 $mail->sendMail(
587 '',
588 '',
589 $lang->txt('ecs_new_approval_subject'),
590 $message,
591 array(),
592 array('normal')
593 );
594
595 return true;
596 }
597
603 {
604 if (
605 ($this->content_obj->getType() == 'crs') ||
606 ($this->content_obj->getType() == 'grp')
607 ) {
608 $GLOBALS['ilLog']->write(__METHOD__ . ': Permission update for courses/groups');
609 $GLOBALS['rbacadmin']->grantPermission(
610 $server->getGlobalRole(),
611 ilRbacReview::_getOperationIdsByName(array('join','visible')),
612 $this->content_obj->getRefId()
613 );
614 }
615 }
616
623 protected function getJsonCore($a_etype)
624 {
625 $json = new stdClass();
626 $json->lang = 'en_EN'; // :TODO: obsolet?
627 $json->id = 'il_' . IL_INST_ID . '_' . $this->getContentObject()->getType() . '_' . $this->getContentObject()->getId();
628 $json->etype = $a_etype;
629 $json->title = $this->content_obj->getTitle();
630 $json->abstract = $this->content_obj->getLongDescription();
631
632 include_once('./Services/Link/classes/class.ilLink.php');
633 $json->url = ilLink::_getLink($this->content_obj->getRefId(), $this->content_obj->getType());
634
635 return $json;
636 }
637
645 protected function addMetadataToJson(&$a_json, ilECSSetting $a_server, array $a_definition)
646 {
647 include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
648 include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
649 include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
651
652 include_once "Services/WebServices/ECS/classes/class.ilECSUtils.php";
653 $values = ilECSUtils::getAdvancedMDValuesForObjId($this->content_obj->getId());
654
655 foreach ($a_definition as $id => $type) {
656 if (is_array($type)) {
657 $target = $type[1];
658 $type = $type[0];
659 } else {
660 $target = $id;
661 }
662
663 if ($field = $mappings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_EXPORT, $id)) {
664 $value = isset($values[$field]) ? $values[$field] : '';
665
666 switch ($type) {
668 $a_json->$target = explode(',', $value);
669 break;
670
672 $a_json->$target = (int) $value;
673 break;
674
676 $a_json->$target = (string) $value;
677 break;
678
680 if (!isset($a_json->$target)) {
681 include_once('./Services/WebServices/ECS/classes/class.ilECSTimePlace.php');
682 $a_json->$target = new ilECSTimePlace();
683 }
684 $a_json->$target->{'set' . ucfirst($id)}($value);
685 break;
686 }
687 }
688 }
689 }
690
697 abstract protected function buildJson(ilECSSetting $a_server);
698}
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
This class represents a property in a property form.
This class represents a checkbox property in a property form.
Class ilECSCategorySettings.
static getInstanceByServerId($a_server_id)
Get instance by server id.
Class ilECSCourseSettings.
static getInstanceByServerId($a_server_id)
Get singleton instance.
Presentation of ecs content details (http://...campusconnect/courselinks/id/details)
static getInstance($a_server_id, $a_econtent_id, $a_resource_type)
Get data from server.
Storage of ECS exported objects.
getEContentId()
get econtent id
static getExportedIds()
Get exported ids @global ilDB $ilDB.
setExported($a_status)
Set exported.
isExported()
check if an object is exported or not
static _isExported($a_obj_id)
Check if object is exported.
static getExportServerIds($a_obj_id)
lookup server ids of exported materials @global ilDB $ilDB
setEContentId($a_id)
set econtent id
Class ilECSFileSettings.
Class ilECSGlossarySettings.
Class ilECSGroupSettings.
Class ilECSLearningModuleSettings.
Handles object exports to ECS.
getContentObject()
Get content object.
doUpdate(ilECSSetting $a_server, ilECSExport $a_export_settings, array $a_mids=null)
Update ECS resource.
static getInstanceByObject(ilObject $a_content_obj)
Get settings handler for repository object.
getJsonCore($a_etype)
Build core json structure.
sendNewContentNotification(ilECSSetting $a_server, $a_econtent_id)
send notifications about new EContent
isActive()
Is ECS (for current object) active?
static _handleDelete(array $a_subbtree_nodes)
addMetadataToJson(&$a_json, ilECSSetting $a_server, array $a_definition)
Add advanced metadata to json (export)
handlePermissionUpdate(ilECSSetting $server)
Handle permission update.
doAdd(ilECSSetting $a_server, ilECSExport $a_export_settings, array $a_mids)
Add resource to ECS.
addSettingsToForm(ilPropertyFormGUI $a_form, $a_type)
Fill ECS export settings "multiple servers".
handleSettingsUpdate()
Update ECS Export Settings.
getECSObjectType()
Get ECS resource identifier, e.g.
doDelete(ilECSSetting $a_server, ilECSExport $a_export_settings)
Delete ECS resource.
handleSettingsForServer(ilECSSetting $a_server, $a_export, $a_mids)
Save ECS settings (add- update- deleteResource)
getParticipants($a_server_id, $a_econtent_id)
Get participants for server and ecs resource.
buildJson(ilECSSetting $a_server)
Build resource-specific json.
handleContentUpdate()
Update ECS Content.
__construct(ilObject $a_content_object)
Constructor.
static getExportServers()
Get server ids which allow an export @global <type> $ilDB.
static getExportableParticipants($a_type)
Get participants which are enabled and export is allowed.
static getInstance()
Get singleton instance.
getServerId()
Get current server id.
getApprovalRecipientsAsString()
get approval recipients as string
getApprovalRecipients()
get approval recipients
static getInstanceByServerId($a_server_id)
Get singleton instance per server.
Representation of ECS EContent Time Place.
static getAdvancedMDValuesForObjId($a_obj_id)
Get advanced metadata values for object id.
const TYPE_TIMEPLACE
Class ilECSWikiSettings.
This class represents a section header in a property form.
static _getLanguage($a_lang_key='')
Get langauge object.
This class handles base functions for mail handling.
static _getAutoGeneratedMessageString(ilLanguage $lang=null)
Get auto generated info string.
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
Class ilObject Basic functions for all objects.
getType()
get object type @access public
This class represents a property form user interface.
addItem($a_item)
Add Item (Property, SectionHeader).
This class represents a property in a property form.
This class represents an option in a radio group.
static _getOperationIdsByName($operations)
get ops_id's by name.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$lang
Definition: consent.php:3
if(!array_key_exists('StateId', $_REQUEST)) $id
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
$server
Definition: getUserInfo.php:12
catch(Exception $e) $message
global $lng
Definition: privfeed.php:17
$type
$a_type
Definition: workflow.php:92