Skip to content

Commit 6d51ec6

Browse files
Merge branch 'master' into GH-6153
2 parents cce0dda + 228bb89 commit 6d51ec6

File tree

27 files changed

+334
-304
lines changed

27 files changed

+334
-304
lines changed

assets/css/scss/atoms/_buttons.scss

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.btn {
2-
@apply cursor-default font-semibold gap-2 inline-flex justify-center px-6 py-2 rounded-md transition flex-none text-base;
2+
@apply cursor-default font-semibold gap-2 inline-flex justify-center items-center px-6 py-2 rounded-md transition flex-none text-base;
33

44
.mdi {
55
@apply text-base;
@@ -156,8 +156,9 @@
156156
}
157157
}
158158

159-
&-sm {
160-
@apply px-4 py-2;
159+
&-sm,
160+
&--sm{
161+
@apply px-3 py-1;
161162
font-size: 13px;
162163
}
163164
}

public/main/admin/configure_plugin.php

+35-50
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,39 @@
66
* @author Julio Montoya <[email protected]> BeezNest 2012
77
* @author Angel Fernando Quiroz Campos <[email protected]>
88
*/
9+
10+
use Chamilo\CoreBundle\Framework\Container;
11+
912
$cidReset = true;
1013
require_once __DIR__.'/../inc/global.inc.php';
1114

1215
api_protect_admin_script();
1316

14-
$pluginName = $_GET['name'];
15-
$appPlugin = new AppPlugin();
16-
$installedPlugins = $appPlugin->getInstalledPlugins();
17-
$pluginInfo = $appPlugin->getPluginInfo($pluginName, true);
17+
$pluginRepo = Container::getPluginRepository();
1818

