/** * constructor * * @access public * @param * */ public function __construct(ilECSSetting $set, $a_parent_obj, $a_parent_cmd, $cid) { global $lng, $ilCtrl; $this->lng = $lng; $this->ctrl = $ilCtrl; // TODO: set id $this->setId($set->getServerId() . '_' . $cid . '_' . 'community_table'); parent::__construct($a_parent_obj, $a_parent_cmd); $this->addColumn($this->lng->txt('ecs_participants'), 'participants', "35%"); $this->addColumn($this->lng->txt('ecs_participants_infos'), 'infos', "35%"); $this->addColumn($this->lng->txt('ecs_tbl_export'), 'export', '5%'); $this->addColumn($this->lng->txt('ecs_tbl_import'), 'import', '5%'); $this->addColumn($this->lng->txt('ecs_tbl_import_type'), 'type', '10%'); $this->addColumn('', 'actions', '10%'); $this->disable('form'); $this->setRowTemplate("tpl.participant_row.html", "Services/WebServices/ECS"); $this->setDefaultOrderField('participants'); $this->setDefaultOrderDirection("desc"); $this->cid = $cid; $this->server = $set; }
/** * Handle delete event * * called by ilTaskScheduler * * @param ilECSSetting $a_server * @param int $a_econtent_id * @param int $a_mid * @return boolean */ public function handleDelete(ilECSSetting $a_server, $a_econtent_id, $a_mid = 0) { global $tree, $ilLog; include_once './Services/WebServices/ECS/classes/class.ilECSImport.php'; // there is no information about the original mid anymore. // Therefor delete any remote objects with given econtent id $obj_ids = ilECSImport::_lookupObjIds($a_server->getServerId(), $a_econtent_id); $ilLog->write(__METHOD__ . ': Received obj_ids ' . print_r($obj_ids, true)); foreach ($obj_ids as $obj_id) { $references = ilObject::_getAllReferences($obj_id); foreach ($references as $ref_id) { if ($tmp_obj = ilObjectFactory::getInstanceByRefId($ref_id, false)) { $ilLog->write(__METHOD__ . ': Deleting obsolete remote course: ' . $tmp_obj->getTitle()); $tmp_obj->delete(); $tree->deleteTree($tree->getNodeData($ref_id)); } unset($tmp_obj); } } return true; }
/** * Handle export reset. * Delete exported econtent and create it again * * @return bool * @static * throws ilException, ilECSConnectorException */ public static function handleExportReset(ilECSSetting $server) { include_once './Services/WebServices/ECS/classes/class.ilECSExport.php'; // Delete all export events $queue = new ilECSEventQueueReader($server->getServerId()); $queue->deleteAllExportedEvents(); // Read all local export info $local_econtent_ids = ilECSExport::_getAllEContentIds($server->getServerId()); $types = self::getAllEContentTypes(); $list = self::getAllResourceIds($server, $types, true); // merge in one array $all_remote_ids = array(); foreach ($list as $resource_type => $remote_ids) { $all_remote_ids = array_merge($all_remote_ids, (array) $remote_ids); } $all_remote_ids = array_unique($all_remote_ids); $GLOBALS['ilLog']->write(__METHOD__ . ': Resources = ' . print_r($all_remote_ids, true)); $GLOBALS['ilLog']->write(__METHOD__ . ': Local = ' . print_r($local_econtent_ids, true)); foreach ($local_econtent_ids as $local_econtent_id => $local_obj_id) { if (!in_array($local_econtent_id, $all_remote_ids)) { // Delete this deprecated info $GLOBALS['ilLog']->write(__METHOD__ . ': Deleting deprecated econtent id ' . $local_econtent_id); ilECSExport::_deleteEContentIds($server->getServerId(), array($local_econtent_id)); } } return true; }
/** * Add advanced metadata to json (export) * * @param object $a_json * @param ilECSSetting $a_server * @param array $a_definition */ protected function addMetadataToJson(&$a_json, ilECSSetting $a_server, array $a_definition) { 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'; $mappings = ilECSDataMappingSettings::getInstanceByServerId($a_server->getServerId()); $values = ilAdvancedMDValues::_getValuesByObjId($this->content_obj->getId()); foreach ($a_definition as $id => $type) { if (is_array($type)) { $target = $type[1]; $type = $type[0]; } else { $target = $id; } if ($field = $mappings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_EXPORT, $id)) { $value = isset($values[$field]) ? $values[$field] : ''; switch ($type) { case ilECSUtils::TYPE_ARRAY: $a_json->{$target} = explode(',', $value); break; case ilECSUtils::TYPE_INT: $a_json->{$target} = (int) $value; break; case ilECSUtils::TYPE_STRING: $a_json->{$target} = (string) $value; break; case ilECSUtils::TYPE_TIMEPLACE: if (!isset($a_json->{$target})) { include_once './Services/WebServices/ECS/classes/class.ilECSTimePlace.php'; $a_json->{$target} = new ilECSTimePlace(); } $a_json->{$target}->{'set' . ucfirst($id)}($value); break; } } } }
/** * send notification about new user accounts * * @access protected */ protected static function _sendNotification(ilECSSetting $server, ilObjUser $user_obj) { if (!count($server->getUserRecipients())) { return true; } // If sub id is set => mail was send include_once './Services/WebServices/ECS/classes/class.ilECSImport.php'; $import = new ilECSImport($server->getServerId(), $user_obj->getId()); if ($import->getSubId()) { return false; } include_once './Services/Language/classes/class.ilLanguageFactory.php'; $lang = ilLanguageFactory::_getLanguage(); $lang->loadLanguageModule('ecs'); include_once './Services/Mail/classes/class.ilMail.php'; $mail = new ilMail(6); $mail->enableSoap(false); $subject = $lang->txt('ecs_new_user_subject'); // build body $body = $lang->txt('ecs_new_user_body') . "\n\n"; $body .= $lang->txt('ecs_new_user_profile') . "\n\n"; $body .= $user_obj->getProfileAsString($lang) . "\n\n"; $body .= ilMail::_getAutoGeneratedMessageString($lang); $mail->sendMail($server->getUserRecipientsAsString(), "", "", $subject, $body, array(), array("normal")); // Store sub_id = 1 in ecs import which means mail is send $import->setSubId(1); $import->save(); return true; }
/** * Handle export reset. * Delete exported econtent and create it again * * @return bool * @static * throws ilException, ilECSConnectorException */ public static function handleExportReset(ilECSSetting $server) { include_once './Services/WebServices/ECS/classes/class.ilECSExport.php'; // Delete all export events $queue = new ilECSEventQueueReader($server->getServerId()); $queue->deleteAllExportedEvents(); // Read all local export info $local_econtent_ids = ilECSExport::_getAllEContentIds($server->getServerId()); $types = self::getAllEContentTypes(); $list = self::getAllResourceIds($server, $types, true); // Delete all deprecated local export info foreach ($list as $resource_type => $remote_econtent_ids) { if ($remote_econtent_ids) { foreach ($local_econtent_ids as $econtent_id => $obj_id) { if (!in_array($econtent_id, $remote_econtent_ids)) { ilECSExport::_deleteEContentIds($server->getServerId(), array($econtent_id)); } } // Delete all with deprecated remote info foreach ($remote_econtent_ids as $econtent_id) { if (!isset($local_econtent_ids[$econtent_id])) { ilECSExport::_deleteEContentIds($server->getServerId(), array($econtent_id)); } } } } return true; }
/** * Handle update * @param ilECSSetting $server * @param type $a_content_id */ public function handleUpdate(ilECSSetting $server, $a_content_id) { // 1) Mark all nodes as deleted // 2a) Delete cms tree // 2) Add cms tree table entries // 2) Replace the cms data table entries // 3) Insert deleted tree nodes in tree // 4) Sync tree try { include_once './Services/WebServices/ECS/classes/Tree/class.ilECSDirectoryTreeConnector.php'; $dir_reader = new ilECSDirectoryTreeConnector($this->getServer()); $res = $dir_reader->getDirectoryTree($a_content_id); $nodes = $res->getResult(); } catch (ilECSConnectorException $e) { $GLOBALS['ilLog']->write(__METHOD__ . ': Tree creation failed with mesage ' . $e->getMessage()); return false; } // read old tree structure include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTree.php'; $tree = new ilECSCmsTree($a_content_id); $root_node = $tree->getNodeData(ilECSCmsTree::lookupRootId($a_content_id)); $old_nodes = array(); if ($root_node['child']) { $old_nodes = $tree->getSubTree($root_node, true); } //$GLOBALS['ilLog']->write(__METHOD__.': OLD TREE DATA ........'.print_r($old_nodes,true)); // Delete old cms tree ilECSCmsTree::deleteByTreeId($a_content_id); // Mark all nodes in cms data as deleted include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php'; ilECSCmsData::writeAllDeleted($this->getServer()->getServerId(), $this->mid, $a_content_id, true); // Check for update or new entry $cms_tree = $nodes; $data_obj_id = ilECSCmsData::lookupObjId($this->getServer()->getServerId(), $this->mid, $a_content_id, $cms_tree->rootID); $data = new ilECSCmsData($data_obj_id); $data->setServerId($server->getServerId()); $data->setMid($this->mid); $data->setCmsId($cms_tree->rootID); $data->setTreeId($a_content_id); $data->setTitle($cms_tree->directoryTreeTitle); $data->setTerm($cms_tree->term); if ($data_obj_id) { $data->setDeleted(false); $data->update(); } else { $data->save(); } $tree->insertRootNode($a_content_id, $data->getObjId()); $tree->setRootId($data->getObjId()); foreach ((array) $cms_tree->nodes as $node) { $data_obj_id = ilECSCmsData::lookupObjId($this->getServer()->getServerId(), $this->mid, $a_content_id, $node->id); // update data entry $data = new ilECSCmsData($data_obj_id); $data->setTitle($node->title); $data->setTerm($node->term); $data->setDeleted(false); if ($data_obj_id) { $data->update(); } else { $data->setCmsId($node->id); $data->setMid($this->mid); $data->setServerId($this->getServer()->getServerId()); $data->setTreeId($a_content_id); $data->setDeleted(false); $data->save(); $data_obj_id = $data->getObjId(); } // add to tree $parent_id = ilECSCmsData::lookupObjId($this->getServer()->getServerId(), $this->mid, $a_content_id, (int) $node->parent->id); $tree->insertNode($data->getObjId(), $parent_id); } // Insert deleted nodes in tree $deleted = ilECSCmsData::findDeletedNodes($this->getServer()->getServerId(), $this->mid, $a_content_id); foreach ((array) $deleted as $obj_id) { $parent = 0; foreach ((array) $old_nodes as $tmp_id => $node) { if ($node['child'] == $obj_id) { $parent = $node['parent']; break; } } if ($tree->isInTree($parent) and $parent) { $tree->insertNode($obj_id, $parent); } } // Sync tree include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTreeSynchronizer.php'; $sync = new ilECSCmsTreeSynchronizer($this->getServer(), $this->mid, $a_content_id); $sync->sync(); return true; }
/** * Handle delete event * * called by ilTaskScheduler * * @param ilECSSetting $a_server * @param int $a_econtent_id * @param int $a_mid * @return boolean */ public function handleDelete(ilECSSetting $a_server, $a_econtent_id, $a_mid = 0) { global $tree, $ilLog; include_once './Services/WebServices/ECS/classes/class.ilECSImport.php'; // if mid is zero delete all obj_ids if (!$a_mid) { $obj_ids = ilECSImport::_lookupObjIds($a_server->getServerId(), $a_econtent_id); } else { $obj_ids = (array) ilECSImport::_lookupObjId($a_server->getServerId(), $a_econtent_id, $a_mid); } $ilLog->write(__METHOD__ . ': Received obj_ids ' . print_r($obj_ids, true)); foreach ($obj_ids as $obj_id) { $references = ilObject::_getAllReferences($obj_id); foreach ($references as $ref_id) { if ($tmp_obj = ilObjectFactory::getInstanceByRefId($ref_id, false)) { $ilLog->write(__METHOD__ . ': Deleting obsolete remote course: ' . $tmp_obj->getTitle()); $tmp_obj->delete(); $tree->deleteTree($tree->getNodeData($ref_id)); } unset($tmp_obj); } } return true; }