Skip to content

Commit c3c4a28

Browse files
committed
Move CmdManager method to WidgetManager
1 parent e3de6ba commit c3c4a28

File tree

5 files changed

+87
-83
lines changed

5 files changed

+87
-83
lines changed

core/class/cmd.class.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
use NextDom\Managers\CmdManager;
20+
use NextDom\Managers\WidgetManager;
2021

2122
/* * ***************************Includes********************************* */
2223
require_once __DIR__ . '/../../core/php/core.inc.php';
@@ -131,7 +132,7 @@ public static function convertColor($_color) {
131132
}
132133

133134
public static function availableWidget($_version) {
134-
return CmdManager::availableWidget($_version);
135+
return WidgetManager::availableWidget($_version);
135136
}
136137

137138
public static function returnState($_options) {

src/Controller/Modals/CmdConfigure.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use NextDom\Helpers\Utils;
3131
use NextDom\Managers\CmdManager;
3232
use NextDom\Managers\ConfigManager;
33+
use NextDom\Managers\WidgetManager;
3334

3435
/**
3536
* Class CmdConfigure
@@ -133,7 +134,7 @@ public static function get(): string
133134
$pageData['configDisplayStatsWidget'] = ConfigManager::byKey('displayStatsWidget');
134135
$pageData['cmdDisplayParameters'] = $cmd->getDisplay('parameters');
135136

136-
$cmdWidgetDashboard = CmdManager::availableWidget('dashboard');
137+
$cmdWidgetDashboard = WidgetManager::availableWidget('dashboard');
137138
if (is_array($cmdWidgetDashboard[$cmd->getType()]) && is_array($cmdWidgetDashboard[$cmd->getType()][$cmd->getSubType()]) && count($cmdWidgetDashboard[$cmd->getType()][$cmd->getSubType()]) > 0) {
138139
$pageData['cmdWidgetDashboard'] = $cmdWidgetDashboard[$cmd->getType()][$cmd->getSubType()];
139140
}

src/Controller/Modals/WidgetReplace.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
use NextDom\Helpers\Render;
2626
use NextDom\Managers\CmdManager;
27+
use NextDom\Managers\WidgetManager;
2728

2829
/**
2930
* Class WidgetReplace
@@ -40,8 +41,8 @@ class WidgetReplace extends BaseAbstractModal
4041
public static function get(): string
4142
{
4243
$pageData = array('dashboardList' => '','mobileList'=>'');
43-
$pageData['dashboardList'] = CmdManager::availableWidget('dashboard');
44-
$pageData['mobileList'] = CmdManager::availableWidget('mobile');
44+
$pageData['dashboardList'] = WidgetManager::availableWidget('dashboard');
45+
$pageData['mobileList'] = WidgetManager::availableWidget('mobile');
4546
return Render::getInstance()->get('/modals/widget.replace.html.twig', $pageData);
4647
}
4748

src/Managers/CmdManager.php

-79
Original file line numberDiff line numberDiff line change
@@ -834,85 +834,6 @@ public static function convertColor($color) {
834834
throw new CoreException(__('Impossible de traduire la couleur en code hexadécimal :') . $color);
835835
}
836836

837-
/**
838-
* Check if widget is available
839-
*
840-
* @param string $version Display version
841-
* TODO A factoriser
842-
* @return array
843-
* @throws \Exception
844-
*/
845-
public static function availableWidget($version) {
846-
global $NEXTDOM_INTERNAL_CONFIG;
847-
$result = [];
848-
$lsOptions = ['files', 'quiet'];
849-
$widgetFileSearch = 'cmd.*';
850-
$widgetLocationPaths = [];
851-
foreach (PluginManager::listPlugin(false, false, false) as $plugin) {
852-
$pluginId = $plugin->getId();
853-
$widgetLocationPaths[] = ['path' => NEXTDOM_ROOT . '/plugins/' . $pluginId . '/core/template/' . $version, Common::LOCATION => $pluginId, Common::TYPE => Common::PLUGIN . ' - ' . $pluginId];
854-
if (method_exists($pluginId, 'templateWidget')) {
855-
foreach ($pluginId::templateWidget() as $type => $data1) {
856-
foreach ($data1 as $subtype => $data2) {
857-
foreach ($data2 as $name => $data3) {
858-
if (!isset($result[$type])) {
859-
$result[$type] = [];
860-
}
861-
if (!isset($result[$type][$subtype])) {
862-
$result[$type][$subtype] = [];
863-
}
864-
$result[$type][$subtype][Common::PLUGIN . ' - ' . $pluginId][$pluginId . '::' . $name] = array(Common::NAME => $name, Common::LOCATION => $pluginId, Common::TYPE => Common::PLUGIN);
865-
}
866-
}
867-
}
868-
}
869-
}
870-
$widgetLocationPaths[] = ['path' => NEXTDOM_ROOT . '/views/templates/' . $version, Common::LOCATION => Common::CORE, Common::TYPE => Common::CORE];
871-
$widgetLocationPaths[] = ['path' => NEXTDOM_ROOT . '/plugins/widget/core/template/' . $version, Common::LOCATION => Common::WIDGET, Common::TYPE => Common::WIDGET];
872-
foreach ($widgetLocationPaths as $widgetLocationPath) {
873-
if (file_exists($widgetLocationPath['path'])) {
874-
$files = FileSystemHelper::ls($widgetLocationPath['path'], $widgetFileSearch, false, $lsOptions);
875-
foreach ($files as $file) {
876-
$informations = explode('.', $file);
877-
if (count($informations) > 3 && stripos($informations[3], 'tmpl') === false) {
878-
if (!isset($result[$informations[1]])) {
879-
$result[$informations[1]] = [];
880-
}
881-
if (!isset($result[$informations[1]][$informations[2]])) {
882-
$result[$informations[1]][$informations[2]] = [];
883-
}
884-
if (!isset($result[$informations[1]][$informations[2]][$informations[3]])) {
885-
$result[$informations[1]][$informations[2]][$widgetLocationPath['type']][$informations[3]] = [Common::NAME => $informations[3], Common::LOCATION => $widgetLocationPath[Common::LOCATION], Common::TYPE => $widgetLocationPath['type']];
886-
}
887-
}
888-
}
889-
}
890-
}
891-
foreach ($NEXTDOM_INTERNAL_CONFIG[NextDomObj::CMD][NextDomObj::WIDGET] as $type => $data1) {
892-
foreach ($data1 as $subtype => $data2) {
893-
foreach ($data2 as $name => $data3) {
894-
if (!isset($result[$type])) {
895-
$result[$type] = [];
896-
}
897-
if (!isset($result[$type][$subtype])) {
898-
$result[$type][$subtype] = [];
899-
}
900-
$result[$type][$subtype][Common::TEMPLATE][$name] = array(Common::NAME => $name, Common::LOCATION => Common::CORE, Common::TYPE => Common::TEMPLATE);
901-
}
902-
}
903-
}
904-
foreach (WidgetManager::all() as $widget) {
905-
if (!isset($result[$widget->getType()])) {
906-
$result[$widget->getType()] = [];
907-
}
908-
if (!isset($result[$widget->getType()][$widget->getSubtype()])) {
909-
$result[$widget->getType()][$widget->getSubtype()] = [];
910-
}
911-
$result[$widget->getType()][$widget->getSubtype()][Common::CUSTOM][$widget->getName()] = array(Common::NAME => $widget->getName(), Common::LOCATION => Common::CUSTOM, Common::TYPE => Common::CUSTOM);
912-
}
913-
return $result;
914-
}
915-
916837
/**
917838
* Force command to return state by event
918839
*

src/Managers/WidgetManager.php

+80
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
namespace NextDom\Managers;
3737

38+
use NextDom\Enums\Common;
39+
use NextDom\Enums\NextDomObj;
3840
use NextDom\Helpers\DBHelper;
3941
use NextDom\Helpers\FileSystemHelper;
4042
use NextDom\Managers\Parents\BaseManager;
@@ -215,4 +217,82 @@ public static function replacement($version, $replace, $by) {
215217
return $replaceCount;
216218
}
217219

220+
/**
221+
* Check if widget is available
222+
*
223+
* @param string $version Display version
224+
* TODO A factoriser
225+
* @return array
226+
* @throws \Exception
227+
*/
228+
public static function availableWidget($version) {
229+
global $NEXTDOM_INTERNAL_CONFIG;
230+
$result = [];
231+
$lsOptions = ['files', 'quiet'];
232+
$widgetFileSearch = 'cmd.*';
233+
$widgetLocationPaths = [];
234+
foreach (PluginManager::listPlugin(false, false, false) as $plugin) {
235+
$pluginId = $plugin->getId();
236+
$widgetLocationPaths[] = ['path' => NEXTDOM_ROOT . '/plugins/' . $pluginId . '/core/template/' . $version, Common::LOCATION => $pluginId, Common::TYPE => Common::PLUGIN . ' - ' . $pluginId];
237+
if (method_exists($pluginId, 'templateWidget')) {
238+
foreach ($pluginId::templateWidget() as $type => $data1) {
239+
foreach ($data1 as $subtype => $data2) {
240+
foreach ($data2 as $name => $data3) {
241+
if (!isset($result[$type])) {
242+
$result[$type] = [];
243+
}
244+
if (!isset($result[$type][$subtype])) {
245+
$result[$type][$subtype] = [];
246+
}
247+
$result[$type][$subtype][Common::PLUGIN . ' - ' . $pluginId][$pluginId . '::' . $name] = array(Common::NAME => $name, Common::LOCATION => $pluginId, Common::TYPE => Common::PLUGIN);
248+
}
249+
}
250+
}
251+
}
252+
}
253+
$widgetLocationPaths[] = ['path' => NEXTDOM_ROOT . '/views/templates/' . $version, Common::LOCATION => Common::CORE, Common::TYPE => Common::CORE];
254+
$widgetLocationPaths[] = ['path' => NEXTDOM_ROOT . '/plugins/widget/core/template/' . $version, Common::LOCATION => Common::WIDGET, Common::TYPE => Common::WIDGET];
255+
foreach ($widgetLocationPaths as $widgetLocationPath) {
256+
if (file_exists($widgetLocationPath['path'])) {
257+
$files = FileSystemHelper::ls($widgetLocationPath['path'], $widgetFileSearch, false, $lsOptions);
258+
foreach ($files as $file) {
259+
$informations = explode('.', $file);
260+
if (count($informations) > 3 && stripos($informations[3], 'tmpl') === false) {
261+
if (!isset($result[$informations[1]])) {
262+
$result[$informations[1]] = [];
263+
}
264+
if (!isset($result[$informations[1]][$informations[2]])) {
265+
$result[$informations[1]][$informations[2]] = [];
266+
}
267+
if (!isset($result[$informations[1]][$informations[2]][$informations[3]])) {
268+
$result[$informations[1]][$informations[2]][$widgetLocationPath['type']][$informations[3]] = [Common::NAME => $informations[3], Common::LOCATION => $widgetLocationPath[Common::LOCATION], Common::TYPE => $widgetLocationPath['type']];
269+
}
270+
}
271+
}
272+
}
273+
}
274+
foreach ($NEXTDOM_INTERNAL_CONFIG[NextDomObj::CMD][NextDomObj::WIDGET] as $type => $data1) {
275+
foreach ($data1 as $subtype => $data2) {
276+
foreach ($data2 as $name => $data3) {
277+
if (!isset($result[$type])) {
278+
$result[$type] = [];
279+
}
280+
if (!isset($result[$type][$subtype])) {
281+
$result[$type][$subtype] = [];
282+
}
283+
$result[$type][$subtype][Common::TEMPLATE][$name] = [Common::NAME => $name, Common::LOCATION => Common::CORE, Common::TYPE => Common::TEMPLATE];
284+
}
285+
}
286+
}
287+
foreach (self::all() as $widget) {
288+
if (!isset($result[$widget->getType()])) {
289+
$result[$widget->getType()] = [];
290+
}
291+
if (!isset($result[$widget->getType()][$widget->getSubtype()])) {
292+
$result[$widget->getType()][$widget->getSubtype()] = [];
293+
}
294+
$result[$widget->getType()][$widget->getSubtype()][Common::CUSTOM][$widget->getName()] = [Common::NAME => $widget->getName(), Common::LOCATION => Common::CUSTOM, Common::TYPE => Common::CUSTOM];
295+
}
296+
return $result;
297+
}
218298
}

0 commit comments

Comments
 (0)