19-
if (!in_array($pluginName, $installedPlugins) || empty($pluginInfo)) {
19+
$plugin = $pluginRepo->getInstalledByName($_GET['plugin']);
20+
21+
if (!$plugin) {
2022
api_not_allowed(true);
2123
}
2224

25+
$accessUrl = Container::getAccessUrlHelper()->getCurrent();
26+
27+
$pluginConfiguration = $plugin->getConfigurationsByAccessUrl($accessUrl);
28+
29+
$appPlugin = new AppPlugin();
30+
$pluginInfo = $appPlugin->getPluginInfo($plugin->getTitle(), true);
31+
32+
$em = Container::getEntityManager();
33+
2334
$content = '';
24-
$currentUrl = api_get_self()."?name=$pluginName";
35+
$currentUrl = api_get_self()."?plugin={$plugin->getTitle()}";
2536

2637
if (isset($pluginInfo['settings_form'])) {
2738
/** @var FormValidator $form */
2839
$form = $pluginInfo['settings_form'];
29-
if (isset($form)) {
30-
// We override the form attributes
31-
$attributes = ['action' => $currentUrl, 'method' => 'POST'];
32-
$form->updateAttributes($attributes);
40+
if (!empty($form)) {
41+
$form->updateAttributes(['action' => $currentUrl, 'method' => 'POST']);
3342
if (isset($pluginInfo['settings'])) {
3443
$form->setDefaults($pluginInfo['settings']);
3544
}
@@ -47,58 +56,34 @@
4756
$values = $form->getSubmitValues();
4857

4958
// Fix only for bbb
50-
if ('bbb' == $pluginName) {
51-
if (!isset($values['global_conference_allow_roles'])) {
52-
$values['global_conference_allow_roles'] = [];
53-
}
59+
if ('bbb' == $plugin->getTitle() && !isset($values['global_conference_allow_roles'])) {
60+
$values['global_conference_allow_roles'] = [];
5461
}
5562

56-
$accessUrlId = api_get_current_access_url_id();
57-
api_delete_settings_params(
58-
[
59-
'category = ? AND access_url = ? AND subkey = ? AND type = ? and variable <> ?' => [
60-
'Plugins',
61-
$accessUrlId,
62-
$pluginName,
63-
'setting',
64-
'status',
65-
],
66-
]
63+
/** @var Plugin $objPlugin */
64+
$objPlugin = $pluginInfo['obj'];
65+
66+
/** @var array<int, string> $pluginFields */
67+
$pluginFields = $objPlugin->getFieldNames();
68+
69+
$pluginConfiguration->setConfiguration(
70+
array_intersect_key($values, array_flip($pluginFields))
6771
);
6872

69-
foreach ($values as $key => $value) {
70-
api_add_setting(
71-
$value,
72-
$pluginName.'_'.$key,
73-
$pluginName,
74-
'setting',
75-
'Plugins',
76-
$pluginName,
77-
'',
78-
'',
79-
'',
80-
api_get_current_access_url_id(),
81-
1
82-
);
83-
}
73+
$em->flush();
8474

8575
Event::addEvent(
8676
LOG_PLUGIN_CHANGE,
8777
LOG_PLUGIN_SETTINGS_CHANGE,
88-
$pluginName,
78+
$plugin->getTitle(),
8979
api_get_utc_datetime(),
9080
api_get_user_id()
9181
);
9282

93-
if (!empty($pluginInfo['plugin_class'])) {
94-
/** @var \Plugin $objPlugin */
95-
$objPlugin = $pluginInfo['plugin_class']::create();
96-
$objPlugin->get_settings(true);
97-
$objPlugin->performActionsAfterConfigure();
83+
$objPlugin->performActionsAfterConfigure();
9884

99-
if (isset($values['show_main_menu_tab'])) {
100-
$objPlugin->manageTab($values['show_main_menu_tab']);
101-
}
85+
if (isset($values['show_main_menu_tab'])) {
86+
$objPlugin->manageTab($values['show_main_menu_tab']);
10287
}
10388

10489
Display::addFlash(Display::return_message(get_lang('Update successful'), 'success'));
@@ -120,6 +105,6 @@
120105
'name' => get_lang('Plugins'),
121106
];
122107

123-
$tpl = new Template($pluginName, true, true, false, true, false);
108+
$tpl = new Template($plugin->getTitle(), true, true, false, true, false);
124109
$tpl->assign('content', $content);
125110
$tpl->display_one_col_template();

public/main/admin/settings.lib.php

+16-5
Original file line numberDiff line numberDiff line change
@@ -187,21 +187,32 @@ function handlePlugins()
187187
if ($isInstalled) {
188188
$toggleAction = $isEnabled ? 'disable' : 'enable';
189189
$toggleText = $isEnabled ? get_lang('Disable') : get_lang('Enable');
190-
$toggleColor = $isEnabled ? 'btn btn--plain' : 'btn btn--warning';
190+
$toggleColor = $isEnabled ? 'btn--plain' : 'btn--warning';
191191

192192
$toggleIcon = $isEnabled ? 'mdi mdi-toggle-switch-off-outline' : 'mdi mdi-toggle-switch-outline';
193193

194-
echo '<button class="plugin-action '.$toggleColor.' px-4 py-2 rounded-md transition flex items-center gap-2"
194+
echo '<button class="plugin-action btn btn--sm '.$toggleColor.'"
195195
data-plugin="'.$pluginName.'" data-action="'.$toggleAction.'">
196196
<i class="'.$toggleIcon.'"></i> '.$toggleText.'
197197
</button>';
198198

199-
echo '<button class="plugin-action btn btn--danger"
200-
data-plugin="'.$plugin_info['title'].'" data-action="uninstall">
199+
echo '<button class="plugin-action btn btn--sm btn--danger"
200+
data-plugin="'.$pluginName.'" data-action="uninstall">
201201
<i class="mdi mdi-trash-can-outline"></i> '.get_lang('Uninstall').'
202202
</button>';
203+
204+
$configureUrl = Container::getRouter()->generate(
205+
'legacy_main',
206+
['name' => 'admin/configure_plugin.php', 'plugin' => $pluginName]
207+
);
208+
209+
echo Display::url(
210+
get_lang('Configure'),
211+
$configureUrl,
212+
['class' => 'btn btn--info btn--sm']
213+
);
203214
} else {
204-
echo '<button class="plugin-action btn btn--success"
215+
echo '<button class="plugin-action btn btn--sm btn--success"
205216
data-plugin="'.$pluginName.'" data-action="install">
206217
<i class="mdi mdi-download"></i> '.get_lang('Install').'
207218
</button>';

public/main/inc/ajax/plugin.ajax.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
case 'uninstall':
4949
case 'enable':
5050
case 'disable':
51-
$pluginTitle = api_replace_dangerous_char($_POST['plugin'] ?? '');
51+
$pluginTitle = $_POST['plugin'] ?? '';
5252
$plugin_info = [
5353
'version' => '0.0.1',
5454
'title' => $pluginTitle,

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

+23-22
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use Chamilo\CoreBundle\Entity\ResourceLink;
55
use Chamilo\CoreBundle\Entity\Tool;
6+
use Chamilo\CoreBundle\Framework\Container;
67
use Chamilo\CourseBundle\Entity\CTool;
78
use Doctrine\ORM\Exception\NotSupported;
89
use Doctrine\ORM\Exception\ORMException;
@@ -85,6 +86,8 @@ protected function __construct($version, $author, $settings = [])
8586
*/
8687
public function get_info()
8788
{
89+
$pluginRepo = Container::getPluginRepository();
90+
8891
$result = [];
8992
$result['obj'] = $this;
9093
$result['title'] = $this->get_title();
@@ -95,6 +98,7 @@ public function get_info()
9598
$result['is_course_plugin'] = $this->isCoursePlugin;
9699
$result['is_admin_plugin'] = $this->isAdminPlugin;
97100
$result['is_mail_plugin'] = $this->isMailPlugin;
101+
$result['entity'] = $pluginRepo->findOneByTitle($this->get_title());
98102

99103
if ($form = $this->getSettingsForm()) {
100104
$result['settings_form'] = $form;
@@ -337,21 +341,15 @@ public function getSettingsForm()
337341
* @param string $name of the plugin setting
338342
*
339343
* @return string Value of the plugin setting
344+
*
345+
* @throws Exception
340346
*/
341347
public function get($name)
342348
{
343349
$settings = $this->get_settings();
344350
foreach ($settings as $setting) {
345-
if ($setting['variable'] === $this->get_name().'_'.$name) {
346-
/*$unserialized = UnserializeApi::unserialize('not_allowed_classes', $setting['selected_value'], true);
347-
348-
if (!empty($setting['selected_value']) &&
349-
false !== $unserialized
350-
) {
351-
$setting['selected_value'] = $unserialized;
352-
}*/
353-
354-
return $setting['selected_value'];
351+
if (isset($setting[$name])) {
352+
return $setting[$name];
355353
}
356354
}
357355

@@ -364,21 +362,19 @@ public function get($name)
364362
* @param bool $forceFromDB Optional. Force get settings from the database
365363
*
366364
* @return array Plugin settings as an array
365+
*
366+
* @throws Exception
367367
*/
368-
public function get_settings($forceFromDB = false)
368+
public function get_settings(bool $forceFromDB = false): array
369369
{
370-
if (empty($this->settings) || $forceFromDB) {
371-
$settings = api_get_settings_params(
372-
[
373-
"subkey = ? AND category = ? AND type = ? AND access_url = ?" => [
374-
$this->get_name(),
375-
'Plugins',
376-
'setting',
377-
api_get_current_access_url_id(),
378-
],
379-
]
370+
$plugin = Container::getPluginRepository()->findOneByTitle($this->get_name());
371+
372+
if ($plugin && empty($this->settings) || $forceFromDB) {
373+
$configByUrl = $plugin->getConfigurationsByAccessUrl(
374+
Container::getAccessUrlHelper()->getCurrent()
380375
);
381-
$this->settings = $settings;
376+
377+
$this->settings = $configByUrl?->getConfiguration() ?? [];
382378
}
383379

384380
return $this->settings;
@@ -1113,4 +1109,9 @@ protected function createLinkToCourseTool(string $name, int $courseId): ?CTool
11131109

11141110
return $cTool;
11151111
}
1112+
1113+
public function getFieldNames(): array
1114+
{
1115+
return array_keys($this->fields);
1116+
}
11161117
}

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

+19-50
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
/* See license terms in /license.txt */
33

4+
use Chamilo\CoreBundle\Framework\Container;
45
use ChamiloSession as Session;
56
use Chamilo\CoreBundle\Component\Utils\ToolIcon;
67
use Symfony\Component\Finder\Finder;
@@ -123,42 +124,21 @@ public function isInstalled($plugin)
123124
return in_array($plugin, $list);
124125
}
125126

126-
/**
127-
* @deprecated
128-
*/
129-
public function get_installed_plugins($fromDatabase = true)
130-
{
131-
return $this->getInstalledPlugins($fromDatabase);
132-
}
133-
134-
/**
135-
* @param bool $fromDatabase
136-
*
137-
* @return array
138-
*/
139-
public function getInstalledPlugins($fromDatabase = true)
127+
public function getInstalledPlugins(bool $fromDatabase = true): array
140128
{
141129
static $installedPlugins = null;
142130

143-
if (false === $fromDatabase) {
144-
if (is_array($installedPlugins)) {
145-
return $installedPlugins;
146-
}
131+
if (false === $fromDatabase && is_array($installedPlugins)) {
132+
return $installedPlugins;
147133
}
148134

149135
if ($fromDatabase || null === $installedPlugins) {
150136
$installedPlugins = [];
151-
$plugins = api_get_settings_params(
152-
[
153-
'variable = ? AND selected_value = ? AND category = ? ' => ['status', 'installed', 'Plugins'],
154-
]
155-
);
156137

157-
if (!empty($plugins)) {
158-
foreach ($plugins as $row) {
159-
$installedPlugins[$row['subkey']] = true;
160-
}
161-
$installedPlugins = array_keys($installedPlugins);
138+
$plugins = Container::getPluginRepository()->getInstalledPlugins();
139+
140+
foreach ($plugins as $plugin) {
141+
$installedPlugins[] = $plugin->getTitle();
162142
}
163143
}
164144

@@ -483,32 +463,21 @@ public function getPluginInfo($pluginName, $forced = false)
483463
require $plugin_file;
484464
}
485465

486-
// @todo check if settings are already added
487-
// Extra options
488-
$plugin_settings = api_get_settings_params(
489-
[
490-
'subkey = ? AND category = ? AND type = ? AND access_url = ?' => [
491-
$pluginName,
492-
'Plugins',
493-
'setting',
494-
api_get_current_access_url_id(),
495-
],
496-
]
466+
$plugin = Container::getPluginRepository()->findOneByTitle($pluginName);
467+
468+
if (!$plugin) {
469+
return [];
470+
}
471+
472+
$configByUrl = $plugin->getConfigurationsByAccessUrl(
473+
Container::getAccessUrlHelper()->getCurrent()
497474
);
498475

499-
$settings_filtered = [];
500-
foreach ($plugin_settings as $item) {
501-
if (!empty($item['selected_value'])) {
502-
//if (unserialize($item['selected_value']) !== false) {
503-
//$item['selected_value'] = unserialize($item['selected_value']);
504-
//}
505-
}
506-
$settings_filtered[$item['variable']] = $item['selected_value'];
476+
if (!$configByUrl) {
477+
return [];
507478
}
508479

509-
$plugin_info['settings'] = $settings_filtered;
510-
$pluginData[$pluginName] = $plugin_info;
511-
//Session::write('plugin_data', $pluginData);
480+
$plugin_info['settings'] = $configByUrl->getConfiguration();
512481

513482
return $plugin_info;
514483
}

0 commit comments

Comments
 (0)