mirror of
https://github.com/Karaka-Management/oms-EquipmentManagement.git
synced 2026-01-11 09:08:42 +00:00
448 lines
18 KiB
PHP
Executable File
448 lines
18 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Jingga
|
|
*
|
|
* PHP Version 8.2
|
|
*
|
|
* @package Modules\EquipmentManagement
|
|
* @copyright Dennis Eichhorn
|
|
* @license OMS License 2.0
|
|
* @version 1.0.0
|
|
* @link https://jingga.app
|
|
*/
|
|
declare(strict_types=1);
|
|
|
|
namespace Modules\EquipmentManagement\Controller;
|
|
|
|
use Modules\Attribute\Models\NullAttributeType;
|
|
use Modules\Attribute\Models\NullAttributeValue;
|
|
use Modules\EquipmentManagement\Models\Attribute\EquipmentAttributeTypeL11nMapper;
|
|
use Modules\EquipmentManagement\Models\Attribute\EquipmentAttributeTypeMapper;
|
|
use Modules\EquipmentManagement\Models\Attribute\EquipmentAttributeValueL11nMapper;
|
|
use Modules\EquipmentManagement\Models\Attribute\EquipmentAttributeValueMapper;
|
|
use Modules\EquipmentManagement\Models\EquipmentMapper;
|
|
use Modules\EquipmentManagement\Models\EquipmentTypeMapper;
|
|
use Modules\EquipmentManagement\Models\Inspection;
|
|
use Modules\EquipmentManagement\Models\InspectionMapper;
|
|
use Modules\EquipmentManagement\Models\InspectionTypeMapper;
|
|
use Modules\Media\Models\MediaMapper;
|
|
use Modules\Organization\Models\UnitMapper;
|
|
use Modules\Tag\Models\TagMapper;
|
|
use phpOMS\Contract\RenderableInterface;
|
|
use phpOMS\DataStorage\Database\Query\Builder;
|
|
use phpOMS\Message\RequestAbstract;
|
|
use phpOMS\Message\ResponseAbstract;
|
|
use phpOMS\Views\View;
|
|
|
|
/**
|
|
* EquipmentManagement class.
|
|
*
|
|
* @package Modules\EquipmentManagement
|
|
* @license OMS License 2.0
|
|
* @link https://jingga.app
|
|
* @since 1.0.0
|
|
* @codeCoverageIgnore
|
|
*/
|
|
final class BackendController extends Controller
|
|
{
|
|
/**
|
|
* 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 viewEquipmentManagementAttributeTypeList(RequestAbstract $request, ResponseAbstract $response, array $data = []) : RenderableInterface
|
|
{
|
|
$view = new \Modules\Attribute\Theme\Backend\Components\AttributeTypeListView($this->app->l11nManager, $request, $response);
|
|
$view->data['nav'] = $this->app->moduleManager->get('Navigation')->createNavigationMid(1008405001, $request, $response);
|
|
|
|
$view->attributes = EquipmentAttributeTypeMapper::getAll()
|
|
->with('l11n')
|
|
->where('l11n/language', $response->header->l11n->language)
|
|
->executeGetArray();
|
|
|
|
$view->path = 'equipment';
|
|
|
|
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 viewEquipmentManagementEquipmentList(RequestAbstract $request, ResponseAbstract $response, array $data = []) : RenderableInterface
|
|
{
|
|
$view = new View($this->app->l11nManager, $request, $response);
|
|
|
|
$view->setTemplate('/Modules/EquipmentManagement/Theme/Backend/equipment-list');
|
|
$view->data['nav'] = $this->app->moduleManager->get('Navigation')->createNavigationMid(1008402001, $request, $response);
|
|
|
|
$list = EquipmentMapper::getAll()
|
|
->with('type')
|
|
->with('type/l11n')
|
|
->where('type/l11n/language', $response->header->l11n->language)
|
|
->sort('id', 'DESC')
|
|
->executeGetArray();
|
|
|
|
$view->data['equipments'] = $list;
|
|
|
|
return $view;
|
|
}
|
|
|
|
/**
|
|
* Routing end-point for application behavior.
|
|
*
|
|
* @param RequestAbstract $request Request
|
|
* @param ResponseAbstract $response Response
|
|
* @param array $data Generic data
|
|
*
|
|
* @return RenderableInterface
|
|
*
|
|
* @since 1.0.0
|
|
* @codeCoverageIgnore
|
|
*/
|
|
public function viewEquipmentManagementAttributeType(RequestAbstract $request, ResponseAbstract $response, array $data = []) : RenderableInterface
|
|
{
|
|
$view = new \Modules\Attribute\Theme\Backend\Components\AttributeTypeView($this->app->l11nManager, $request, $response);
|
|
$view->data['nav'] = $this->app->moduleManager->get('Navigation')->createNavigationMid(1008405001, $request, $response);
|
|
|
|
$view->attribute = EquipmentAttributeTypeMapper::get()
|
|
->with('l11n')
|
|
->with('defaults')
|
|
->with('defaults/l11n')
|
|
->where('id', (int) $request->getData('id'))
|
|
->where('l11n/language', $response->header->l11n->language)
|
|
->where('defaults/l11n/language', [$response->header->l11n->language, null])
|
|
->execute();
|
|
|
|
$view->l11ns = EquipmentAttributeTypeL11nMapper::getAll()
|
|
->where('ref', $view->attribute->id)
|
|
->executeGetArray();
|
|
|
|
$view->path = 'fleet/vehicle';
|
|
|
|
return $view;
|
|
}
|
|
|
|
/**
|
|
* Routing end-point for application behavior.
|
|
*
|
|
* @param RequestAbstract $request Request
|
|
* @param ResponseAbstract $response Response
|
|
* @param array $data Generic data
|
|
*
|
|
* @return RenderableInterface
|
|
*
|
|
* @since 1.0.0
|
|
* @codeCoverageIgnore
|
|
*/
|
|
public function viewEquipmentManagementAttributeValue(RequestAbstract $request, ResponseAbstract $response, array $data = []) : RenderableInterface
|
|
{
|
|
$view = new \Modules\Attribute\Theme\Backend\Components\AttributeValueView($this->app->l11nManager, $request, $response);
|
|
$view->data['nav'] = $this->app->moduleManager->get('Navigation')->createNavigationMid(1008405001, $request, $response);
|
|
|
|
$view->attribute = EquipmentAttributeValueMapper::get()
|
|
->with('l11n')
|
|
->where('id', (int) $request->getData('id'))
|
|
->where('l11n/language', [$response->header->l11n->language, null])
|
|
->execute();
|
|
|
|
$view->l11ns = EquipmentAttributeValueL11nMapper::getAll()
|
|
->where('ref', $view->attribute->id)
|
|
->executeGetArray();
|
|
|
|
// @todo Also find the ItemAttributeType
|
|
|
|
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 viewEquipmentManagementEquipmentCreate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : RenderableInterface
|
|
{
|
|
$view = new View($this->app->l11nManager, $request, $response);
|
|
|
|
$view->setTemplate('/Modules/EquipmentManagement/Theme/Backend/equipment-view');
|
|
$view->data['nav'] = $this->app->moduleManager->get('Navigation')->createNavigationMid(1008402001, $request, $response);
|
|
|
|
$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['equipment-notes'] = new \Modules\Editor\Theme\Backend\Components\Compound\BaseView($this->app->l11nManager, $request, $response);
|
|
|
|
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 viewEquipmentManagementEquipmentView(RequestAbstract $request, ResponseAbstract $response, array $data = []) : RenderableInterface
|
|
{
|
|
$view = new View($this->app->l11nManager, $request, $response);
|
|
|
|
$view->setTemplate('/Modules/EquipmentManagement/Theme/Backend/equipment-view');
|
|
$view->data['nav'] = $this->app->moduleManager->get('Navigation')->createNavigationMid(1008402001, $request, $response);
|
|
|
|
$view->data['equipment'] = EquipmentMapper::get()
|
|
->with('attributes')
|
|
->with('attributes/type')
|
|
->with('attributes/value')
|
|
->with('attributes/type/l11n')
|
|
->with('attributes/value/l11n')
|
|
->with('files')
|
|
->with('files/tags')
|
|
->with('type')
|
|
->with('type/l11n')
|
|
->with('fuelType')
|
|
->with('fuelType/l11n')
|
|
->where('id', (int) $request->getData('id'))
|
|
->where('type/l11n/language', $response->header->l11n->language)
|
|
->where('fuelType/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();
|
|
|
|
$view->data['inspections'] = InspectionMapper::getAll()
|
|
->with('type')
|
|
->with('type/l11n')
|
|
->where('reference', $view->data['equipment']->id)
|
|
->where('type/l11n/language', $response->header->l11n->language)
|
|
->executeGetArray();
|
|
|
|
// @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(EquipmentMapper::HAS_MANY['files']['external'], 'file')
|
|
->from(EquipmentMapper::TABLE)
|
|
->leftJoin(EquipmentMapper::HAS_MANY['files']['table'])
|
|
->on(EquipmentMapper::HAS_MANY['files']['table'] . '.' . EquipmentMapper::HAS_MANY['files']['self'], '=', EquipmentMapper::TABLE . '.' . EquipmentMapper::PRIMARYFIELD)
|
|
->leftJoin(MediaMapper::TABLE)
|
|
->on(EquipmentMapper::HAS_MANY['files']['table'] . '.' . EquipmentMapper::HAS_MANY['files']['external'], '=', MediaMapper::TABLE . '.' . MediaMapper::PRIMARYFIELD)
|
|
->leftJoin(MediaMapper::HAS_MANY['tags']['table'])
|
|
->on(MediaMapper::TABLE . '.' . MediaMapper::PRIMARYFIELD, '=', MediaMapper::HAS_MANY['tags']['table'] . '.' . MediaMapper::HAS_MANY['tags']['self'])
|
|
->leftJoin(TagMapper::TABLE)
|
|
->on(MediaMapper::HAS_MANY['tags']['table'] . '.' . MediaMapper::HAS_MANY['tags']['external'], '=', TagMapper::TABLE . '.' . TagMapper::PRIMARYFIELD)
|
|
->where(EquipmentMapper::HAS_MANY['files']['self'], '=', $view->data['equipment']->id)
|
|
->where(TagMapper::TABLE . '.' . TagMapper::getColumnByMember('name'), '=', 'profile_image');
|
|
|
|
$view->data['equipmentImage'] = MediaMapper::get()
|
|
->where('id', $results)
|
|
->limit(1)
|
|
->execute();
|
|
|
|
$view->data['types'] = EquipmentTypeMapper::getAll()
|
|
->with('l11n')
|
|
->where('l11n/language', $response->header->l11n->language)
|
|
->executeGetArray();
|
|
|
|
$view->data['units'] = UnitMapper::getAll()
|
|
->executeGetArray();
|
|
|
|
$view->data['attributeTypes'] = EquipmentAttributeTypeMapper::getAll()
|
|
->with('l11n')
|
|
->where('l11n/language', $response->header->l11n->language)
|
|
->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['equipment-notes'] = new \Modules\Editor\Theme\Backend\Components\Compound\BaseView($this->app->l11nManager, $request, $response);
|
|
|
|
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 viewEquipmentManagementInspectionList(RequestAbstract $request, ResponseAbstract $response, array $data = []) : RenderableInterface
|
|
{
|
|
$view = new View($this->app->l11nManager, $request, $response);
|
|
|
|
$view->setTemplate('/Modules/EquipmentManagement/Theme/Backend/inspection-list');
|
|
$view->data['nav'] = $this->app->moduleManager->get('Navigation')->createNavigationMid(1008404001, $request, $response);
|
|
|
|
$view->data['inspections'] = InspectionMapper::getAll()
|
|
->with('type')
|
|
->with('type/l11n')
|
|
->where('type/l11n/language', $request->header->l11n->language)
|
|
->sort('id', 'DESC')
|
|
->limit(100)
|
|
->executeGetArray();
|
|
|
|
$view->data['equipment'] = EquipmentMapper::getAll()
|
|
->with('account')
|
|
->where('id', \array_map(function (Inspection $inspection) : int { return $inspection->reference; }, $view->data['inspections']))
|
|
->executeGetArray();
|
|
|
|
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 viewEquipmentManagementInspectionTypeList(RequestAbstract $request, ResponseAbstract $response, array $data = []) : RenderableInterface
|
|
{
|
|
$view = new View($this->app->l11nManager, $request, $response);
|
|
$view->setTemplate('/Modules/EquipmentManagement/Theme/Backend/inspection-type-list');
|
|
$view->data['nav'] = $this->app->moduleManager->get('Navigation')->createNavigationMid(1008404001, $request, $response);
|
|
|
|
$view->data['types'] = InspectionTypeMapper::getAll()
|
|
->with('l11n')
|
|
->where('l11n/language', $response->header->l11n->language)
|
|
->sort('id', 'DESC')
|
|
->executeGetArray();
|
|
|
|
return $view;
|
|
}
|
|
|
|
/**
|
|
* Routing end-point for application behavior.
|
|
*
|
|
* @param RequestAbstract $request Request
|
|
* @param ResponseAbstract $response Response
|
|
* @param array $data Generic data
|
|
*
|
|
* @return RenderableInterface
|
|
*
|
|
* @since 1.0.0
|
|
* @codeCoverageIgnore
|
|
*/
|
|
public function viewEquipmentManagementAttributeTypeCreate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : RenderableInterface
|
|
{
|
|
$view = new \Modules\Attribute\Theme\Backend\Components\AttributeTypeView($this->app->l11nManager, $request, $response);
|
|
$view->data['nav'] = $this->app->moduleManager->get('Navigation')->createNavigationMid(1008405001, $request, $response);
|
|
|
|
$view->attribute = new NullAttributeType();
|
|
|
|
$view->path = 'equipment';
|
|
|
|
return $view;
|
|
}
|
|
|
|
/**
|
|
* Routing end-point for application behavior.
|
|
*
|
|
* @param RequestAbstract $request Request
|
|
* @param ResponseAbstract $response Response
|
|
* @param array $data Generic data
|
|
*
|
|
* @return RenderableInterface
|
|
*
|
|
* @since 1.0.0
|
|
* @codeCoverageIgnore
|
|
*/
|
|
public function viewEquipmentManagementAttributeValueCreate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : RenderableInterface
|
|
{
|
|
$view = new \Modules\Attribute\Theme\Backend\Components\AttributeValueView($this->app->l11nManager, $request, $response);
|
|
$view->data['nav'] = $this->app->moduleManager->get('Navigation')->createNavigationMid(1008405001, $request, $response);
|
|
|
|
$view->type = EquipmentAttributeTypeMapper::get()->where('id', (int) $request->getData('type'))->execute();
|
|
$view->attribute = new NullAttributeValue();
|
|
|
|
$view->path = 'equipment';
|
|
|
|
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 viewEquipmentManagementInspectionCreate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : RenderableInterface
|
|
{
|
|
$view = new View($this->app->l11nManager, $request, $response);
|
|
|
|
$view->setTemplate('/Modules/EquipmentManagement/Theme/Backend/inspection-view');
|
|
$view->data['nav'] = $this->app->moduleManager->get('Navigation')->createNavigationMid(1003502001, $request, $response);
|
|
|
|
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 viewEquipmentManagementInspectionView(RequestAbstract $request, ResponseAbstract $response, array $data = []) : RenderableInterface
|
|
{
|
|
$view = new View($this->app->l11nManager, $request, $response);
|
|
|
|
$view->setTemplate('/Modules/EquipmentManagement/Theme/Backend/inspection-view');
|
|
$view->data['nav'] = $this->app->moduleManager->get('Navigation')->createNavigationMid(1003502001, $request, $response);
|
|
|
|
$view->data['inspections'] = InspectionMapper::getAll()
|
|
->where('id', (int) $request->getData('id'))
|
|
->executeGetArray();
|
|
|
|
return $view;
|
|
}
|
|
}
|