Example #1
0
 /**
  * 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 '';
     }
 }
 /**
  * csv export of imported remote courses
  *
  * @access protected
  * @return
  */
 protected function exportImported()
 {
     global $ilObjDataCache, $ilUser;
     // :TODO: mind resource type and move to ilRemoteObjectBase...
     $rcourses = ilUtil::_getObjectsByOperations('rcrs', 'visible', $ilUser->getId(), -1);
     // Read participants
     include_once './Modules/RemoteCourse/classes/class.ilObjRemoteCourse.php';
     include_once './Services/WebServices/ECS/classes/class.ilECSCommunityReader.php';
     try {
         $reader = ilECSCommunityReader::_getInstance();
     } catch (ilECSConnectorException $e) {
         $reader = null;
     }
     // read obj_ids
     $ilObjDataCache->preloadReferenceCache($rcourses);
     $obj_ids = array();
     foreach ($rcourses as $rcrs_ref_id) {
         $obj_id = $ilObjDataCache->lookupObjId($rcrs_ref_id);
         $obj_ids[$obj_id] = $obj_id;
     }
     include_once 'Services/Utilities/classes/class.ilCSVWriter.php';
     $writer = new ilCSVWriter();
     $writer->addColumn($this->lng->txt('title'));
     $writer->addColumn($this->lng->txt('description'));
     $writer->addColumn($this->lng->txt('ecs_imported_from'));
     $writer->addColumn($this->lng->txt('ecs_field_courseID'));
     $writer->addColumn($this->lng->txt('ecs_field_term'));
     $writer->addColumn($this->lng->txt('ecs_field_lecturer'));
     $writer->addColumn($this->lng->txt('ecs_field_courseType'));
     $writer->addColumn($this->lng->txt('ecs_field_semester_hours'));
     $writer->addColumn($this->lng->txt('ecs_field_credits'));
     $writer->addColumn($this->lng->txt('ecs_field_room'));
     $writer->addColumn($this->lng->txt('ecs_field_cycle'));
     $writer->addColumn($this->lng->txt('ecs_field_begin'));
     $writer->addColumn($this->lng->txt('ecs_field_end'));
     $writer->addColumn($this->lng->txt('last_update'));
     include_once './Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php';
     $settings = ilECSDataMappingSettings::_getInstance();
     foreach ($obj_ids as $obj_id) {
         include_once './Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php';
         $values = ilAdvancedMDValues::_getValuesByObjId($obj_id);
         $writer->addRow();
         $writer->addColumn(ilObject::_lookupTitle($obj_id));
         $writer->addColumn(ilObject::_lookupDescription($obj_id));
         $mid = ilObjRemoteCourse::_lookupMID($obj_id);
         if ($reader and $participant = $reader->getParticipantByMID($mid)) {
             $writer->addColumn($participant->getParticipantName());
         }
         $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS, 'courseID');
         $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
         $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS, 'term');
         $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
         $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS, 'lecturer');
         $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
         $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS, 'courseType');
         $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
         $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS, 'semester_hours');
         $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
         $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS, 'credits');
         $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
         $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS, 'room');
         $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
         $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS, 'cycle');
         $writer->addColumn(isset($values[$field]) ? $values[$field] : '');
         $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS, 'begin');
         $writer->addColumn(isset($values[$field]) ? ilFormat::formatUnixTime($values[$field], true) : '');
         $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS, 'end');
         $writer->addColumn(isset($values[$field]) ? ilFormat::formatUnixTime($values[$field], true) : '');
         $writer->addColumn($ilObjDataCache->lookupLastUpdate($obj_id));
     }
     ilUtil::deliverData($writer->getCSVString(), date("Y_m_d") . "_ecs_import.csv", "text/csv");
 }
 /**
  * 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;
     }
 }