/** * Lookup participant name * @param int $a_owner Mid of participant * @param int $a_server_id * @return */ public static function lookupParticipantName($a_owner, $a_server_id) { global $ilLog; try { include_once './Services/WebServices/ECS/classes/class.ilECSCommunityReader.php'; $reader = ilECSCommunityReader::getInstanceByServerId($a_server_id); if ($part = $reader->getParticipantByMID($a_owner)) { return $part->getParticipantName(); } return ''; } catch (ilECSConnectorException $e) { $ilLog->write(__METHOD__ . ': Error reading participants.'); return ''; } }
/** * update whitelist * * @access protected * */ protected function updateCommunities() { global $ilLog; include_once './Services/WebServices/ECS/classes/class.ilECSCommunityReader.php'; include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php'; // @TODO: Delete deprecated communities $invalidImportTypes = false; if (!$this->validateImportTypes($_POST['import_type'])) { $invalidImportTypes = true; } $servers = ilECSServerSettings::getInstance(); foreach ($servers->getServers() as $server) { try { // Read communities $cReader = ilECSCommunityReader::getInstanceByServerId($server->getServerId()); // Update community cache foreach ($cReader->getCommunities() as $community) { include_once './Services/WebServices/ECS/classes/class.ilECSCommunityCache.php'; $cCache = ilECSCommunityCache::getInstance($server->getServerId(), $community->getId()); $cCache->setCommunityName($community->getTitle()); $cCache->setMids($community->getMids()); $cCache->setOwnId($community->getOwnId()); $cCache->update(); } } catch (Exception $e) { $GLOBALS['ilLog']->write(__METHOD__ . ': Cannot read ecs communities: ' . $e->getMessage()); } } include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSetting.php'; foreach ((array) $_POST['sci_mid'] as $sid => $tmp) { foreach ((array) $_POST['sci_mid'][$sid] as $mid => $tmp) { $set = new ilECSParticipantSetting($sid, $mid); $set->enableExport(array_key_exists($mid, (array) $_POST['export'][$sid]) ? true : false); $set->enableImport(array_key_exists($mid, (array) $_POST['import'][$sid]) ? true : false); $set->setImportType($_POST['import_type'][$sid][$mid]); // update title/cname try { $part = ilECSCommunityReader::getInstanceByServerId($sid)->getParticipantByMID($mid); if ($part instanceof ilECSParticipant) { $set->setTitle($part->getParticipantName()); } $com = ilECSCommunityReader::getInstanceByServerId($sid)->getCommunityByMID($mid); if ($com instanceof ilECSCommunity) { $set->setCommunityName($com->getTitle()); } } catch (Exception $e) { $GLOBALS['ilLog']->write(__METHOD__ . ': Cannot read ecs communities: ' . $e->getMessage()); } $set->update(); } } if ($invalidImportTypes) { ilUtil::sendFailure($this->lng->txt('ecs_invalid_import_type_cms'), true); } else { ilUtil::sendSuccess($this->lng->txt('settings_saved'), true); } $GLOBALS['ilCtrl']->redirect($this, 'communities'); // TODO: Do update of remote courses and ... return true; }
/** * Parse * * @access public * @param array array of remote course ids * */ public function parse($a_rcrs) { global $ilObjDataCache; // Preload object data $ilObjDataCache->preloadReferenceCache($a_rcrs); // Read participants include_once './Modules/RemoteCourse/classes/class.ilObjRemoteCourse.php'; include_once './Services/WebServices/ECS/classes/class.ilECSCommunityReader.php'; include_once './Services/WebServices/ECS/classes/class.ilECSImport.php'; // read obj_ids $obj_ids = array(); foreach ($a_rcrs as $rcrs_ref_id) { $obj_id = $ilObjDataCache->lookupObjId($rcrs_ref_id); $obj_ids[$obj_id] = $ilObjDataCache->lookupObjId($rcrs_ref_id); } foreach ($obj_ids as $obj_id => $obj_id) { $tmp_arr['obj_id'] = $obj_id; $tmp_arr['sid'] = ilECSImport::lookupServerId($obj_id); $tmp_arr['title'] = $ilObjDataCache->lookupTitle($obj_id); $tmp_arr['desc'] = $ilObjDataCache->lookupDescription($obj_id); $tmp_arr['md'] = ''; $mid = ilObjRemoteCourse::_lookupMID($obj_id); if ($tmp_arr['sid']) { try { $reader = ilECSCommunityReader::getInstanceByServerId($tmp_arr['sid']); } catch (ilECSConnectorException $e) { $reader = null; } if ($reader and $participant = $reader->getParticipantByMID($mid)) { $tmp_arr['from'] = $participant->getParticipantName(); $tmp_arr['from_info'] = $participant->getDescription(); } } else { $tmp_arr['from'] = $this->lng->txt("ecs_server_deleted"); } $tmp_arr['last_update'] = $ilObjDataCache->lookupLastUpdate($obj_id); $content[] = $tmp_arr; } $this->setData($content ? $content : array()); }
/** * send notifications about new EContent * * @return bool */ protected function sendNewContentNotification(ilECSSetting $a_server, $a_econtent_id) { global $ilLog; if (!count($rcps = $a_server->getApprovalRecipients())) { return true; } include_once './Services/Mail/classes/class.ilMail.php'; include_once './Services/Language/classes/class.ilLanguageFactory.php'; $lang = ilLanguageFactory::_getLanguage(); $lang->loadLanguageModule('ecs'); // @TODO: read mail $mail = new ilMail(self::MAIL_SENDER); $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'); try { $found = false; $receivers = null; include_once './Services/WebServices/ECS/classes/class.ilECSEContentDetails.php'; $details = ilECSEContentDetails::getInstance($a_server->getServerId(), $a_econtent_id, $this->getECSObjectType()); if ($details instanceof ilECSEContentDetails) { $receivers = $details->getReceivers(); } if ($receivers) { foreach ($receivers as $member) { $found = true; include_once './Services/WebServices/ECS/classes/class.ilECSCommunityReader.php'; $part = ilECSCommunityReader::getInstanceByServerId($a_server->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"; } } catch (ilECSConnectorException $e) { $ilLog->write(__METHOD__ . ': Cannot read approvements.'); return false; } include_once './Services/Link/classes/class.ilLink.php'; $href = ilLink::_getStaticLink($this->content_obj->getRefId(), 'crs', true); $message .= $lang->txt("perma_link") . ': ' . $href . "\n\n"; $message .= ilMail::_getAutoGeneratedMessageString(); $mail->sendMail($a_server->getApprovalRecipientsAsString(), '', '', $lang->txt('ecs_new_approval_subject'), $message, array(), array('normal')); return true; }
/** * Validate ECS hash * * @access public * @param string username * @param string pass * */ public function validateHash() { global $ilLog; // fetch hash if (isset($_GET['ecs_hash']) and strlen($_GET['ecs_hash'])) { $hash = $_GET['ecs_hash']; } if (isset($_GET['ecs_hash_url'])) { $hashurl = urldecode($_GET['ecs_hash_url']); $hash = basename(parse_url($hashurl, PHP_URL_PATH)); //$hash = urldecode($_GET['ecs_hash_url']); } $GLOBALS['ilLog']->write(__METHOD__ . ': Using ecs hash ' . $hash); // Check if hash is valid ... try { include_once './Services/WebServices/ECS/classes/class.ilECSConnector.php'; $connector = new ilECSConnector($this->getCurrentServer()); $res = $connector->getAuth($hash); $auths = $res->getResult(); $GLOBALS['ilLog']->write(__METHOD__ . ': Auths: ' . print_r($auths, TRUE)); if ($auths->pid) { try { include_once './Services/WebServices/ECS/classes/class.ilECSCommunityReader.php'; $reader = ilECSCommunityReader::getInstanceByServerId($this->getCurrentServer()->getServerId()); $part = $reader->getParticipantByMID($auths->pid); if (is_object($part) and is_object($part->getOrganisation())) { $this->abreviation = $part->getOrganisation()->getAbbreviation(); } else { $this->abreviation = $auths->abbr; } } catch (Exception $e) { $ilLog->write(__METHOD__ . ': Authentication failed with message: ' . $e->getMessage()); return false; } } else { $this->abreviation = $auths->abbr; } $ilLog->write(__METHOD__ . ': Got abr: ' . $this->abreviation); } catch (ilECSConnectorException $e) { $ilLog->write(__METHOD__ . ': Authentication failed with message: ' . $e->getMessage()); return false; } // read current mid try { include_once './Services/WebServices/ECS/classes/class.ilECSConnector.php'; $connector = new ilECSConnector($this->getCurrentServer()); $details = $connector->getAuth($hash, TRUE); $GLOBALS['ilLog']->write(__METHOD__ . ': ' . print_r($details, TRUE)); $GLOBALS['ilLog']->write(__METHOD__ . ': Token created for mid ' . $details->getFirstSender()); $this->setMID($details->getFirstSender()); } catch (ilECSConnectorException $e) { $ilLog->write(__METHOD__ . ': Receiving mid failed with message: ' . $e->getMessage()); return false; } return TRUE; }
/** * Read MID's of this installation * * @access private * */ private function readMIDs() { try { $this->mids = array(); include_once './Services/WebServices/ECS/classes/class.ilECSCommunityReader.php'; $reader = ilECSCommunityReader::getInstanceByServerId($this->getServer()->getServerId()); foreach ($reader->getCommunities() as $com) { foreach ($com->getParticipants() as $part) { if ($part->isSelf()) { $this->mids[] = $part->getMID(); $this->log->write('Fetch MID: ' . $part->getMID()); } } } } catch (ilException $exc) { throw $exc; } }