refactor helper function extendableApps to singleton helper class ExtendableAppsHelper and use it in FHC-Header and FHC-Footer, revert previous changes to other CI views

This commit is contained in:
Harald Bamberger
2026-02-27 16:50:50 +01:00
parent 43a37021a5
commit 28f4a38752
15 changed files with 197 additions and 74 deletions
+161 -45
View File
@@ -277,75 +277,191 @@ function absoluteJsImportUrl($relurl)
* if customJSModules contains at least one vuejs app and customisation files
* exist in extensions
*/
function extendableApps($includes)
class ExtendableAppsHelper
{
if(!isset($includes['customJSModules']))
private static $instance = null;
protected $extensions;
protected $customCSSs;
protected $customJSs;
protected $customJSModules;
protected $initialised;
protected $appscount;
protected $extCustomCSSs;
protected $extCustomJSs;
protected $extCustomJSModules;
private function __construct()
{
return;
$this->extensions = array();
$this->customCSSs = null;
$this->customJSs = null;
$this->customJSModules = null;
$this->initialised = false;
$this->appscount = 0;
$this->extCustomCSSs = null;
$this->extCustomJSs = null;
$this->extCustomJSModules = null;
}
if(!is_array($includes['customJSModules']))
public static function getInstance()
{
$includes['customJSModules'] = array($includes['customJSModules']);
}
$extensions = array();
$fsiterator = new FilesystemIterator(FHCPATH . 'application/extensions');
foreach ($fsiterator as $fsitem)
{
if(preg_match('/^FHC-Core-/', $fsitem->getBasename()))
if(self::$instance === null)
{
$extensions[] = $fsitem->getBasename();
self::$instance = new ExtendableAppsHelper();
}
return self::$instance;
}
$appscount = 0;
$tmpCustomJSModules = array();
foreach($includes['customJSModules'] as $item)
public function init($customCSSs, $customJSs, $customJSModules)
{
$matches = array();
if(preg_match('#^public/(extensions/FHC-Core-.+)?js/apps/(.*)\.js$#', $item, $matches))
if($this->initialised)
{
$appscount++;
return;
}
$fhcextension = $matches[1];
$app = $matches[2];
$this->customCSSs = $customCSSs;
$this->customJSs = $customJSs;
$this->customJSModules = $customJSModules;
$this->initialised = true;
$extend_js_suffix = 'js/extend_app/' . $fhcextension . $app . '.js';
$extend_css_suffix = 'css/extend_app/' . $fhcextension . $app . '.css';
if(!isset($this->customJSModules))
{
return;
}
foreach($extensions as $extension)
if(!is_array($this->customJSModules))
{
$this->customJSModules = array($this->customJSModules);
}
if(count($this->customJSModules) < 1)
{
return;
}
$this->buildExtensionsList();
$this->prepareExtendedArrays();
}
public function getCustomCSSs()
{
if(is_null($this->extCustomCSSs))
{
return $this->customCSSs;
}
return $this->extCustomCSSs;
}
public function getCustomJSs()
{
if(is_null($this->extCustomJSs))
{
return $this->customJSs;
}
return $this->extCustomJSs;
}
public function getCustomJSModules()
{
if(is_null($this->extCustomJSModules))
{
return $this->customJSModules;
}
return $this->extCustomJSModules;
}
protected function buildExtensionsList()
{
$this->extensions = array();
$fsiterator = new FilesystemIterator(FHCPATH . 'application/extensions');
foreach ($fsiterator as $fsitem)
{
if(preg_match('/^FHC-Core-/', $fsitem->getBasename()))
{
$extend_js = 'public/extensions/' . $extension . '/' . $extend_js_suffix;
$extend_css = 'public/extensions/' . $extension . '/' . $extend_css_suffix;
if(is_readable(FHCPATH . $extend_js))
{
array_push($tmpCustomJSModules, $extend_js);
}
if(is_readable(FHCPATH . $extend_css))
{
array_push($includes['customCSSs'], $extend_css);
}
$this->extensions[] = $fsitem->getBasename();
}
}
array_push($tmpCustomJSModules, $item);
}
$includes['customJSModules'] = $tmpCustomJSModules;
if($appscount > 0)
protected function prepareExtendedArrays()
{
if(!isset($includes['customJSs']))
$this->appscount = 0;
$this->initExtCustomCSSs();
$this->extCustomJSModules = array();
foreach($this->customJSModules as $item)
{
$includes['customJSs'] = array();
$matches = array();
if(preg_match('#^public/(extensions/FHC-Core-.+)?js/apps/(.*)\.js$#', $item, $matches))
{
$this->appscount++;
$fhcextension = $matches[1];
$app = $matches[2];
$extend_js_suffix = 'js/extend_app/' . $fhcextension . $app . '.js';
$extend_css_suffix = 'css/extend_app/' . $fhcextension . $app . '.css';
foreach($this->extensions as $extension)
{
$extend_js = 'public/extensions/' . $extension . '/' . $extend_js_suffix;
$extend_css = 'public/extensions/' . $extension . '/' . $extend_css_suffix;
if(is_readable(FHCPATH . $extend_js))
{
array_push($this->extCustomJSModules, $extend_js);
}
if(is_readable(FHCPATH . $extend_css))
{
array_push($this->extCustomCSSs, $extend_css);
}
}
}
array_push($this->extCustomJSModules, $item);
}
elseif(!is_array($includes['customJSs']))
if($this->appscount > 0)
{
$includes['customJSs'] = array($includes['customJSs']);
$this->addFhcAppsJs();
}
array_push($includes['customJSs'], 'public/js/FhcApps.js');
}
return $includes;
protected function initExtCustomCSSs()
{
if(!isset($this->customCSSs))
{
$this->extCustomCSSs = array();
}
elseif(!is_array($this->customCSSs))
{
$this->extCustomCSSs = array($this->customCSSs);
}
else
{
$this->extCustomCSSs = $this->customCSSs;
}
}
protected function addFhcAppsJs()
{
if(!isset($this->customJSs))
{
$this->extCustomJSs = array();
}
elseif(!is_array($this->customJSs))
{
$this->extCustomJSs = array($this->customJSs);
}
else
{
$this->extCustomJSs = $this->customJSs;
}
array_push($this->extCustomJSs, 'public/js/FhcApps.js');
}
}
+2 -2
View File
@@ -1,9 +1,9 @@
<?php
$includesArray = extendableApps(array(
$includesArray = array(
'title' => 'Documents',
'tabulator5' => true,
'customJSModules' => ['public/js/apps/Cis/Documents.js']
));
);
$this->load->view('templates/CISVUE-Header', $includesArray);
?>
+2 -2
View File
@@ -1,5 +1,5 @@
<?php
$includesArray = extendableApps(array(
$includesArray = array(
'title' => 'Profil Änderungen',
'vue3' => true,
'primevue3' => true,
@@ -16,7 +16,7 @@ $includesArray = extendableApps(array(
'customCSSs' => array(
'public/css/components/FilterComponent.css','public/css/components/FormUnderline.css'
)
));
);
if(defined("CIS4"))
{
@@ -1,6 +1,6 @@
<?php
$includesArray = extendableApps(array(
$includesArray = array(
'title' => 'Cis4',
'axios027' => true,
'bootstrap5' => true,
@@ -42,7 +42,7 @@ $includesArray = extendableApps(array(
'public/js/apps/Dashboard/Fhc.js',
),
));
);
$this->load->view('templates/CISVUE-Header', $includesArray);
?>
+2 -2
View File
@@ -1,5 +1,5 @@
<?php
$includesArray = extendableApps(array(
$includesArray = array(
'title' => 'LVVerwaltung',
'axios027' => true,
'bootstrap5' => true,
@@ -20,7 +20,7 @@
'customJSModules' => [
'public/js/apps/LVVerwaltung.js'
]
));
);
$this->load->view('templates/FHC-Header', $includesArray);
+2 -2
View File
@@ -1,5 +1,5 @@
<?php
$includesArray = extendableApps(array(
$includesArray = array(
'title' => 'Studentenverwaltung',
'axios027' => true,
'bootstrap5' => true,
@@ -30,7 +30,7 @@
'customJSModules' => [
'public/js/apps/Studentenverwaltung.js'
]
));
);
$this->load->view('templates/FHC-Header', $includesArray);
?>
+2 -2
View File
@@ -1,5 +1,5 @@
<?php
$includesArray = extendableApps(array(
$includesArray = array(
'title' => 'Bismeldestichtage',
'axios027' => true,
'bootstrap5' => true,
@@ -11,7 +11,7 @@
'customCSSs' => array('vendor/vuejs/vuedatepicker_css/main.css'),
'customJSs' => array('vendor/vuejs/vuedatepicker_js/vue-datepicker.iife.js'),
'customJSModules' => array('public/js/apps/Bismeldestichtag/Bismeldestichtag.js')
));
);
$this->load->view('templates/FHC-Header', $includesArray);
?>
+2 -2
View File
@@ -1,5 +1,5 @@
<?php
$sitesettings = extendableApps(array(
$sitesettings = array(
'title' => 'Antrag auf Änderung des Studierendenstatus',
'cis' => true,
'vue3' => true,
@@ -16,7 +16,7 @@ $sitesettings = extendableApps(array(
),
'customJSs' => array(
)
));
);
if(defined('CIS4')){
$this->load->view(
@@ -2,7 +2,7 @@
use \DateTime as DateTime;
$sitesettings = extendableApps(array(
$sitesettings = array(
'title' => 'Anträge auf Änderung des Studierendenstatus',
'cis' => true,
'vue3' => true,
@@ -25,7 +25,7 @@ $sitesettings = extendableApps(array(
),
'customJSs' => array(
)
));
);
$this->load->view(
'templates/FHC-Header',
@@ -1,5 +1,5 @@
<?php
$sitesettings = extendableApps(array(
$sitesettings = array(
'title' => 'Antrag auf Änderung des Studierendenstatus',
'cis' => true,
'vue3' => true,
@@ -15,7 +15,7 @@ $sitesettings = extendableApps(array(
),
'customJSs' => array(
)
));
);
if(defined('CIS4')){
$this->load->view(
@@ -1,5 +1,5 @@
<?php
$sitesettings = extendableApps(array(
$sitesettings = array(
'title' => 'Antrag Wiederholung vom Studium',
'cis' => true,
'vue3' => true,
@@ -19,7 +19,7 @@ $sitesettings = extendableApps(array(
),
'customJSs' => array(
)
));
);
$this->load->view(
'templates/FHC-Header',
@@ -1,5 +1,5 @@
<?php
$includesArray = extendableApps(array(
$includesArray = array(
'title' => 'LV Template Übersicht',
'vue3' => true,
'axios027' => true,
@@ -14,7 +14,7 @@ $includesArray = extendableApps(array(
'public/css/Fhc.css',
'public/css/lvTemplateUebersicht.css'
)
));
);
$this->load->view('templates/FHC-Header', $includesArray);
?>
+2 -2
View File
@@ -1,5 +1,5 @@
<?php
$includesArray = extendableApps(array(
$includesArray = array(
'title' => 'Logs Viewer',
'axios027' => true,
'bootstrap5' => true,
@@ -14,7 +14,7 @@
'ui' => array('bitteEintragWaehlen')
),
'customJSModules' => array('public/js/apps/LogsViewer/LogsViewer.js'),
));
);
$this->load->view('templates/FHC-Header', $includesArray);
?>
+6 -4
View File
@@ -17,6 +17,7 @@
$use_vuejs_dev_version = $this->config->item('use_vuejs_dev_version');
// By default set the parameters to null
$customCSSs = isset($customCSSs) ? $customCSSs : null;
$customJSs = isset($customJSs) ? $customJSs : null;
$customJSModules = isset($customJSModules) ? $customJSModules : null;
@@ -191,12 +192,13 @@
// NOTE: keep it as the last but one
if ($addons === true) generateAddonsJSsInclude($calledPath.'/'.$calledMethod);
$extapphelper = ExtendableAppsHelper::getInstance();
$extapphelper->init($customCSSs, $customJSs, $customJSModules);
// Eventually required JS
// NOTE: keep it as the latest
generateJSsInclude($customJSs);
generateJSModulesInclude($customJSModules);
generateJSsInclude($extapphelper->getCustomJSs());
generateJSModulesInclude($extapphelper->getCustomJSModules());
?>
</body>
</html>
+6 -1
View File
@@ -9,6 +9,8 @@
$title = isset($title) ? $title : null;
$refresh = isset($refresh) ? $refresh : null;
$customCSSs = isset($customCSSs) ? $customCSSs : null;
$customJSs = isset($customJSs) ? $customJSs : null;
$customJSModules = isset($customJSModules) ? $customJSModules : null;
$skipID = isset($skipID) ? $skipID : null;
?>
<!-- Header start -->
@@ -132,8 +134,11 @@
//Tags
if ($tags === true) generateCSSsInclude('public/css/tags.css');
$extapphelper = ExtendableAppsHelper::getInstance();
$extapphelper->init($customCSSs, $customJSs, $customJSModules);
// Eventually required CSS
generateCSSsInclude($customCSSs); // Eventually required CSS
generateCSSsInclude($extapphelper->getCustomCSSs()); // Eventually required CSS
?>
</head>
<body>