Enhance dynamicimages module with refined asset management and image path configuration

- Update `dynamicimages_asset` constructor to prepend working directory to paths.
- Add helper methods (`getPath`, `getWidth`, `getHeight`) to `dynamicimages_asset`.
- Extend `dynamicimages_image_t` trait with debugging and path configuration utilities.
- Refactor asset path handling in `machine_1` with constants for image files.
- Load `dynamicimages` interfaces, traits, classes, helpers, and configurations in `index.php`.
This commit is contained in:
Jeppe Bundgaard
2026-01-27 11:21:07 +01:00
parent f1f7ba1d46
commit e2521e222f
5 changed files with 68 additions and 15 deletions
+21
View File
@@ -112,6 +112,27 @@ require_once 'modules/goals/classes/goals_criteria_products.php';
require_once 'modules/goals/classes/goals_criteria.php';
require_once 'modules/goals/classes/goals.php';
// Dynamic Images module
foreach (glob(WD . '/modules/dynamicimages/interfaces/*.php') as $interface) {
require_once $interface;
}
foreach (glob(WD . '/modules/dynamicimages/traits/*.php') as $trait) {
require_once $trait;
}
foreach (glob(WD . '/modules/dynamicimages/classes/*.php') as $classFile) {
require_once $classFile;
}
foreach (glob(WD . '/modules/dynamicimages/helpers/*.php') as $helper) {
require_once $helper;
}
foreach (glob(WD . '/modules/dynamicimages/config/*.php') as $configFile) {
require_once $configFile;
}
// Load image definitions (e.g., dynamicimages\images\machine_1)
foreach (glob(WD . '/modules/dynamicimages/images/*.php') as $imageClass) {
require_once $imageClass;
}
use classes\db;
use classes\redis;
use classes\request;
@@ -29,7 +29,7 @@ class dynamicimages_asset implements dynamicimages_asset_i
*/
public function __construct(string $path)
{
$this->path = $path;
$this->path = WD . '/' . $path;
$this->initialize();
}
/**
@@ -42,4 +42,18 @@ class dynamicimages_asset implements dynamicimages_asset_i
}
list($this->width, $this->height) = getimagesize($this->path);
}
public function getPath(): string
{
return $this->path;
}
public function getWidth(): ?int
{
return $this->width;
}
public function getHeight(): ?int
{
return $this->height;
}
}
@@ -29,14 +29,4 @@ class dynamicimages_image implements dynamicimages_image_i
$this->setAssets($assets);
}
public function getAssetPath(string $asset_name): string
{
return $this->module_asset_path . $asset_name;
}
public function setAssetPath(string $asset_path): dynamicimages_image_i
{
$this->module_asset_path = $asset_path;
return $this;
}
}
@@ -8,16 +8,22 @@ use dynamicimages\classes\dynamicimages_image;
class machine_1 extends dynamicimages_image
{
const IMAGE_POWER_BUTTON = 'machine_1_button_start_stop.png';
const IMAGE_PANEL_BACKGROUND = 'machine_1_panel_background.png';
const IMAGE_WASH_PROGRAMS_THUMB = 'machine_1_wash_programs_thumb_transparent.png';
const IMAGE_WASH_PROGRAMS = 'machine_1_wash_programs_transparent.png';
/**
* @throws \Exception
*/
public function __construct()
{
$this->setAssetPath(self::asset_path . str_replace(__NAMESPACE__ . '\\', '', __CLASS__) . '/');
parent::__construct([
new dynamicimages_asset(self::getAssetPath('machine_1_button_start_stop.png')),
new dynamicimages_asset(self::getAssetPath('machine_1_panel_background.png')),
new dynamicimages_asset(self::getAssetPath('machine_1_wash_programs_thumb_transparent.png')),
new dynamicimages_asset(self::getAssetPath('machine_1_wash_programs_transparent.png')),
new dynamicimages_asset(self::getAssetPath(self::IMAGE_POWER_BUTTON)),
new dynamicimages_asset(self::getAssetPath(self::IMAGE_PANEL_BACKGROUND)),
new dynamicimages_asset(self::getAssetPath(self::IMAGE_WASH_PROGRAMS_THUMB)),
new dynamicimages_asset(self::getAssetPath(self::IMAGE_WASH_PROGRAMS)),
], self::asset_path . str_replace('\\', '/', __CLASS__) . '/');
echo 'Asset path set for machine_1: ' . $this->module_asset_path . PHP_EOL;
}
@@ -33,4 +33,26 @@ trait dynamicimages_image_t
$this->assets[] = $asset;
return $this;
}
/**
* Debug
*/
public function debugAssets(): void
{
echo 'Assets count: ' . count($this->assets) . PHP_EOL;
foreach ($this->assets as $asset) {
echo 'Asset path: ' . $asset->getPath() . ' - (Width: ' . $asset->getWidth() . ', Height: ' . $asset->getHeight() . ')' . PHP_EOL;
}
}
public function getAssetPath(string $asset_name): string
{
return $this->module_asset_path . $asset_name;
}
public function setAssetPath(string $asset_path): dynamicimages_image_i
{
$this->module_asset_path = $asset_path;
return $this;
}
}