Skip to content

Commit ea4458d

Browse files
Merge pull request #6270 from christianbeeznest/rna-22587
Plugin: Fix 500 error on course homepage and config form for Positioning tool - refs BT#22587
2 parents 1477918 + 3386130 commit ea4458d

File tree

4 files changed

+51
-58
lines changed

4 files changed

+51
-58
lines changed

public/main/inc/lib/plugin.class.php

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -908,41 +908,24 @@ public function renderRegion($region)
908908
*
909909
* @return bool True if plugin is installed/enabled, false otherwise
910910
*/
911-
public function isEnabled($checkEnabled = false)
911+
public function isEnabled(bool $checkEnabled = false): bool
912912
{
913-
$settings = api_get_settings_params_simple(
914-
[
915-
"subkey = ? AND category = ? AND type = ? AND variable = 'status' " => [
916-
$this->get_name(),
917-
'Plugins',
918-
'setting',
919-
],
920-
]
921-
);
922-
if (is_array($settings) && isset($settings['selected_value']) && 'installed' == $settings['selected_value']) {
923-
// The plugin is installed
924-
// If we need a check on whether it is enabled, also check for
925-
// *plugin*_tool_enable and make sure it is *NOT* false
926-
if ($checkEnabled) {
927-
$enabled = api_get_settings_params_simple(
928-
[
929-
"variable = ? AND subkey = ? AND category = 'Plugins' " => [
930-
$this->get_name().'_tool_enable',
931-
$this->get_name(),
932-
],
933-
]
934-
);
935-
if (is_array($enabled) && isset($enabled['selected_value']) && 'false' == $enabled['selected_value']) {
936-
// Only return false if the setting exists and it is
937-
// *specifically* set to false
938-
return false;
939-
}
940-
}
913+
$settings = $this->get_settings();
941914

942-
return true;
915+
if (empty($settings)) {
916+
return false;
943917
}
944918

945-
return false;
919+
if ($checkEnabled) {
920+
if (
921+
isset($settings['tool_enable']) &&
922+
strtolower($settings['tool_enable']) === 'false'
923+
) {
924+
return false;
925+
}
926+
}
927+
928+
return true;
946929
}
947930

948931
/**

public/main/inc/lib/plugin.lib.php

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -451,32 +451,41 @@ public function getAllPluginContentsByRegion($plugin_name, $region, $template, $
451451
*/
452452
public function getPluginInfo($pluginName, $forced = false)
453453
{
454-
//$pluginData = Session::read('plugin_data');
455-
if (0) {
456-
//if (isset($pluginData[$pluginName]) && $forced == false) {
457-
return $pluginData[$pluginName];
458-
} else {
459-
$plugin_file = api_get_path(SYS_PLUGIN_PATH)."$pluginName/plugin.php";
460-
461-
$plugin_info = [];
462-
if (file_exists($plugin_file)) {
463-
require $plugin_file;
464-
}
454+
$plugin_info = [];
455+
$pluginPath = api_get_path(SYS_PLUGIN_PATH);
456+
$pluginDirs = [
457+
$pluginName,
458+
strtolower($pluginName),
459+
ucfirst(strtolower($pluginName)),
460+
];
465461

466-
$plugin = Container::getPluginRepository()->findOneByTitle($pluginName);
462+
$plugin_file = null;
467463

468-
if (!$plugin) {
469-
return [];
464+
foreach ($pluginDirs as $dir) {
465+
$path = $pluginPath . "$dir/plugin.php";
466+
if (file_exists($path)) {
467+
$plugin_file = $path;
468+
break;
470469
}
470+
}
471471

472-
$configByUrl = $plugin->getConfigurationsByAccessUrl(
473-
Container::getAccessUrlHelper()->getCurrent()
474-
);
472+
if ($plugin_file) {
473+
require $plugin_file;
474+
}
475475

476-
$plugin_info['settings'] = $configByUrl?->getConfiguration() ?? [];
476+
$plugin = Container::getPluginRepository()->findOneByTitle($pluginName);
477477

478-
return $plugin_info;
478+
if (!$plugin) {
479+
return [];
479480
}
481+
482+
$configByUrl = $plugin->getConfigurationsByAccessUrl(
483+
Container::getAccessUrlHelper()->getCurrent()
484+
);
485+
486+
$plugin_info['settings'] = $configByUrl?->getConfiguration() ?? [];
487+
488+
return $plugin_info;
480489
}
481490

482491
/**

public/plugin/Positioning/start.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
/* For license terms, see /license.txt */
44

5+
use Chamilo\CoreBundle\Component\Utils\ObjectIcon;
6+
57
require_once __DIR__.'/../../main/inc/global.inc.php';
68

79
api_protect_course_script(true);
@@ -72,7 +74,7 @@
7274
return $actions;
7375
};
7476

75-
$table = Exercise::exerciseGrid(
77+
$table = Exercise::exerciseGridResource(
7678
0,
7779
null,
7880
null,
@@ -142,7 +144,7 @@
142144

143145
$template->assign(
144146
'positioning_introduction',
145-
Display::return_message($plugin->get_lang('PositioningIntroduction'))
147+
Display::return_message($plugin->get_lang('PositioningIntroduction'), false)
146148
);
147149
$template->assign('table', $exercisesToString);
148150
$template->assign('radars', $radars);
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1+
{{ positioning_introduction|raw }}
12

2-
{{ positioning_introduction }}
3-
4-
{{ table }}
3+
{{ table|raw }}
54

65
{% if radars %}
7-
{{ radars }}
8-
<br>
9-
{{ "ChartShowsAverageForAllStudentsUsingZeroForIncompleteTests"| get_plugin_lang('Positioning') }}
6+
{{ radars|raw }}
7+
<br>
8+
{{ "ChartShowsAverageForAllStudentsUsingZeroForIncompleteTests"|get_plugin_lang('Positioning') }}
109
{% endif %}

0 commit comments

Comments
 (0)