Restore loading of plugins in regions for v2

pull/2715/head
Julio Montoya 8 years ago
parent 5243c2d9f2
commit fa8cb2345f
  1. 22
      config/packages/twig.yaml
  2. 12
      main/inc/global.inc.php
  3. 29
      main/inc/lib/api.lib.php
  4. 62
      main/inc/lib/plugin.lib.php
  5. 199
      main/inc/lib/template.lib.php
  6. 7
      src/CoreBundle/EventListener/LegacyListener.php
  7. 132
      src/CoreBundle/EventListener/PluginListener.php
  8. 22
      src/CoreBundle/Menu/NavBuilder.php
  9. 14
      src/CoreBundle/Resources/config/services.yml
  10. 1
      src/CoreBundle/Twig/Extension/ChamiloExtension.php
  11. 60
      src/ThemeBundle/EventListener/TwigListener.php

@ -1,6 +1,6 @@
twig:
debug: '%kernel.debug%'
paths: ['%kernel.project_dir%/templates', '%kernel.project_dir%/main/template/']
paths: ['%kernel.project_dir%/templates', '%kernel.project_dir%/main/template/', '%kernel.project_dir%/plugin/']
form_themes:
- 'bootstrap_4_layout.html.twig'
- '@SonataFormatter/Form/formatter.html.twig'
@ -22,24 +22,4 @@ twig:
header:
message:
show_media_element: 1
plugin_content_bottom:
plugin_content_top:
plugin_main_bottom:
plugin_course_tool_plugin:
plugin_footer_center:
plugin_footer_left:
plugin_footer_right:
plugin_header_center:
plugin_header_left:
plugin_header_right:
plugin_header_main:
plugin_login_bottom:
plugin_login_top:
plugin_login_left:
plugin_login_right:
plugin_main_top:
plugin_menu_administrator:
plugin_menu_bottom:
plugin_menu_top:
plugin_pre_footer:
footer_extra_content:

