diff --git a/Controller/ApiController.php b/Controller/ApiController.php index c5bd957..c276f02 100644 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -89,6 +89,7 @@ final class ApiController extends Controller $asset->type = new NullBaseStringL11nType((int) ($request->getDataInt('type') ?? 0)); $asset->status = AssetStatus::tryFromValue($request->getDataInt('status')) ?? AssetStatus::INACTIVE; $asset->unit = $request->getDataInt('unit') ?? $this->app->unitId; + $asset->equipment = $request->getDataInt('equipment'); return $asset; } diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 3b98528..8aaf3fe 100644 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -81,16 +81,62 @@ final class BackendController extends Controller public function viewAssetManagementView(RequestAbstract $request, ResponseAbstract $response, $data = null) : RenderableInterface { $view = new View($this->app->l11nManager, $request, $response); + $view->setTemplate('/Modules/AssetManagement/Theme/Backend/asset-view'); - $view->data['nav'] = $this->app->moduleManager->get('Navigation')->createNavigationMid(1006601001, $request, $response); + $view->data['nav'] = $this->app->moduleManager->get('Navigation')->createNavigationMid(1008402001, $request, $response); $view->data['asset'] = AssetMapper::get() + ->with('attributes') + ->with('attributes/type') + ->with('attributes/value') + ->with('attributes/type/l11n') + ->with('attributes/value/l11n') + ->with('files') + ->with('files/types') ->with('type') ->with('type/l11n') + ->where('id', (int) $request->getData('id')) ->where('type/l11n/language', $response->header->l11n->language) - ->where('id', (int) $request->getData('int')) + ->where('attributes/type/l11n/language', $response->header->l11n->language) + ->where('attributes/value/l11n/language', [$response->header->l11n->language, null]) ->execute(); + // @feature Create a new read mapper function that returns relation models instead of its own model + // https://github.com/Karaka-Management/phpOMS/issues/320 + $query = new Builder($this->app->dbPool->get()); + $results = $query->selectAs(AssetMapper::HAS_MANY['files']['external'], 'file') + ->from(AssetMapper::TABLE) + ->leftJoin(AssetMapper::HAS_MANY['files']['table']) + ->on(AssetMapper::HAS_MANY['files']['table'] . '.' . AssetMapper::HAS_MANY['files']['self'], '=', AssetMapper::TABLE . '.' . AssetMapper::PRIMARYFIELD) + ->leftJoin(MediaMapper::TABLE) + ->on(AssetMapper::HAS_MANY['files']['table'] . '.' . AssetMapper::HAS_MANY['files']['external'], '=', MediaMapper::TABLE . '.' . MediaMapper::PRIMARYFIELD) + ->leftJoin(MediaMapper::HAS_MANY['types']['table']) + ->on(MediaMapper::TABLE . '.' . MediaMapper::PRIMARYFIELD, '=', MediaMapper::HAS_MANY['types']['table'] . '.' . MediaMapper::HAS_MANY['types']['self']) + ->leftJoin(MediaTypeMapper::TABLE) + ->on(MediaMapper::HAS_MANY['types']['table'] . '.' . MediaMapper::HAS_MANY['types']['external'], '=', MediaTypeMapper::TABLE . '.' . MediaTypeMapper::PRIMARYFIELD) + ->where(AssetMapper::HAS_MANY['files']['self'], '=', $view->data['asset']->id) + ->where(MediaTypeMapper::TABLE . '.' . MediaTypeMapper::getColumnByMember('name'), '=', 'asset_profile_image'); + + $view->data['assetImage'] = MediaMapper::get() + ->with('types') + ->where('id', $results) + ->limit(1) + ->execute(); + + $view->data['types'] = AssetTypeMapper::getAll() + ->with('l11n') + ->where('l11n/language', $response->header->l11n->language) + ->executeGetArray(); + + $view->data['units'] = UnitMapper::getAll() + ->executeGetArray(); + + $view->data['attributeView'] = new \Modules\Attribute\Theme\Backend\Components\AttributeView($this->app->l11nManager, $request, $response); + $view->data['attributeView']->data['default_localization'] = $this->app->l11nServer; + + $view->data['media-upload'] = new \Modules\Media\Theme\Backend\Components\Upload\BaseView($this->app->l11nManager, $request, $response); + $view->data['asset-notes'] = new \Modules\Editor\Theme\Backend\Components\Compound\BaseView($this->app->l11nManager, $request, $response); + return $view; } @@ -174,80 +220,6 @@ final class BackendController extends Controller return $view; } - /** - * Routing end-point for application behavior. - * - * @param RequestAbstract $request Request - * @param ResponseAbstract $response Response - * @param array $data Generic data - * - * @return RenderableInterface Returns a renderable object - * - * @since 1.0.0 - * @codeCoverageIgnore - */ - public function viewAssetManagementAssetView(RequestAbstract $request, ResponseAbstract $response, array $data = []) : RenderableInterface - { - $view = new View($this->app->l11nManager, $request, $response); - - $view->setTemplate('/Modules/AssetManagement/Theme/Backend/asset-view'); - $view->data['nav'] = $this->app->moduleManager->get('Navigation')->createNavigationMid(1008402001, $request, $response); - - $view->data['asset'] = AssetMapper::get() - ->with('attributes') - ->with('attributes/type') - ->with('attributes/value') - ->with('attributes/type/l11n') - ->with('attributes/value/l11n') - ->with('files') - ->with('files/types') - ->with('type') - ->with('type/l11n') - ->where('id', (int) $request->getData('id')) - ->where('type/l11n/language', $response->header->l11n->language) - ->where('attributes/type/l11n/language', $response->header->l11n->language) - ->where('attributes/value/l11n/language', [$response->header->l11n->language, null]) - ->execute(); - - // @feature Create a new read mapper function that returns relation models instead of its own model - // https://github.com/Karaka-Management/phpOMS/issues/320 - $query = new Builder($this->app->dbPool->get()); - $results = $query->selectAs(AssetMapper::HAS_MANY['files']['external'], 'file') - ->from(AssetMapper::TABLE) - ->leftJoin(AssetMapper::HAS_MANY['files']['table']) - ->on(AssetMapper::HAS_MANY['files']['table'] . '.' . AssetMapper::HAS_MANY['files']['self'], '=', AssetMapper::TABLE . '.' . AssetMapper::PRIMARYFIELD) - ->leftJoin(MediaMapper::TABLE) - ->on(AssetMapper::HAS_MANY['files']['table'] . '.' . AssetMapper::HAS_MANY['files']['external'], '=', MediaMapper::TABLE . '.' . MediaMapper::PRIMARYFIELD) - ->leftJoin(MediaMapper::HAS_MANY['types']['table']) - ->on(MediaMapper::TABLE . '.' . MediaMapper::PRIMARYFIELD, '=', MediaMapper::HAS_MANY['types']['table'] . '.' . MediaMapper::HAS_MANY['types']['self']) - ->leftJoin(MediaTypeMapper::TABLE) - ->on(MediaMapper::HAS_MANY['types']['table'] . '.' . MediaMapper::HAS_MANY['types']['external'], '=', MediaTypeMapper::TABLE . '.' . MediaTypeMapper::PRIMARYFIELD) - ->where(AssetMapper::HAS_MANY['files']['self'], '=', $view->data['asset']->id) - ->where(MediaTypeMapper::TABLE . '.' . MediaTypeMapper::getColumnByMember('name'), '=', 'asset_profile_image'); - - $view->data['assetImage'] = MediaMapper::get() - ->with('types') - ->where('id', $results) - ->limit(1) - ->execute(); - - $view->data['types'] = AssetTypeMapper::getAll() - ->with('l11n') - ->where('l11n/language', $response->header->l11n->language) - ->executeGetArray(); - - $view->data['units'] = UnitMapper::getAll() - ->executeGetArray(); - - $view->data['attributeView'] = new \Modules\Attribute\Theme\Backend\Components\AttributeView($this->app->l11nManager, $request, $response); - $view->data['attributeView']->data['default_localization'] = $this->app->l11nServer; - - $view->data['media-upload'] = new \Modules\Media\Theme\Backend\Components\Upload\BaseView($this->app->l11nManager, $request, $response); - $view->data['asset-notes'] = new \Modules\Editor\Theme\Backend\Components\Compound\BaseView($this->app->l11nManager, $request, $response); - - return $view; - } - /** * Routing end-point for application behavior. * diff --git a/Models/Asset.php b/Models/Asset.php index 46bafe5..4b50782 100644 --- a/Models/Asset.php +++ b/Models/Asset.php @@ -44,7 +44,7 @@ class Asset implements \JsonSerializable public \DateTimeImmutable $createdAt; - public int $equipment = 0; + public ?int $equipment = null; /** * Constructor. diff --git a/Theme/Backend/asset-view.tpl.php b/Theme/Backend/asset-view.tpl.php index 7e92e16..5cad854 100644 --- a/Theme/Backend/asset-view.tpl.php +++ b/Theme/Backend/asset-view.tpl.php @@ -40,7 +40,6 @@ echo $this->data['nav']->render();
  • -
  • @@ -144,7 +143,7 @@ echo $this->data['nav']->render(); $asset->attributes, $this->data['attributeTypes'] ?? [], $this->data['units'] ?? [], - '{/api}fleet/asset/attribute?csrf={$CSRF}', + '{/api}accounting/asset/attribute?csrf={$CSRF}', $asset->id ); ?> @@ -161,59 +160,6 @@ echo $this->data['nav']->render(); data['asset-notes']->render('asset-notes', '', $asset->notes); ?> - request->uri->fragment === 'c-tab-5' ? ' checked' : ''; ?>> -
    - -
    -
    -
    -
    getHtml('Upcoming'); ?>
    - - - - - data['inspections'] as $inspection) : - // @todo handle old inspections in the past? maybe use a status?! - if ($inspection->next === null) { - continue; - } - ?> - -
    getHtml('Date'); ?> - getHtml('Type'); ?> - getHtml('Responsible'); ?> -
    next->format('Y-m-d H:i'); ?> - printHtml($inspection->type->getL11n()); ?> - - -
    -
    -
    - -
    -
    -
    getHtml('History'); ?>
    - - - - - data['inspections'] as $inspection) : ?> - -
    getHtml('Date'); ?> - getHtml('Type'); ?> - getHtml('Responsible'); ?> -
    date->format('Y-m-d H:i'); ?> - printHtml($inspection->type->getL11n()); ?> - - -
    -
    -
    -
    -
    - request->uri->fragment === 'c-tab-8' ? ' checked' : ''; ?>>