|
35 | 35 |
|
36 | 36 | namespace NextDom\Managers;
|
37 | 37 |
|
| 38 | +use NextDom\Enums\Common; |
| 39 | +use NextDom\Enums\NextDomObj; |
38 | 40 | use NextDom\Helpers\DBHelper;
|
39 | 41 | use NextDom\Helpers\FileSystemHelper;
|
40 | 42 | use NextDom\Managers\Parents\BaseManager;
|
@@ -215,4 +217,82 @@ public static function replacement($version, $replace, $by) {
|
215 | 217 | return $replaceCount;
|
216 | 218 | }
|
217 | 219 |
|
| 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 | + } |
218 | 298 | }
|
0 commit comments