@ -176,7 +176,7 @@ try {
\Patchwork\Utf8\Bootup::initAll();
// access_url == 1 is the default chamilo location
if ($_configuration['access_url'] != 1) {
/*if ($_configuration['access_url'] != 1) {
$url_info = api_get_access_url($_configuration['access_url']);
if ($url_info['active'] == 1) {
$settings_by_access = &api_get_settings(null, 'list', $_configuration['access_url'], 1);
@ -193,9 +193,9 @@ try {
$settings_by_access_list[$row['variable']][$row['subkey']][$row['category']] = $row;
}
}
}
}*/
$result = &api_get_settings(null, 'list', 1);
/*$result = &api_get_settings(null, 'list', 1);
foreach ($result as &$row) {
if ($_configuration['access_url'] != 1) {
if ($url_info['active'] == 1) {
@ -234,9 +234,9 @@ try {
$_setting[$row['variable']][$row['subkey']] = $row['selected_value'];
}
}
}
}*/
$result = &api_get_settings('Plugins', 'list', $_configuration['access_url']);
/*$result = &api_get_settings('Plugins', 'list', $_configuration['access_url']);
$_plugins = [];
foreach ($result as &$row) {
$key = &$row['variable'];
@ -250,7 +250,7 @@ try {
$_setting[$key][$row['subkey']] = $row['selected_value'];
$_plugins[$key][$row['subkey']] = $row['selected_value'];
}
}
}*/
// Error reporting settings.
if (api_get_setting('server_type') === 'test') {

@ -838,8 +838,7 @@ function api_get_path($path = '', $configuration = [])
}
$isInitialized = [];
$course_folder = isset($configuration['course_folder']) ? $configuration['course_folder'] : $course_folder;
$root_rel = isset($configuration['url_append']) ? $configuration['url_append'] : '';
$root_rel = $configuration['url_append'] ?? '';
// Web server base and system server base.
if (!array_key_exists($root_web, $isInitialized)) {
@ -856,7 +855,7 @@ function api_get_path($path = '', $configuration = [])
// upgraded to return correct results in this case.
// Dealing with trailing slashes.
$slashed_root_web = api_add_trailing_slash($root_web);
$rootWebWithSlash = api_add_trailing_slash($root_web);
$root_sys = api_add_trailing_slash($root_sys);
$root_rel = api_add_trailing_slash($root_rel);
$code_folder = api_add_trailing_slash($code_folder);
@ -868,25 +867,25 @@ function api_get_path($path = '', $configuration = [])
$paths[$root_web][REL_CODE_PATH] = $root_rel.$code_folder;
$paths[$root_web][REL_DEFAULT_COURSE_DOCUMENT_PATH] = $paths[$root_web][REL_PATH].'main/default_course_document/';
$paths[$root_web][WEB_PATH] = $slashed_root_web;
$paths[$root_web][WEB_CODE_PATH] = $paths[$root_web][WEB_PATH].$code_folder;
$paths[$root_web][WEB_COURSE_PATH] = $paths[$root_web][WEB_PATH].$course_folder;
$paths[$root_web][WEB_DEFAULT_COURSE_DOCUMENT_PATH] = $paths[$root_web][WEB_CODE_PATH].'default_course_document/';
$paths[$root_web][WEB_APP_PATH] = $paths[$root_web][WEB_PATH].$paths[$root_web][WEB_APP_PATH];
$paths[$root_web][WEB_PLUGIN_PATH] = $paths[$root_web][WEB_PATH].$paths[$root_web][WEB_PLUGIN_PATH];
$paths[$root_web][WEB_PLUGIN_ASSET_PATH] = $paths[$root_web][WEB_PATH].$paths[$root_web][WEB_PLUGIN_ASSET_PATH];
$paths[$root_web][WEB_ARCHIVE_PATH] = $paths[$root_web][WEB_PATH].$paths[$root_web][WEB_ARCHIVE_PATH];
$paths[$root_web][WEB_PATH] = $rootWebWithSlash;
$paths[$root_web][WEB_CODE_PATH] = $rootWebWithSlash.$code_folder;
$paths[$root_web][WEB_COURSE_PATH] = $rootWebWithSlash.$course_folder;
$paths[$root_web][WEB_APP_PATH] = $rootWebWithSlash.$paths[$root_web][WEB_APP_PATH];
$paths[$root_web][WEB_PLUGIN_PATH] = $rootWebWithSlash.$paths[$root_web][WEB_PLUGIN_PATH];
$paths[$root_web][WEB_PLUGIN_ASSET_PATH] = $rootWebWithSlash.$paths[$root_web][WEB_PLUGIN_ASSET_PATH];
$paths[$root_web][WEB_ARCHIVE_PATH] = $rootWebWithSlash.$paths[$root_web][WEB_ARCHIVE_PATH];
$paths[$root_web][WEB_CSS_PATH] = $rootWebWithSlash.$paths[$root_web][WEB_CSS_PATH];
$paths[$root_web][WEB_UPLOAD_PATH] = $rootWebWithSlash.$paths[$root_web][WEB_UPLOAD_PATH];
$paths[$root_web][WEB_PUBLIC_PATH] = $rootWebWithSlash.$paths[$root_web][WEB_PUBLIC_PATH];
$paths[$root_web][WEB_HOME_PATH] = $rootWebWithSlash.$paths[$root_web][REL_HOME_PATH];
$paths[$root_web][WEB_CSS_PATH] = $paths[$root_web][WEB_PATH].$paths[$root_web][WEB_CSS_PATH];
$paths[$root_web][WEB_DEFAULT_COURSE_DOCUMENT_PATH] = $paths[$root_web][WEB_CODE_PATH].'default_course_document/';
$paths[$root_web][WEB_IMG_PATH] = $paths[$root_web][WEB_CODE_PATH].$paths[$root_web][WEB_IMG_PATH];
$paths[$root_web][WEB_LIBRARY_PATH] = $paths[$root_web][WEB_CODE_PATH].$paths[$root_web][WEB_LIBRARY_PATH];
$paths[$root_web][WEB_LIBRARY_JS_PATH] = $paths[$root_web][WEB_CODE_PATH].$paths[$root_web][WEB_LIBRARY_JS_PATH];
$paths[$root_web][WEB_AJAX_PATH] = $paths[$root_web][WEB_CODE_PATH].$paths[$root_web][WEB_AJAX_PATH];
$paths[$root_web][WEB_FONTS_PATH] = $paths[$root_web][WEB_CODE_PATH].$paths[$root_web][WEB_FONTS_PATH];
$paths[$root_web][WEB_TEMPLATE_PATH] = $paths[$root_web][WEB_CODE_PATH].$paths[$root_web][WEB_TEMPLATE_PATH];
$paths[$root_web][WEB_UPLOAD_PATH] = $paths[$root_web][WEB_PATH].$paths[$root_web][WEB_UPLOAD_PATH];
$paths[$root_web][WEB_PUBLIC_PATH] = $paths[$root_web][WEB_PATH].$paths[$root_web][WEB_PUBLIC_PATH];
$paths[$root_web][WEB_HOME_PATH] = $paths[$root_web][WEB_PATH].$paths[$root_web][REL_HOME_PATH];
$paths[$root_web][SYS_PATH] = $root_sys;
$paths[$root_web][SYS_CODE_PATH] = $root_sys.$code_folder;

@ -260,14 +260,14 @@ class AppPlugin
*
* @return null|string
*/
public function load_region($region, $template, $forced = false)
public function loadRegion($pluginRegionList, $region, $template, $forced = false)
{
if ($region == 'course_tool_plugin') {
if ($region === 'course_tool_plugin') {
return '';
}
ob_start();
$this->get_all_plugin_contents_by_region($region, $template, $forced);
$this->get_all_plugin_contents_by_region($pluginRegionList, $region, $template, $forced);
$content = ob_get_contents();
ob_end_clean();
@ -284,13 +284,12 @@ class AppPlugin
*/
public function load_plugin_lang_variables($plugin_name)
{
global $language_interface;
$language_interface = api_get_interface_language();
$root = api_get_path(SYS_PLUGIN_PATH);
$strings = null;
// 1. Loading english if exists
$english_path = $root.$plugin_name."/lang/english.php";
$english_path = $root.$plugin_name.'/lang/english.php';
if (is_readable($english_path)) {
include $english_path;
@ -302,7 +301,6 @@ class AppPlugin
// 2. Loading the system language
if ($language_interface != 'english') {
$path = $root.$plugin_name."/lang/$language_interface.php";
if (is_readable($path)) {
include $path;
if (!empty($strings)) {
@ -311,7 +309,7 @@ class AppPlugin
}
}
} else {
$interfaceLanguageId = api_get_language_id($language_interface);
/*$interfaceLanguageId = api_get_language_id($language_interface);
$interfaceLanguageInfo = api_get_language_info($interfaceLanguageId);
$languageParentId = intval($interfaceLanguageInfo['parent_id']);
@ -328,7 +326,7 @@ class AppPlugin
}
}
}
}
}*/
}
}
}
@ -342,15 +340,15 @@ class AppPlugin
*
* @todo improve this function
*/
public function get_all_plugin_contents_by_region($region, $template, $forced = false)
public function get_all_plugin_contents_by_region($_plugins, $region, $template, $forced = false)
{
global $_plugins;
if (isset($_plugins[$region]) && is_array($_plugins[$region])) {
// Load the plugin information
foreach ($_plugins[$region] as $plugin_name) {
// The plugin_info variable is available inside the plugin index
$plugin_info = $this->getPluginInfo($plugin_name, $forced);
// We also know where the plugin is
$plugin_info['current_region'] = $region;
@ -373,7 +371,7 @@ class AppPlugin
}
// Setting the plugin info available in the template if exists.
$template->assign($plugin_name, $_template);
$template->addGlobal($plugin_name, $_template);
// Loading the Twig template plugin files if exists
$template_list = [];
@ -698,4 +696,44 @@ class AppPlugin
return false;
}
public function setPluginRegion($pluginRegionList, $pluginRegion, $twig)
{
if (!empty($pluginRegion)) {
$regionContent = $this->loadRegion(
$pluginRegionList,
$pluginRegion,
$twig,
true //$this->force_plugin_load
);
$pluginList = $this->get_installed_plugins();
foreach ($pluginList as $plugin_name) {
// The plugin_info variable is available inside the plugin index
$pluginInfo = $this->getPluginInfo($plugin_name);
if (isset($pluginInfo['is_course_plugin']) && $pluginInfo['is_course_plugin']) {
$courseInfo = api_get_course_info();
if (!empty($courseInfo)) {
if (isset($pluginInfo['obj']) && $pluginInfo['obj'] instanceof Plugin) {
/** @var Plugin $plugin */
$plugin = $pluginInfo['obj'];
$regionContent .= $plugin->renderRegion($pluginRegion);
}
}
} else {
continue;
}
}
if (!empty($regionContent)) {
$twig->addGlobal('plugin_'.$pluginRegion, $regionContent);
} else {
$twig->addGlobal('plugin_'.$pluginRegion, null);
}
}
return null;
}
}

@ -75,7 +75,7 @@ class Template
// Page title
$this->title = $title;
$this->show_learnpath = $show_learnpath;
$this->setResponseCode($responseCode);
//$this->setResponseCode($responseCode);
if (empty($this->show_learnpath)) {
$origin = api_get_origin();
@ -88,172 +88,39 @@ class Template
$this->hide_global_chat = $hide_global_chat;
$this->load_plugins = $load_plugins;
$template_paths = [
/*$template_paths = [
api_get_path(SYS_CODE_PATH).'template/overrides', // user defined templates
api_get_path(SYS_CODE_PATH).'template', //template folder
api_get_path(SYS_PLUGIN_PATH), // plugin folder
api_get_path(SYS_PATH).'src/ThemeBundle/Resources/views',
];
$urlId = api_get_current_access_url_id();
$cache_folder = api_get_path(SYS_ARCHIVE_PATH).'twig/'.$urlId.'/';
if (!is_dir($cache_folder)) {
//mkdir($cache_folder, api_get_permissions_for_new_directories(), true);
}
$loader = new Twig_Loader_Filesystem($template_paths);
];*/
$isTestMode = api_get_setting('server_type') === 'test';
//Setting Twig options depending on the server see http://twig.sensiolabs.org/doc/api.html#environment-options
if ($isTestMode) {
$options = [
//'cache' => api_get_path(SYS_ARCHIVE_PATH), //path to the cache folder
'autoescape' => false,
'debug' => true,
'auto_reload' => true,
'optimizations' => 0,
// turn on optimizations with -1
'strict_variables' => false,
//If set to false, Twig will silently ignore invalid variables
];
} else {
$options = [
'cache' => $cache_folder,
//path to the cache folder
'autoescape' => false,
'debug' => false,
'auto_reload' => false,
'optimizations' => -1,
// turn on optimizations with -1
'strict_variables' => false,
//If set to false, Twig will silently ignore invalid variables
];
}
//$this->twig = new Twig_Environment($loader, $options);
$this->twig = Container::getTwig();
if ($isTestMode) {
//$this->twig->addExtension(new Twig_Extension_Debug());
}
// Twig filters setup
$filters = [
'get_plugin_lang',
'get_lang',
'api_get_path',
'api_get_local_time',
'api_convert_and_format_date',
'api_is_allowed_to_edit',
'api_get_user_info',
'api_get_configuration_value',
'api_get_setting',
[
'name' => 'return_message',
'callable' => 'Display::return_message_and_translate',
],
[
'name' => 'display_page_header',
'callable' => 'Display::page_header_and_translate',
],
[
'name' => 'display_page_subheader',
'callable' => 'Display::page_subheader_and_translate',
],
[
'name' => 'icon',
'callable' => 'Template::get_icon_path',
],
[
'name' => 'img',
'callable' => 'Template::get_image',
],
[
'name' => 'format_date',
'callable' => 'Template::format_date',
],
[
'name' => 'get_template',
'callable' => 'Template::findTemplateFilePath',
],
[
'name' => 'date_to_time_ago',
'callable' => 'Display::dateToStringAgoAndLongDate',
],
];
foreach ($filters as $filter) {
if (is_array($filter)) {
//$this->twig->addFilter(new Twig_SimpleFilter($filter['name'], $filter['callable']));
} else {
//$this->twig->addFilter(new Twig_SimpleFilter($filter, $filter));
}
}
/*$this->twig->addFunction(
new TwigFunction('sonata_page_render_container', [$this, 'renderContainer'], ['is_safe' => ['html']])
);*/
$functions = [
['name' => 'get_tutors_names', 'callable' => 'Template::returnTutorsNames'],
['name' => 'get_teachers_names', 'callable' => 'Template::returnTeachersNames'],
];
foreach ($functions as $function) {
//$this->twig->addFunction(new Twig_SimpleFunction($function['name'], $function['callable']));
}
// Setting system variables
$this->set_system_parameters();
//$this->set_system_parameters();
// Setting user variables
$this->set_user_parameters();
//$this->set_user_parameters();
// Setting course variables
$this->set_course_parameters();
//$this->set_course_parameters();
// Setting administrator variables
//$this->setAdministratorParams();
//$this->setCSSEditor();
// Header and footer are showed by default
$this->set_footer($show_footer);
$this->set_header($show_header);
//$this->set_footer($show_footer);
//$this->set_header($show_header);
$this->set_header_parameters($sendHeaders);
$this->set_footer_parameters();
//$this->set_header_parameters($sendHeaders);
//$this->set_footer_parameters();
$defaultStyle = api_get_configuration_value('default_template');
if (!empty($defaultStyle)) {
$this->templateFolder = $defaultStyle;
}
$this->assign('template', $this->templateFolder);
$this->assign('locale', api_get_language_isocode());
$this->assign('login_class', null);
// Chamilo plugins
if ($this->show_header) {
if ($this->load_plugins) {
$this->plugin = new AppPlugin();
//1. Showing installed plugins in regions
$pluginRegions = $this->plugin->get_plugin_regions();
foreach ($pluginRegions as $region) {
$this->set_plugin_region($region);
}
//2. Loading the course plugin info
global $course_plugin;
if (isset($course_plugin) && !empty($course_plugin) && !empty($this->course_id)) {
//Load plugin get_langs
$this->plugin->load_plugin_lang_variables($course_plugin);
}
}
}
}
/**
@ -1028,48 +895,6 @@ class Template
$this->display($tpl);
}
/**
* Sets the plugin content in a template variable.
*
* @param string $pluginRegion
*/
public function set_plugin_region($pluginRegion)
{
if (!empty($pluginRegion)) {
$regionContent = $this->plugin->load_region(
$pluginRegion,
$this,
$this->force_plugin_load
);
$pluginList = $this->plugin->get_installed_plugins();
foreach ($pluginList as $plugin_name) {
// The plugin_info variable is available inside the plugin index
$pluginInfo = $this->plugin->getPluginInfo($plugin_name);
if (isset($pluginInfo['is_course_plugin']) && $pluginInfo['is_course_plugin']) {
$courseInfo = api_get_course_info();
if (!empty($courseInfo)) {
if (isset($pluginInfo['obj']) && $pluginInfo['obj'] instanceof Plugin) {
/** @var Plugin $plugin */
$plugin = $pluginInfo['obj'];
$regionContent .= $plugin->renderRegion($pluginRegion);
}
}
} else {
continue;
}
}
if (!empty($regionContent)) {
$this->assign('plugin_'.$pluginRegion, $regionContent);
} else {
$this->assign('plugin_'.$pluginRegion, null);
}
}
return null;
}
/**
* @param string $template
@ -1613,8 +1438,8 @@ class Template
$this->assign('portal_name', $portal_name);
//Menu
$menu = menuArray();
$this->assign('menu', $menu);
//$menu = menuArray();
//$this->assign('menu', $menu);
$breadcrumb = '';
// Hide breadcrumb in LP

@ -136,13 +136,6 @@ class LegacyListener
// Theme icon is loaded in the TwigListener src/ThemeBundle/EventListener/TwigListener.php
//$theme = api_get_visual_theme();
//$twig->addGlobal('favico', \Template::getPortalIcon($theme));
$extraFooter = trim(api_get_setting('footer_extra_content'));
$twig->addGlobal('footer_extra_content', $extraFooter);
$extraHeader = trim(api_get_setting('header_extra_content'));
$twig->addGlobal('header_extra_content', $extraHeader);
$languages = api_get_languages();
$languageList = [];
foreach ($languages as $isoCode => $language) {

@ -1,132 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\EventListener;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
/**
* Class PluginListener.
*
* @package Chamilo\CoreBundle\EventListener
*/
class PluginListener
{
use ContainerAwareTrait;
/**
* @param GetResponseEvent $event
*/
public function onKernelRequest(GetResponseEvent $event)
{
}
/**
* @param FilterResponseEvent $event
*/
public function onKernelResponse(FilterResponseEvent $event)
{
}
/**
* @param FilterControllerEvent $event
*/
public function onKernelController(FilterControllerEvent $event)
{
$request = $event->getRequest();
$controller = $request->get('_controller');
// Only process legacy listener when loading legacy controller
/*if ($controller != 'Chamilo\CoreBundle\Controller\LegacyController::classicAction') {
return;
}*/
$skipControllers = [
'web_profiler.controller.profiler:toolbarAction',
'fos_js_routing.controller:indexAction',
];
// Skip legacy listener
if (in_array($controller, $skipControllers)) {
return;
}
// Legacy way of detect current access_url
$request = $event->getRequest();
if (!$request->hasPreviousSession()) {
return;
}
$controller = $request->get('_controller');
// Only process legacy listener when loading legacy controller
/*if ($controller != 'Chamilo\CoreBundle\Controller\LegacyController::classicAction') {
return;
}*/
$skipControllers = [
'web_profiler.controller.profiler:searchBarAction',
'FOS\RestBundle\Controller\ExceptionController::showAction',
'web_profiler.controller.profiler:panelAction',
'web_profiler.controller.profiler:toolbarAction', // debug toolbar
'fos_js_routing.controller:indexAction', // js/routing?callback=fos.Router.setData
];
// Skip legacy listener
if (in_array($controller, $skipControllers)) {
return;
}
/** @var ContainerInterface $container */
$container = $this->container;
$installed = $this->container->getParameter('installed');
if (!empty($installed)) {
return;
//$result = & api_get_settings('Plugins', 'list', $_configuration['access_url']);
$result = &api_get_settings('Plugins', 'list', 1);
$_plugins = [];
foreach ($result as &$row) {
$key = $row['variable'];
$_plugins[$key][] = $row['selected_value'];
}
// Loading Chamilo plugins
$appPlugin = new \AppPlugin();
$pluginRegions = $appPlugin->get_plugin_regions();
$force_plugin_load = true;
$pluginList = $appPlugin->get_installed_plugins();
$courseId = $request->getSession()->get('_real_cid');
foreach ($pluginRegions as $pluginRegion) {
$regionContent = $appPlugin->load_region(
$pluginRegion,
$container->get('twig'),
$_plugins,
$force_plugin_load
);
foreach ($pluginList as $pluginName) {
// The plugin_info variable is available inside the plugin index
$pluginInfo = $appPlugin->getPluginInfo($pluginName);
if (isset($pluginInfo['is_course_plugin']) && $pluginInfo['is_course_plugin']) {
if (!empty($courseId)) {
if (isset($pluginInfo['obj']) && $pluginInfo['obj'] instanceof \Plugin) {
/** @var \Plugin $plugin */
$plugin = $pluginInfo['obj'];
$regionContent .= $plugin->renderRegion($pluginRegion);
}
}
} else {
continue;
}
}
$container->get('twig')->addGlobal('plugin_'.$pluginRegion, $regionContent);
}
}
}
}

@ -66,6 +66,8 @@ class NavBuilder implements ContainerAwareInterface
$menu = $factory->createItem('root');
$menu->setChildrenAttribute('class', 'navbar-nav');
$settingsManager = $container->get('chamilo.settings.manager');
$menu->addChild(
$translator->trans('Home'),
[
@ -104,15 +106,17 @@ class NavBuilder implements ContainerAwareInterface
]
);
$menu->addChild(
$translator->trans('Social'),
[
'route' => 'legacy_main',
'routeParameters' => [
'name' => 'social/home.php',
],
]
);
if ('true' === $settingsManager->getSetting('social.allow_social_tool')) {
$menu->addChild(
$translator->trans('Social'),
[
'route' => 'legacy_main',
'routeParameters' => [
'name' => 'social/home.php',
],
]
);
}
if ($checker->isGranted('ROLE_ADMIN')) {
$menu->addChild(

@ -138,13 +138,13 @@ services:
- {name: kernel.event_listener, event: kernel.controller, method: onKernelController}
# Setting user and platform locale
chamilo_core.listener.plugin:
class: Chamilo\CoreBundle\EventListener\PluginListener
calls:
- [setContainer, ['@service_container']]
tags:
- {name: kernel.event_listener, event: kernel.request, method: onKernelRequest}
- {name: kernel.event_listener, event: kernel.controller, method: onKernelController, priority: 4}
# chamilo_core.listener.plugin:
# class: Chamilo\CoreBundle\EventListener\PluginListener
# calls:
# - [setContainer, ['@service_container']]
# tags:
# - {name: kernel.event_listener, event: kernel.request, method: onKernelRequest}
# - {name: kernel.event_listener, event: kernel.controller, method: onKernelController, priority: 4}
# deprecated use
# chamilo_core.listener.legacy_login_listener:

@ -23,7 +23,6 @@ class ChamiloExtension extends \Twig_Extension
new \Twig_SimpleFilter('icon', 'Template::get_icon_path'),
new \Twig_SimpleFilter('img', 'Template::get_image'),
new \Twig_SimpleFilter('api_get_local_time', 'api_get_local_time'),
new \Twig_SimpleFilter('api_is_allowed_to_edit', 'api_is_allowed_to_edit'),
new \Twig_SimpleFilter('format_date', 'Template::format_date'),
new \Twig_SimpleFilter('date_to_time_ago', 'Display::dateToStringAgoAndLongDate'),
new \Twig_SimpleFilter('api_get_configuration_value', 'api_get_configuration_value'),

@ -43,13 +43,18 @@ class TwigListener implements EventSubscriberInterface
Container::setContainer($container);
Container::setLegacyServices($container);
$settingsManager = $container->get('chamilo.settings.manager');
$theme = api_get_visual_theme();
$twig = $container->get('twig');
$twig->addGlobal('favico', \Template::getPortalIcon($theme));
if (api_get_setting('show_administrator_data') === 'true') {
$firstName = api_get_setting('administratorName');
$lastName = api_get_setting('administratorSurname');
if ($settingsManager->getSetting('display.show_administrator_data') === 'true') {
$firstName = $settingsManager->getSetting('admin.administrator_name');
$lastName = $settingsManager->getSetting('admin.administrator_surname');
$email = $settingsManager->getSetting('admin.administrator_email');
$phone = $settingsManager->getSetting('admin.administrator_phone');
if (!empty($firstName) && !empty($lastName)) {
$name = api_get_person_name($firstName, $lastName);
} else {
@ -63,28 +68,34 @@ class TwigListener implements EventSubscriberInterface
// Administrator name
if (!empty($name)) {
$adminName = get_lang('Manager').' : ';
$adminName .= \Display::encrypted_mailto_link(api_get_setting('emailAdministrator'), $name);
$adminName .= \Display::encrypted_mailto_link($email, $name);
}
$twig->addGlobal('administrator_name', $adminName);
$admin = [
'email' => $email,
'surname' => $lastName,
'name' => $firstName,
'telephone' => $phone,
];
$twig->addGlobal('_admin', $admin);
}
$admin = [
'email' => api_get_setting('emailAdministrator'),
'surname' => api_get_setting('administratorSurname'),
'name' => api_get_setting('administratorName'),
'telephone' => api_get_setting('administratorTelephone'),
];
$extraFooter = trim($settingsManager->getSetting('tracking.footer_extra_content'));
$twig->addGlobal('footer_extra_content', $extraFooter);
$twig->addGlobal('_admin', $admin);
$extraHeader = trim($settingsManager->getSetting('tracking.header_extra_content'));
$twig->addGlobal('header_extra_content', $extraHeader);
if (api_get_setting('show_tutor_data') === 'true') {
if ($settingsManager->getSetting('display.show_tutor_data') === 'true') {
// Course manager
$courseId = api_get_course_int_id();
$sessionId = api_get_session_id();
if (!empty($courseId)) {
$tutorData = '';
if ($sessionId != 0) {
if ($sessionId !== 0) {
$coachEmail = \CourseManager::get_email_of_tutor_to_session(
$sessionId,
$courseId
@ -125,6 +136,29 @@ class TwigListener implements EventSubscriberInterface
$twig->addGlobal('teachers', $teacherData);
}
}
// Plugins - Region list
$pluginConfiguration = api_get_settings('Plugins', 'list', 1);
$pluginRegionList = [];
foreach ($pluginConfiguration as $plugin) {
if ($plugin['type'] === 'region') {
$pluginRegionList[$plugin['variable']][] = $plugin['subkey'];
}
}
$appPlugin = new \AppPlugin();
// 1. Showing installed plugins in regions
$pluginRegions = $appPlugin->get_plugin_regions();
foreach ($pluginRegions as $region) {
$appPlugin->setPluginRegion($pluginRegionList, $region, $twig);
}
//2. Loading the course plugin info
global $course_plugin;
if (isset($course_plugin) && !empty($course_plugin) && !empty($this->course_id)) {
//Load plugin get_langs
// $this->plugin->load_plugin_lang_variables($course_plugin);
}
}
/**

Loading…
Cancel
Save