* initial commit
This commit is contained in:
182
src/App/Action/AbstractCrudAction.php
Normal file
182
src/App/Action/AbstractCrudAction.php
Normal file
@@ -0,0 +1,182 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Interop\Http\ServerMiddleware\MiddlewareInterface as ServerMiddlewareInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
use Zend\Json\Json;
|
||||
|
||||
abstract class AbstractCrudAction implements ServerMiddlewareInterface
|
||||
{
|
||||
const IDENTIFIER_NAME = 'id';
|
||||
const CORS_ALLOW_HEADERS = [
|
||||
'DNT',
|
||||
'X-CustomHeader',
|
||||
'Keep-Alive',
|
||||
'User-Agent',
|
||||
'X-Requested-With',
|
||||
'If-Modified-Since',
|
||||
'Cache-Control',
|
||||
'Content-Type',
|
||||
'Authorization',
|
||||
];
|
||||
|
||||
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
$requestMethod = strtoupper($request->getMethod());
|
||||
$id = $request->getAttribute(static::IDENTIFIER_NAME);
|
||||
|
||||
switch ($requestMethod) {
|
||||
case 'GET':
|
||||
return isset($id)
|
||||
? $this->get($request, $delegate)
|
||||
: $this->getList($request, $delegate);
|
||||
case 'POST':
|
||||
return $this->create($request, $delegate);
|
||||
case 'PUT':
|
||||
return $this->update($request, $delegate);
|
||||
case 'DELETE':
|
||||
return isset($id)
|
||||
? $this->delete($request, $delegate)
|
||||
: $this->deleteList($request, $delegate);
|
||||
case 'HEAD':
|
||||
return $this->head($request, $delegate);
|
||||
case 'OPTIONS':
|
||||
return $this->options($request, $delegate);
|
||||
case 'PATCH':
|
||||
return $this->patch($request, $delegate);
|
||||
default:
|
||||
return $delegate->process($request);
|
||||
}
|
||||
}
|
||||
|
||||
public function get(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->createResponse(['content' => 'Method not allowed'], 405);
|
||||
}
|
||||
|
||||
public function getList(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->createResponse(['content' => 'Method not allowed'], 405);
|
||||
}
|
||||
|
||||
public function create(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->createResponse(['content' => 'Method not allowed'], 405);
|
||||
}
|
||||
|
||||
public function update(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->createResponse(['content' => 'Method not allowed'], 405);
|
||||
}
|
||||
|
||||
public function delete(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->createResponse(['content' => 'Method not allowed'], 405);
|
||||
}
|
||||
|
||||
public function deleteList(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->createResponse(['content' => 'Method not allowed'], 405);
|
||||
}
|
||||
|
||||
public function head(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->createResponse(['content' => 'Method not allowed'], 405);
|
||||
}
|
||||
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->createResponse(['content' => 'Method not allowed'], 405);
|
||||
}
|
||||
|
||||
public function patch(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->createResponse(['content' => 'Method not allowed'], 405);
|
||||
}
|
||||
|
||||
final protected function createResponse($data, $status = 200)
|
||||
{
|
||||
return new JsonResponse($data, $status);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @return array|object
|
||||
*/
|
||||
public function getRequestData(ServerRequestInterface $request)
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
|
||||
if (!empty($body)) {
|
||||
return $body;
|
||||
}
|
||||
|
||||
return $this->parseRequestData(
|
||||
$request->getBody()->getContents(),
|
||||
$request->getHeaderLine('content-type')
|
||||
);
|
||||
}
|
||||
|
||||
protected function withCorsHeaders(ResponseInterface $response, iterable $methods = [])
|
||||
{
|
||||
if ($methods) {
|
||||
$methodsHeader = implode(',', $methods);
|
||||
$response = $response->withHeader('Accept', $methodsHeader)
|
||||
->withHeader('Access-Control-Allow-Methods', $methodsHeader);
|
||||
}
|
||||
return $response
|
||||
->withHeader('Access-Control-Allow-Origin', '*')
|
||||
->withHeader('Access-Control-Allow-Headers', implode(",", self::CORS_ALLOW_HEADERS));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $contentType
|
||||
* @return mixed
|
||||
*/
|
||||
private function parseRequestData($input, $contentType)
|
||||
{
|
||||
$contentTypeParts = preg_split('/\s*[;,]\s*/', $contentType);
|
||||
$parser = $this->returnParserContentType($contentTypeParts[0]);
|
||||
|
||||
return $parser($input);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $contentType
|
||||
* @return callable
|
||||
*/
|
||||
private function returnParserContentType(string $contentType)
|
||||
{
|
||||
if ($contentType === 'application/x-www-form-urlencoded') {
|
||||
return function ($input) {
|
||||
parse_str($input, $data);
|
||||
return $data;
|
||||
};
|
||||
} elseif ($contentType === 'application/json') {
|
||||
return function ($input) {
|
||||
$jsonDecoder = new Json();
|
||||
try {
|
||||
return $jsonDecoder->decode($input, Json::TYPE_ARRAY);
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
} elseif ($contentType === 'multipart/form-data') {
|
||||
return function ($input) {
|
||||
return $input;
|
||||
};
|
||||
}
|
||||
|
||||
return function ($input) {
|
||||
return $input;
|
||||
};
|
||||
}
|
||||
}
|
||||
83
src/App/Action/Auth/AuthAction.php
Normal file
83
src/App/Action/Auth/AuthAction.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Auth;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\AuthService;
|
||||
use Doctrine\ORM\NoResultException;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class AuthAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
'POST',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var AuthService
|
||||
*/
|
||||
private $authService;
|
||||
|
||||
public function __construct(AuthService $authService)
|
||||
{
|
||||
$this->authService = $authService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new auth token (login)
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response\JsonResponse
|
||||
*/
|
||||
public function create(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
$authData = $this->getRequestData($request);
|
||||
try {
|
||||
return new JsonCorsResponse($this->authService->authenticate($authData['login'], $authData['password']));
|
||||
} catch (NoResultException $e) {
|
||||
return new JsonCorsResponse([
|
||||
'message' => $e->getMessage()
|
||||
], 403);
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse([
|
||||
'message' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renew auth token
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response\JsonResponse
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
try {
|
||||
$token = $request->getAttribute('token', false);
|
||||
return new JsonCorsResponse($this->authService->renewToken($token));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse([
|
||||
'message' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return static
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
15
src/App/Action/Auth/AuthFactory.php
Normal file
15
src/App/Action/Auth/AuthFactory.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Auth;
|
||||
|
||||
use App\Service\AuthService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class AuthFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$faultManagerService = $container->get(AuthService::class);
|
||||
return new AuthAction($faultManagerService);
|
||||
}
|
||||
}
|
||||
51
src/App/Action/ErrorCategoryAction.php
Normal file
51
src/App/Action/ErrorCategoryAction.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\ErrorCategoryService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class ErrorCategoryAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var ErrorCategoryService
|
||||
*/
|
||||
private $errorCategoryService;
|
||||
|
||||
public function __construct(ErrorCategoryService $errorCategoryService)
|
||||
{
|
||||
$this->errorCategoryService = $errorCategoryService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all faults accessible to the user
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return new JsonCorsResponse($this->errorCategoryService->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
16
src/App/Action/ErrorCategoryFactory.php
Normal file
16
src/App/Action/ErrorCategoryFactory.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
|
||||
use App\Service\ErrorCategoryService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class ErrorCategoryFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
/** @var ErrorCategoryService $errorCategoryService */
|
||||
$errorCategoryService = $container->get(ErrorCategoryService::class);
|
||||
return new ErrorCategoryAction($errorCategoryService);
|
||||
}
|
||||
}
|
||||
51
src/App/Action/ErrorOriginAction.php
Normal file
51
src/App/Action/ErrorOriginAction.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\ErrorOriginService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class ErrorOriginAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var ErrorOriginService
|
||||
*/
|
||||
private $errorOriginService;
|
||||
|
||||
public function __construct(ErrorOriginService $errorOriginService)
|
||||
{
|
||||
$this->errorOriginService = $errorOriginService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all faults accessible to the user
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return new JsonCorsResponse($this->errorOriginService->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
16
src/App/Action/ErrorOriginFactory.php
Normal file
16
src/App/Action/ErrorOriginFactory.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
|
||||
use App\Service\ErrorOriginService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class ErrorOriginFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
/** @var ErrorOriginService $errorOriginService */
|
||||
$errorOriginService = $container->get(ErrorOriginService::class);
|
||||
return new ErrorOriginAction($errorOriginService);
|
||||
}
|
||||
}
|
||||
52
src/App/Action/FacilityLocationAction.php
Normal file
52
src/App/Action/FacilityLocationAction.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\FacilityLocationService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class FacilityLocationAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var FacilityLocationService
|
||||
*/
|
||||
private $facilityLocationService;
|
||||
|
||||
public function __construct(FacilityLocationService $facilityLocationService)
|
||||
{
|
||||
$this->facilityLocationService = $facilityLocationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all faults accessible to the user
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return new JsonCorsResponse($this->facilityLocationService->getFacilityLocationListFlat());
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
16
src/App/Action/FacilityLocationFactory.php
Normal file
16
src/App/Action/FacilityLocationFactory.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
|
||||
use App\Service\FacilityLocationService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class FacilityLocationFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
/** @var FacilityLocationService $facilityLocationService */
|
||||
$facilityLocationService = $container->get(FacilityLocationService::class);
|
||||
return new FacilityLocationAction($facilityLocationService);
|
||||
}
|
||||
}
|
||||
122
src/App/Action/Fault/FaultAction.php
Normal file
122
src/App/Action/Fault/FaultAction.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\FaultManagerService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class FaultAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
'POST',
|
||||
'PUT',
|
||||
'PATCH',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var FaultManagerService
|
||||
*/
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all faults accessible to the user
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return new JsonCorsResponse($this->faultManagerService->getFaultList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a single fault
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function get(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
$id = $request->getAttribute('id', false);
|
||||
return new JsonCorsResponse($this->faultManagerService->getFault($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Post a new fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function create(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
try {
|
||||
$data = $this->getRequestData($request);
|
||||
$token = $request->getAttribute('token');
|
||||
return new JsonCorsResponse($this->faultManagerService->createFault($data, $token->uid), 201);
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse($e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function update(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
try {
|
||||
$id = $request->getAttribute('id');
|
||||
$token = $request->getAttribute('token');
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonCorsResponse($this->faultManagerService->updateFault($id, $data, $token->uid));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse($e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a fault report (NYI)
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function delete(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
try {
|
||||
$id = $request->getAttribute('id');
|
||||
return new JsonCorsResponse($this->faultManagerService->deleteFault($id));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
104
src/App/Action/Fault/FaultAttachmentAction.php
Normal file
104
src/App/Action/Fault/FaultAttachmentAction.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\FaultAttachmentService;
|
||||
use App\Service\FaultManagerService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
use Zend\Diactoros\Stream;
|
||||
|
||||
class FaultAttachmentAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
'POST',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var FaultManagerService
|
||||
*/
|
||||
private $faultManagerService;
|
||||
|
||||
/**
|
||||
* @var FaultAttachmentService
|
||||
*/
|
||||
private $attachmentService;
|
||||
|
||||
public function __construct(
|
||||
FaultManagerService $faultManagerService,
|
||||
FaultAttachmentService $attachmentService
|
||||
) {
|
||||
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
$this->attachmentService = $attachmentService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Post a new fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function create(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
$faultId = $request->getAttribute('id');
|
||||
$type = $request->getAttribute('type', 'file');
|
||||
$token = $request->getAttribute('token');
|
||||
try {
|
||||
/** @var UploadedFileInterface[] $files */
|
||||
$files = $request->getUploadedFiles()['file'];
|
||||
return new JsonCorsResponse(
|
||||
$this->attachmentService->createAttachments($faultId, $files, $token->uid, $type),
|
||||
201
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse($e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return Response
|
||||
*/
|
||||
public function get(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
$id = $request->getAttribute('id');
|
||||
$attachment = $this->attachmentService->get($id);
|
||||
$stream = new Stream($attachment->getIoStream());
|
||||
switch ($attachment->getType()) {
|
||||
case 'image':
|
||||
$contentType = 'image/jpg';
|
||||
break;
|
||||
case 'expense':
|
||||
$contentType = 'application/pdf';
|
||||
break;
|
||||
default:
|
||||
$contentType = 'application/octet-stream';
|
||||
}
|
||||
$response = new Response($stream);
|
||||
return $response->withStatus(200)
|
||||
->withHeader('Content-type', $contentType)
|
||||
// ->withHeader('Content-disposition', 'attachment;filename='.$attachment->getFileName())
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
17
src/App/Action/Fault/FaultAttachmentFactory.php
Normal file
17
src/App/Action/Fault/FaultAttachmentFactory.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
|
||||
use App\Service\FaultAttachmentService;
|
||||
use App\Service\FaultManagerService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class FaultAttachmentFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$faultManagerService = $container->get(FaultManagerService::class);
|
||||
$attachmentService = $container->get(FaultAttachmentService::class);
|
||||
return new FaultAttachmentAction($faultManagerService, $attachmentService);
|
||||
}
|
||||
}
|
||||
59
src/App/Action/Fault/FaultCommentAction.php
Normal file
59
src/App/Action/Fault/FaultCommentAction.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\FaultManagerService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class FaultCommentAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'POST',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var FaultManagerService
|
||||
*/
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Post a new fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function create(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
$faultId = $request->getAttribute('id');
|
||||
$jwt = $request->getAttribute('token');
|
||||
try {
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonCorsResponse($this->faultManagerService->addFaultComment($faultId, $data, $jwt->uid), 201);
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
15
src/App/Action/Fault/FaultCommentFactory.php
Normal file
15
src/App/Action/Fault/FaultCommentFactory.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
|
||||
use App\Service\FaultManagerService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class FaultCommentFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$faultManagerService = $container->get(FaultManagerService::class);
|
||||
return new FaultCommentAction($faultManagerService);
|
||||
}
|
||||
}
|
||||
15
src/App/Action/Fault/FaultFactory.php
Normal file
15
src/App/Action/Fault/FaultFactory.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
|
||||
use App\Service\FaultManagerService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class FaultFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$faultManagerService = $container->get(FaultManagerService::class);
|
||||
return new FaultAction($faultManagerService);
|
||||
}
|
||||
}
|
||||
59
src/App/Action/Fault/FaultRejectAction.php
Normal file
59
src/App/Action/Fault/FaultRejectAction.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\FaultManagerService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class FaultRejectAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'POST',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var FaultManagerService
|
||||
*/
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Post a new fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function create(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
$faultId = $request->getAttribute('id');
|
||||
$jwt = $request->getAttribute('token');
|
||||
try {
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonCorsResponse($this->faultManagerService->rejectFault($faultId, $data, $jwt->uid), 201);
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse($e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
15
src/App/Action/Fault/FaultRejectFactory.php
Normal file
15
src/App/Action/Fault/FaultRejectFactory.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
|
||||
use App\Service\FaultManagerService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class FaultRejectFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$faultManagerService = $container->get(FaultManagerService::class);
|
||||
return new FaultRejectAction($faultManagerService);
|
||||
}
|
||||
}
|
||||
58
src/App/Action/Fault/FaultS2ConfirmAction.php
Normal file
58
src/App/Action/Fault/FaultS2ConfirmAction.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\FaultManagerService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class FaultS2ConfirmAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'PUT',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var FaultManagerService
|
||||
*/
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function update(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
try {
|
||||
$id = $request->getAttribute('id');
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonCorsResponse($this->faultManagerService->confirmFault($id, $data));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
58
src/App/Action/Fault/FaultS3AcknowledgeAction.php
Normal file
58
src/App/Action/Fault/FaultS3AcknowledgeAction.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\FaultManagerService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class FaultS3AcknowledgeAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'PUT',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var FaultManagerService
|
||||
*/
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function update(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
try {
|
||||
$id = $request->getAttribute('id');
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonCorsResponse($this->faultManagerService->ackFault($id, $data));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
58
src/App/Action/Fault/FaultS4RepairedAction.php
Normal file
58
src/App/Action/Fault/FaultS4RepairedAction.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\FaultManagerService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class FaultS4RepairedAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'PUT',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var FaultManagerService
|
||||
*/
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function update(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
try {
|
||||
$id = $request->getAttribute('id');
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonCorsResponse($this->faultManagerService->repairFault($id, $data));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
58
src/App/Action/Fault/FaultS5AcceptedAction.php
Normal file
58
src/App/Action/Fault/FaultS5AcceptedAction.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Fault;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\FaultManagerService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class FaultS5AcceptedAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'PUT',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var FaultManagerService
|
||||
*/
|
||||
private $faultManagerService;
|
||||
|
||||
public function __construct(FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->faultManagerService = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a fault report
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function update(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
try {
|
||||
$id = $request->getAttribute('id');
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonCorsResponse($this->faultManagerService->acceptFault($id, $data));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse($e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
68
src/App/Action/MaintenanceAction.php
Normal file
68
src/App/Action/MaintenanceAction.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\MaintenanceManagerService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
class MaintenanceAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
'POST',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var MaintenanceManagerService
|
||||
*/
|
||||
private $maintenanceManagerService;
|
||||
|
||||
public function __construct(MaintenanceManagerService $maintenanceManagerService)
|
||||
{
|
||||
$this->maintenanceManagerService = $maintenanceManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renew auth token
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response\JsonResponse
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return new JsonCorsResponse($this->maintenanceManagerService->getMaintenanceList()->getValues());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return JsonCorsResponse|\Zend\Diactoros\Response\JsonResponse
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
* @throws \Doctrine\ORM\TransactionRequiredException
|
||||
*/
|
||||
public function get(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
$hash = $request->getAttribute(self::IDENTIFIER_NAME);
|
||||
return new JsonCorsResponse($this->maintenanceManagerService->get($hash));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return JsonCorsResponse|\Zend\Diactoros\Response\JsonResponse
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
* @throws \Doctrine\ORM\TransactionRequiredException
|
||||
*/
|
||||
public function update(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
$hash = $request->getAttribute(self::IDENTIFIER_NAME);
|
||||
$data = $this->getRequestData($request);
|
||||
$jwt = $request->getAttribute('token');
|
||||
return new JsonCorsResponse($this->maintenanceManagerService->update($hash, $data, $jwt->uid));
|
||||
}
|
||||
}
|
||||
21
src/App/Action/MaintenanceFactory.php
Normal file
21
src/App/Action/MaintenanceFactory.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
|
||||
use App\Service\MaintenanceManagerService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class MaintenanceFactory
|
||||
{
|
||||
/**
|
||||
* @param ContainerInterface $container
|
||||
* @return MaintenanceAction
|
||||
* @throws \Psr\Container\ContainerExceptionInterface
|
||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
||||
*/
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$maintenanceManagerService = $container->get(MaintenanceManagerService::class);
|
||||
return new MaintenanceAction($maintenanceManagerService);
|
||||
}
|
||||
}
|
||||
37
src/App/Action/MaintenanceUpcomingAction.php
Normal file
37
src/App/Action/MaintenanceUpcomingAction.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\MaintenanceManagerService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
class MaintenanceUpcomingAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var MaintenanceManagerService
|
||||
*/
|
||||
private $maintenanceManagerService;
|
||||
|
||||
public function __construct(MaintenanceManagerService $maintenanceManagerService)
|
||||
{
|
||||
$this->maintenanceManagerService = $maintenanceManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renew auth token
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response\JsonResponse
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return new JsonCorsResponse($this->maintenanceManagerService->getUpcomingMaintenanceList()->getValues());
|
||||
}
|
||||
}
|
||||
21
src/App/Action/MaintenanceUpcomingFactory.php
Normal file
21
src/App/Action/MaintenanceUpcomingFactory.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
|
||||
use App\Service\MaintenanceManagerService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class MaintenanceUpcomingFactory
|
||||
{
|
||||
/**
|
||||
* @param ContainerInterface $container
|
||||
* @return MaintenanceUpcomingAction
|
||||
* @throws \Psr\Container\ContainerExceptionInterface
|
||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
||||
*/
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$maintenanceManagerService = $container->get(MaintenanceManagerService::class);
|
||||
return new MaintenanceUpcomingAction($maintenanceManagerService);
|
||||
}
|
||||
}
|
||||
63
src/App/Action/Pdf/GenerateMaintenanceSheetAction.php
Normal file
63
src/App/Action/Pdf/GenerateMaintenanceSheetAction.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Pdf;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Service\MaintenanceManagerService;
|
||||
use App\Service\PdfService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
use Zend\Diactoros\Response\TextResponse;
|
||||
|
||||
class GenerateMaintenanceSheetAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var PdfService
|
||||
*/
|
||||
private $pdfService;
|
||||
|
||||
/**
|
||||
* @var MaintenanceManagerService
|
||||
*/
|
||||
private $maintenanceManager;
|
||||
|
||||
public function __construct(PdfService $pdfService, MaintenanceManagerService $maintenanceManagerService)
|
||||
{
|
||||
$this->pdfService = $pdfService;
|
||||
$this->maintenanceManager = $maintenanceManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response\JsonResponse|TextResponse|static
|
||||
* @throws \PHPPdf\Core\PHPPdf\Exception\Exception
|
||||
*/
|
||||
public function get(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
$id = $request->getAttribute('id', false);
|
||||
try {
|
||||
return (new TextResponse($this->pdfService->getMaintenanceSheet($id)))
|
||||
->withHeader('Content-type', 'application/pdf');
|
||||
} catch (\Exception $e) {
|
||||
return new TextResponse($e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return static
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
25
src/App/Action/Pdf/GenerateMaintenanceSheetFactory.php
Normal file
25
src/App/Action/Pdf/GenerateMaintenanceSheetFactory.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Pdf;
|
||||
|
||||
use App\Service\MaintenanceManagerService;
|
||||
use App\Service\PdfService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class GenerateMaintenanceSheetFactory
|
||||
{
|
||||
/**
|
||||
* @param ContainerInterface $container
|
||||
* @return GenerateMaintenanceSheetAction
|
||||
* @throws \Psr\Container\ContainerExceptionInterface
|
||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
||||
*/
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
/** @var PdfService $pdfService */
|
||||
$pdfService = $container->get(PdfService::class);
|
||||
/** @var MaintenanceManagerService $maintenanceManagerService */
|
||||
$maintenanceManagerService = $container->get(MaintenanceManagerService::class);
|
||||
return new GenerateMaintenanceSheetAction($pdfService, $maintenanceManagerService);
|
||||
}
|
||||
}
|
||||
67
src/App/Action/Pdf/GenerateWorksheetAction.php
Normal file
67
src/App/Action/Pdf/GenerateWorksheetAction.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Pdf;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Service\FaultManagerService;
|
||||
use App\Service\PdfService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
use Zend\Diactoros\Response\TextResponse;
|
||||
|
||||
class GenerateWorksheetAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var PdfService
|
||||
*/
|
||||
private $pdfService;
|
||||
|
||||
/**
|
||||
* @var FaultManagerService
|
||||
*/
|
||||
private $faultManager;
|
||||
|
||||
public function __construct(PdfService $pdfService, FaultManagerService $faultManagerService)
|
||||
{
|
||||
$this->pdfService = $pdfService;
|
||||
$this->faultManager = $faultManagerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renew auth token
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function get(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
$id = $request->getAttribute('id', false);
|
||||
try {
|
||||
return (new TextResponse($this->pdfService->getWorksheet($id)))
|
||||
->withHeader('Content-type', 'application/pdf')
|
||||
// ->withHeader('Content-disposition', 'attachment; filename='
|
||||
// . $this->faultManager->getFault($id)->getWorksheetNumber() . '.pdf')
|
||||
;
|
||||
} catch (\Exception $e) {
|
||||
return new TextResponse($e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return static
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
19
src/App/Action/Pdf/GenerateWorksheetFactory.php
Normal file
19
src/App/Action/Pdf/GenerateWorksheetFactory.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\Pdf;
|
||||
|
||||
use App\Service\FaultManagerService;
|
||||
use App\Service\PdfService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class GenerateWorksheetFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
/** @var PdfService $pdfService */
|
||||
$pdfService = $container->get(PdfService::class);
|
||||
/** @var FaultManagerService $faultManager */
|
||||
$faultManager = $container->get(FaultManagerService::class);
|
||||
return new GenerateWorksheetAction($pdfService, $faultManager);
|
||||
}
|
||||
}
|
||||
16
src/App/Action/PingAction.php
Normal file
16
src/App/Action/PingAction.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
|
||||
use App\Response\JsonCorsResponse;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Interop\Http\ServerMiddleware\MiddlewareInterface as ServerMiddlewareInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
class PingAction implements ServerMiddlewareInterface
|
||||
{
|
||||
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return new JsonCorsResponse(['ack' => time()]);
|
||||
}
|
||||
}
|
||||
51
src/App/Action/SolutionTimeIntervalAction.php
Normal file
51
src/App/Action/SolutionTimeIntervalAction.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\SolutionTimeIntervalService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class SolutionTimeIntervalAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var SolutionTimeIntervalService
|
||||
*/
|
||||
private $solutionTimeIntervalService;
|
||||
|
||||
public function __construct(SolutionTimeIntervalService $facilityLocationService)
|
||||
{
|
||||
$this->solutionTimeIntervalService = $facilityLocationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all faults accessible to the user
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return new JsonCorsResponse($this->solutionTimeIntervalService->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate): Response
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
16
src/App/Action/SolutionTimeIntervalFactory.php
Normal file
16
src/App/Action/SolutionTimeIntervalFactory.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action;
|
||||
|
||||
use App\Service\SolutionTimeIntervalService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class SolutionTimeIntervalFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
/** @var SolutionTimeIntervalService $facilityLocationService */
|
||||
$facilityLocationService = $container->get(SolutionTimeIntervalService::class);
|
||||
return new SolutionTimeIntervalAction($facilityLocationService);
|
||||
}
|
||||
}
|
||||
57
src/App/Action/User/PasswordAction.php
Normal file
57
src/App/Action/User/PasswordAction.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\User;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\UserService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class PasswordAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'POST',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var UserService
|
||||
*/
|
||||
private $userService;
|
||||
|
||||
public function __construct(UserService $userService)
|
||||
{
|
||||
$this->userService = $userService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return JsonCorsResponse
|
||||
*/
|
||||
public function create(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
$token = $request->getAttribute('token');
|
||||
try {
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonCorsResponse($this->userService->changePassword($token->uid, $data['old'], $data['new']));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse([
|
||||
'message' => $e->getMessage()
|
||||
], $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return static
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
16
src/App/Action/User/PasswordFactory.php
Normal file
16
src/App/Action/User/PasswordFactory.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\User;
|
||||
|
||||
use App\Service\UserService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class PasswordFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
/** @var UserService $userService */
|
||||
$userService = $container->get(UserService::class);
|
||||
return new PasswordAction($userService);
|
||||
}
|
||||
}
|
||||
93
src/App/Action/User/UserAction.php
Normal file
93
src/App/Action/User/UserAction.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\User;
|
||||
|
||||
use App\Action\AbstractCrudAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\UserService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\EmptyResponse;
|
||||
|
||||
class UserAction extends AbstractCrudAction
|
||||
{
|
||||
const CORS_ALLOW_METHODS = [
|
||||
'GET',
|
||||
'PUT',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var UserService
|
||||
*/
|
||||
private $userService;
|
||||
|
||||
public function __construct(UserService $userService)
|
||||
{
|
||||
$this->userService = $userService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renew auth token
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return \Zend\Diactoros\Response\JsonResponse
|
||||
*/
|
||||
public function getList(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
try {
|
||||
return new JsonCorsResponse($this->userService->getList());
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse([
|
||||
'message' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return JsonCorsResponse
|
||||
*/
|
||||
public function get(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
$id = $request->getAttribute('id');
|
||||
try {
|
||||
return new JsonCorsResponse($this->userService->get($id));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse([
|
||||
'message' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return JsonCorsResponse
|
||||
*/
|
||||
public function update(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
$id = $request->getAttribute('id');
|
||||
try {
|
||||
$data = $this->getRequestData($request);
|
||||
return new JsonCorsResponse($this->userService->update($id, $data));
|
||||
} catch (\Exception $e) {
|
||||
return new JsonCorsResponse([
|
||||
'message' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure CORS preflight
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
* @param DelegateInterface $delegate
|
||||
* @return static
|
||||
*/
|
||||
public function options(ServerRequestInterface $request, DelegateInterface $delegate)
|
||||
{
|
||||
return $this->withCorsHeaders(new EmptyResponse(), self::CORS_ALLOW_METHODS);
|
||||
}
|
||||
}
|
||||
16
src/App/Action/User/UserFactory.php
Normal file
16
src/App/Action/User/UserFactory.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\User;
|
||||
|
||||
use App\Service\UserService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class UserFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
/** @var UserService $userService */
|
||||
$userService = $container->get(UserService::class);
|
||||
return new UserAction($userService);
|
||||
}
|
||||
}
|
||||
60
src/App/Command/ConvertMaintenanceHashCommand.php
Normal file
60
src/App/Command/ConvertMaintenanceHashCommand.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Entity\DeviceGroup;
|
||||
use App\Entity\DeviceMaintenanceTask;
|
||||
use App\Entity\Maintenance;
|
||||
use App\Service\MaintenanceManagerService;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class ConvertMaintenanceHashCommand extends Command
|
||||
{
|
||||
/** @var EntityManager */
|
||||
private $entityManager;
|
||||
|
||||
/** @var MaintenanceManagerService */
|
||||
private $maintenanceManager;
|
||||
|
||||
public function __construct(EntityManager $entityManager, MaintenanceManagerService $maintenanceManagerService)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
$this->maintenanceManager = $maintenanceManagerService;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('convert:hash')
|
||||
->setDescription('convert v1 hash to v2');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
* @return int|null|void
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
/** @var DeviceGroup[] $maintGroups */
|
||||
$maintGroups = $this->maintenanceManager->getMaintenanceList();
|
||||
|
||||
foreach ($maintGroups as $maintGroup) {
|
||||
foreach ($maintGroup->getDevices() as $device) {
|
||||
foreach ($device->getTasks() as $task) {
|
||||
if(null !== ($entity = $this->entityManager->getRepository(Maintenance::class)->findOneBy([
|
||||
'oldHash' => $task->getLegacyHash(),
|
||||
]))) {
|
||||
/** @var Maintenance $entity */
|
||||
$entity->setHash($task->getHash());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
}
|
||||
25
src/App/Command/ConvertMaintenanceHashCommandFactory.php
Normal file
25
src/App/Command/ConvertMaintenanceHashCommandFactory.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Service\MaintenanceManagerService;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class ConvertMaintenanceHashCommandFactory
|
||||
{
|
||||
/**
|
||||
* @param ContainerInterface $container
|
||||
* @return ConvertMaintenanceHashCommand
|
||||
* @throws \Psr\Container\ContainerExceptionInterface
|
||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
||||
*/
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
/** @var EntityManager $entityManager */
|
||||
$entityManager = $container->get('doctrine.entity_manager.orm_default');
|
||||
/** @var MaintenanceManagerService $maintenanceManager */
|
||||
$maintenanceManager = $container->get(MaintenanceManagerService::class);
|
||||
return new ConvertMaintenanceHashCommand($entityManager, $maintenanceManager);
|
||||
}
|
||||
}
|
||||
34
src/App/Command/InitializeFixtureCommand.php
Normal file
34
src/App/Command/InitializeFixtureCommand.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Service\FixtureLoaderService;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class InitializeFixtureCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @var FixtureLoaderService
|
||||
*/
|
||||
private $fixtureLoaderService;
|
||||
|
||||
public function __construct(FixtureLoaderService $fixtureLoaderService)
|
||||
{
|
||||
$this->fixtureLoaderService = $fixtureLoaderService;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('initialize:fixture')
|
||||
->setDescription('Loads data fixture into the database, replacing already existing data');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->fixtureLoaderService->load($output);
|
||||
}
|
||||
}
|
||||
16
src/App/Command/InitializeFixtureCommandFactory.php
Normal file
16
src/App/Command/InitializeFixtureCommandFactory.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Service\FixtureLoaderService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class InitializeFixtureCommandFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
/** @var FixtureLoaderService $fixtureLoaderService */
|
||||
$fixtureLoaderService = $container->get(FixtureLoaderService::class);
|
||||
return new InitializeFixtureCommand($fixtureLoaderService);
|
||||
}
|
||||
}
|
||||
33
src/App/Command/MailTestCommand.php
Normal file
33
src/App/Command/MailTestCommand.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Service\Mailer\MailerService;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class MailTestCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @var MailerService
|
||||
*/
|
||||
private $mailerService;
|
||||
|
||||
public function __construct(MailerService $mailerService)
|
||||
{
|
||||
$this->mailerService = $mailerService;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('mail:test')
|
||||
->setDescription('Test email');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->mailerService->sendTestMessage();
|
||||
}
|
||||
}
|
||||
16
src/App/Command/MailTestCommandFactory.php
Normal file
16
src/App/Command/MailTestCommandFactory.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Service\Mailer\MailerService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class MailTestCommandFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
/** @var MailerService $mailerService */
|
||||
$mailerService = $container->get(MailerService::class);
|
||||
return new MailTestCommand($mailerService);
|
||||
}
|
||||
}
|
||||
95
src/App/ConfigProvider.php
Normal file
95
src/App/ConfigProvider.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Monolog\Logger;
|
||||
|
||||
/**
|
||||
* The configuration provider for the App module
|
||||
*
|
||||
* @see https://docs.zendframework.com/zend-component-installer/
|
||||
*/
|
||||
class ConfigProvider
|
||||
{
|
||||
/**
|
||||
* Returns the configuration array
|
||||
*
|
||||
* To add a bit of a structure, each section is defined in a separate
|
||||
* method which returns an array with its configuration.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function __invoke()
|
||||
{
|
||||
return [
|
||||
'dependencies' => $this->getDependencies(),
|
||||
'templates' => $this->getTemplates(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the container dependencies
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDependencies()
|
||||
{
|
||||
return [
|
||||
'invokables' => [
|
||||
Action\PingAction::class => Action\PingAction::class,
|
||||
|
||||
],
|
||||
'factories' => [
|
||||
Action\MaintenanceAction::class => Action\MaintenanceFactory::class,
|
||||
Action\MaintenanceUpcomingAction::class => Action\MaintenanceUpcomingFactory::class,
|
||||
|
||||
Action\Auth\AuthAction::class => Action\Auth\AuthFactory::class,
|
||||
Action\User\UserAction::class => Action\User\UserFactory::class,
|
||||
Action\User\PasswordAction::class => Action\User\PasswordFactory::class,
|
||||
Action\Fault\FaultAction::class => Action\Fault\FaultFactory::class,
|
||||
Action\Fault\FaultAttachmentAction::class => Action\Fault\FaultAttachmentFactory::class,
|
||||
Action\Fault\FaultCommentAction::class => Action\Fault\FaultCommentFactory::class,
|
||||
Action\Fault\FaultRejectAction::class => Action\Fault\FaultRejectFactory::class,
|
||||
Action\ErrorOriginAction::class => Action\ErrorOriginFactory::class,
|
||||
Action\ErrorCategoryAction::class => Action\ErrorCategoryFactory::class,
|
||||
Action\FacilityLocationAction::class => Action\FacilityLocationFactory::class,
|
||||
Action\SolutionTimeIntervalAction::class => Action\SolutionTimeIntervalFactory::class,
|
||||
Action\Pdf\GenerateWorksheetAction::class => Action\Pdf\GenerateWorksheetFactory::class,
|
||||
Action\Pdf\GenerateMaintenanceSheetAction::class => Action\Pdf\GenerateMaintenanceSheetFactory::class,
|
||||
|
||||
Service\AuthService::class => Service\AuthServiceFactory::class,
|
||||
Service\UserService::class => Service\UserServiceFactory::class,
|
||||
Service\FaultManagerService::class => Service\FaultManagerServiceFactory::class,
|
||||
Service\FaultAttachmentService::class => Service\FaultAttachmentServiceFactory::class,
|
||||
Service\FixtureLoaderService::class => Service\FixtureLoaderServiceFactory::class,
|
||||
Service\ErrorCategoryService::class => Service\ErrorCategoryServiceFactory::class,
|
||||
Service\ErrorOriginService::class => Service\ErrorOriginServiceFactory::class,
|
||||
Service\FacilityLocationService::class => Service\FacilityLocationServiceFactory::class,
|
||||
Service\SolutionTimeIntervalService::class => Service\SolutionTimeIntervalServiceFactory::class,
|
||||
Service\PdfService::class => Service\PdfServiceFactory::class,
|
||||
Service\MailerService::class => Service\MailerServiceFactory::class,
|
||||
Service\MaintenanceManagerService::class => Service\MaintenanceManagerServiceFactory::class,
|
||||
Service\XlsxParserService::class => Service\XlsxParserServiceFactory::class,
|
||||
|
||||
'service.acl' => Service\RbaclFactory::class,
|
||||
Logger::class => Service\LoggerFactory::class,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the templates configuration
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTemplates()
|
||||
{
|
||||
return [
|
||||
'paths' => [
|
||||
'app' => ['templates/app'],
|
||||
'error' => ['templates/error'],
|
||||
'layout' => ['templates/layout'],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
346
src/App/Entity/Attachment.php
Normal file
346
src/App/Entity/Attachment.php
Normal file
@@ -0,0 +1,346 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Event\LifecycleEventArgs;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Imagine\Image\Box;
|
||||
use Imagine\Image\ImageInterface;
|
||||
use Imagine\Gd\Imagine;
|
||||
use JsonSerializable;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(
|
||||
* name="attachments",
|
||||
* indexes={
|
||||
* @ORM\Index(name="AT_type_idx", columns={"type"}),
|
||||
* @ORM\Index(name="AT_active_idx", columns={"active"})
|
||||
* }
|
||||
* )
|
||||
* @ORM\HasLifecycleCallbacks
|
||||
*/
|
||||
class Attachment implements JsonSerializable
|
||||
{
|
||||
|
||||
const MAX_PIXEL_SPREAD = 3200;
|
||||
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\GeneratedValue(strategy="IDENTITY")
|
||||
* @var int
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\JoinColumn(name="fault_id", nullable=false)
|
||||
* @ORM\ManyToOne(targetEntity="Fault", inversedBy="attachments")
|
||||
* @var Fault
|
||||
*/
|
||||
private $fault;
|
||||
|
||||
/**
|
||||
* @ORM\JoinColumn(name="user_id", nullable=false)
|
||||
* @ORM\ManyToOne(targetEntity="User", inversedBy="attachments")
|
||||
* @var User
|
||||
*/
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* Type can be image or invoice
|
||||
*
|
||||
* @ORM\Column(name="type", type="string", length=50, nullable=false)
|
||||
* @var string
|
||||
*/
|
||||
private $type = 'image';
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="active", type="boolean", options={"default": true})
|
||||
* @var bool
|
||||
*/
|
||||
private $active = true;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $rawFileData = null;
|
||||
|
||||
/**
|
||||
* Temporary variably, only used for entity postRemove hook
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $idPreDeleteTemp;
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return Attachment
|
||||
*/
|
||||
public function setId(int $id): Attachment
|
||||
{
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Fault
|
||||
*/
|
||||
public function getFault(): Fault
|
||||
{
|
||||
return $this->fault;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Fault $fault
|
||||
* @return Attachment
|
||||
*/
|
||||
public function setFault(Fault $fault)
|
||||
{
|
||||
$this->fault = $fault;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
public function getUser(): User
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @return Attachment
|
||||
*/
|
||||
public function setUser(User $user): Attachment
|
||||
{
|
||||
$this->user = $user;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @return Attachment
|
||||
*/
|
||||
public function setType(string $type): Attachment
|
||||
{
|
||||
$this->type = $type;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function getActive(): bool
|
||||
{
|
||||
return $this->active;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $active
|
||||
* @return Attachment
|
||||
*/
|
||||
public function setActive(bool $active): Attachment
|
||||
{
|
||||
$this->active = $active;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRawFileData(): string
|
||||
{
|
||||
return $this->rawFileData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $rawFileData
|
||||
* @return Attachment
|
||||
*/
|
||||
public function setRawFileData(string $rawFileData): Attachment
|
||||
{
|
||||
$this->rawFileData = $rawFileData;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\PrePersist
|
||||
* @return Attachment
|
||||
*/
|
||||
public function validatePrePersist(): Attachment
|
||||
{
|
||||
if ($this->getRawFileData() == null) {
|
||||
throw new \InvalidArgumentException("File data can't be empty");
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\PostPersist
|
||||
* @return Attachment
|
||||
*/
|
||||
public function saveOnPersist(): Attachment
|
||||
{
|
||||
if ($this->getType() == 'image') {
|
||||
return $this->saveDataAsImageFile($this->rawFileData);
|
||||
}
|
||||
|
||||
return $this->saveDataAsBinaryFile($this->rawFileData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\PreRemove
|
||||
* @return Attachment
|
||||
*/
|
||||
public function preDeleteHelper(): Attachment
|
||||
{
|
||||
$this->idPreDeleteTemp = $this->id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\PostRemove
|
||||
* @return Attachment
|
||||
*/
|
||||
public function deleteImage(): Attachment
|
||||
{
|
||||
unlink($this->getFileName($this->idPreDeleteTemp));
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $rawFileData
|
||||
* @return Attachment
|
||||
*/
|
||||
public function saveDataAsImageFile(string $rawFileData): Attachment
|
||||
{
|
||||
$folder = $this->getContainingFolder();
|
||||
if (!file_exists($folder)) {
|
||||
mkdir($folder, 0755, true);
|
||||
}
|
||||
|
||||
$extendedId = $this->getExtendedId();
|
||||
$pathSplit = str_split($extendedId, 3);
|
||||
$fileName = array_pop($pathSplit);
|
||||
$imagine = new Imagine();
|
||||
$image = $imagine->load($rawFileData);
|
||||
$originBox = $image->getSize();
|
||||
$originWidth = $originBox->getWidth();
|
||||
$originHeight = $originBox->getHeight();
|
||||
if ($originWidth > self::MAX_PIXEL_SPREAD || $originHeight > self::MAX_PIXEL_SPREAD) {
|
||||
if ($originWidth > $originHeight) {
|
||||
$newWidth = self::MAX_PIXEL_SPREAD;
|
||||
$newHeight = floor(self::MAX_PIXEL_SPREAD * $originHeight / $originWidth);
|
||||
} elseif ($originHeight > $originWidth) {
|
||||
$newWidth = floor(self::MAX_PIXEL_SPREAD * $originWidth / $originHeight);
|
||||
$newHeight = self::MAX_PIXEL_SPREAD;
|
||||
} else {
|
||||
$newWidth = self::MAX_PIXEL_SPREAD;
|
||||
$newHeight = self::MAX_PIXEL_SPREAD;
|
||||
}
|
||||
// $image->resize(new Box($newWidth, $newHeight), ImageInterface::FILTER_LANCZOS);
|
||||
$image->resize(new Box($newWidth, $newHeight));
|
||||
$image->effects()->sharpen();
|
||||
}
|
||||
$image->save(sprintf("%s/%s", $folder, $fileName), [
|
||||
'format' => 'jpeg',
|
||||
'jpeg_quality' => 80,
|
||||
]);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function saveDataAsBinaryFile(string $rawFileData): Attachment
|
||||
{
|
||||
$folder = $this->getContainingFolder();
|
||||
if (!file_exists($folder)) {
|
||||
mkdir($folder, 0755, true);
|
||||
}
|
||||
$pathSplit = str_split($this->getExtendedId(), 3);
|
||||
$fileName = array_pop($pathSplit);
|
||||
file_put_contents(sprintf("%s/%s", $folder, $fileName), $rawFileData);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return string
|
||||
*/
|
||||
private function getContainingFolder($id = null): string
|
||||
{
|
||||
$attachmentFolder = str_split($this->getExtendedId($id), 3);
|
||||
array_pop($attachmentFolder);
|
||||
return sprintf('data/attachments/%s', implode('/', $attachmentFolder));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function getExtendedId($id = null): string
|
||||
{
|
||||
if ($this->id == null && $id == null) {
|
||||
throw new \Exception("Entity must be persisted first.");
|
||||
}
|
||||
|
||||
return sprintf("%09d", $id ? $id : $this->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return string
|
||||
*/
|
||||
public function getFileName($id = null): string
|
||||
{
|
||||
$splitParts = str_split($this->getExtendedId($id), 3);
|
||||
$fileName = array_pop($splitParts);
|
||||
return sprintf("%s/%s", $this->getContainingFolder($id), $fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return resource
|
||||
*/
|
||||
public function getIoStream()
|
||||
{
|
||||
return fopen($this->getFileName(), 'r');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRawAttachmentData(): string
|
||||
{
|
||||
return file_get_contents($this->getFileName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return [
|
||||
'id' => $this->getId(),
|
||||
'type' => $this->getType(),
|
||||
'active' => $this->getActive(),
|
||||
'user' => $this->getUser(),
|
||||
];
|
||||
}
|
||||
}
|
||||
66
src/App/Entity/AuthResponse.php
Normal file
66
src/App/Entity/AuthResponse.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use JsonSerializable;
|
||||
|
||||
class AuthResponse implements JsonSerializable
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $message;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $token;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMessage(): string
|
||||
{
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
* @return AuthResponse
|
||||
*/
|
||||
public function setMessage(string $message): AuthResponse
|
||||
{
|
||||
$this->message = $message;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getToken(): string
|
||||
{
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $token
|
||||
* @return AuthResponse
|
||||
*/
|
||||
public function setToken(string $token): AuthResponse
|
||||
{
|
||||
$this->token = $token;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return [
|
||||
'message' => $this->getMessage(),
|
||||
'token' => $this->getToken(),
|
||||
];
|
||||
}
|
||||
}
|
||||
179
src/App/Entity/Device.php
Normal file
179
src/App/Entity/Device.php
Normal file
@@ -0,0 +1,179 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
class Device implements \JsonSerializable
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $responsible;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $count;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $workDescription;
|
||||
|
||||
/**
|
||||
* @var DeviceMaintenanceTask[]|ArrayCollection
|
||||
*/
|
||||
private $tasks;
|
||||
|
||||
/** @var DeviceGroup */
|
||||
private $group;
|
||||
|
||||
public function __construct(DeviceGroup $group)
|
||||
{
|
||||
$this->group = $group;
|
||||
$this->tasks = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return Device
|
||||
*/
|
||||
public function setName(string $name): Device
|
||||
{
|
||||
$this->name = trim($name);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getResponsible(): string
|
||||
{
|
||||
return $this->responsible;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $responsible
|
||||
* @return Device
|
||||
*/
|
||||
public function setResponsible(string $responsible): Device
|
||||
{
|
||||
$this->responsible = trim($responsible);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getCount(): int
|
||||
{
|
||||
return $this->count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $count
|
||||
* @return Device
|
||||
*/
|
||||
public function setCount(int $count): Device
|
||||
{
|
||||
$this->count = $count;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getWorkDescription(): string
|
||||
{
|
||||
return $this->workDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $workDescription
|
||||
* @return Device
|
||||
*/
|
||||
public function setWorkDescription(string $workDescription): Device
|
||||
{
|
||||
$this->workDescription = trim($workDescription);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DeviceMaintenanceTask[]|ArrayCollection
|
||||
*/
|
||||
public function getTasks(): ?ArrayCollection
|
||||
{
|
||||
return $this->tasks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DeviceMaintenanceTask[]|ArrayCollection $tasks
|
||||
* @return Device
|
||||
*/
|
||||
public function setTasks(ArrayCollection $tasks)
|
||||
{
|
||||
$this->tasks = $tasks;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DeviceMaintenanceTask $device
|
||||
* @return Device
|
||||
*/
|
||||
public function addTask(DeviceMaintenanceTask $device): Device
|
||||
{
|
||||
if (!$this->tasks->contains($device)) {
|
||||
$this->tasks->add($device);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DeviceMaintenanceTask $maintenanceTask
|
||||
* @return Device
|
||||
*/
|
||||
public function removeTask(DeviceMaintenanceTask $maintenanceTask): Device
|
||||
{
|
||||
if ($this->tasks->contains($maintenanceTask)) {
|
||||
$this->tasks->removeElement($maintenanceTask);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getGroup(): DeviceGroup
|
||||
{
|
||||
return $this->group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify data which should be serialized to JSON
|
||||
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
|
||||
* @return mixed data which can be serialized by <b>json_encode</b>,
|
||||
* which is a value of any type other than a resource.
|
||||
* @since 5.4.0
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return [
|
||||
'name' => $this->getName(),
|
||||
'count' => $this->getCount(),
|
||||
'responsible' => $this->getResponsible(),
|
||||
'workDescription' => $this->getWorkDescription(),
|
||||
'tasks' => $this->getTasks()->getValues(),
|
||||
];
|
||||
}
|
||||
}
|
||||
99
src/App/Entity/DeviceGroup.php
Normal file
99
src/App/Entity/DeviceGroup.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
class DeviceGroup implements \JsonSerializable
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @var Device[]|ArrayCollection
|
||||
*/
|
||||
private $devices;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->devices = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return DeviceGroup
|
||||
*/
|
||||
public function setName(string $name): DeviceGroup
|
||||
{
|
||||
$this->name = trim($name);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Device[]|ArrayCollection
|
||||
*/
|
||||
public function getDevices(): ArrayCollection
|
||||
{
|
||||
return $this->devices;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Device[]|ArrayCollection $devices
|
||||
* @return DeviceGroup
|
||||
*/
|
||||
public function setDevices($devices): DeviceGroup
|
||||
{
|
||||
$this->devices = $devices;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Device $device
|
||||
* @return DeviceGroup
|
||||
*/
|
||||
public function addDevice(Device $device): DeviceGroup
|
||||
{
|
||||
if (!$this->devices->contains($device)) {
|
||||
$this->devices->add($device);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Device $device
|
||||
* @return DeviceGroup
|
||||
*/
|
||||
public function removeDevice(Device $device): DeviceGroup
|
||||
{
|
||||
if ($this->devices->contains($device)) {
|
||||
$this->devices->removeElement($device);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify data which should be serialized to JSON
|
||||
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
|
||||
* @return mixed data which can be serialized by <b>json_encode</b>,
|
||||
* which is a value of any type other than a resource.
|
||||
* @since 5.4.0
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return [
|
||||
'name' => $this->getName(),
|
||||
'devices' => $this->getDevices()->getValues(),
|
||||
];
|
||||
}
|
||||
}
|
||||
247
src/App/Entity/DeviceMaintenanceTask.php
Normal file
247
src/App/Entity/DeviceMaintenanceTask.php
Normal file
@@ -0,0 +1,247 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
class DeviceMaintenanceTask implements \JsonSerializable
|
||||
{
|
||||
/** @var int */
|
||||
private $year;
|
||||
|
||||
/** @var int */
|
||||
private $month;
|
||||
|
||||
/** @var int */
|
||||
private $week;
|
||||
|
||||
/** @var int */
|
||||
private $workerCount;
|
||||
|
||||
/** @var float */
|
||||
private $timeCost;
|
||||
|
||||
/** @var \DateTime */
|
||||
private $shouldStartAt;
|
||||
|
||||
/** @var \DateTime */
|
||||
private $shouldBeDoneBy;
|
||||
|
||||
/** @var string */
|
||||
private $state = 'new';
|
||||
|
||||
/** @var Device */
|
||||
private $device;
|
||||
|
||||
public function __construct(Device $device)
|
||||
{
|
||||
$this->device = $device;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getYear(): int
|
||||
{
|
||||
return $this->year;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $year
|
||||
* @return DeviceMaintenanceTask
|
||||
*/
|
||||
public function setYear(int $year): DeviceMaintenanceTask
|
||||
{
|
||||
$this->year = $year;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getMonth(): int
|
||||
{
|
||||
return $this->month;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $month
|
||||
* @return DeviceMaintenanceTask
|
||||
*/
|
||||
public function setMonth(int $month): DeviceMaintenanceTask
|
||||
{
|
||||
$this->month = $month;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getWeek(): int
|
||||
{
|
||||
return $this->week;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $week
|
||||
* @return DeviceMaintenanceTask
|
||||
*/
|
||||
public function setWeek(int $week): DeviceMaintenanceTask
|
||||
{
|
||||
$this->week = $week;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getWorkerCount(): int
|
||||
{
|
||||
return $this->workerCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $workerCount
|
||||
* @return DeviceMaintenanceTask
|
||||
*/
|
||||
public function setWorkerCount(int $workerCount): DeviceMaintenanceTask
|
||||
{
|
||||
$this->workerCount = $workerCount;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getTimeCost(): float
|
||||
{
|
||||
return $this->timeCost;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $timeCost
|
||||
* @return DeviceMaintenanceTask
|
||||
*/
|
||||
public function setTimeCost(float $timeCost): DeviceMaintenanceTask
|
||||
{
|
||||
$this->timeCost = $timeCost;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getShouldStartAt(): \DateTime
|
||||
{
|
||||
return $this->shouldStartAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $shouldStartAt
|
||||
* @return DeviceMaintenanceTask
|
||||
*/
|
||||
public function setShouldStartAt(\DateTime $shouldStartAt): DeviceMaintenanceTask
|
||||
{
|
||||
$this->shouldStartAt = $shouldStartAt;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getShouldBeDoneBy(): \DateTime
|
||||
{
|
||||
return $this->shouldBeDoneBy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $shouldBeDoneBy
|
||||
* @return DeviceMaintenanceTask
|
||||
*/
|
||||
public function setShouldBeDoneBy(\DateTime $shouldBeDoneBy): DeviceMaintenanceTask
|
||||
{
|
||||
$this->shouldBeDoneBy = $shouldBeDoneBy;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isDone(): bool
|
||||
{
|
||||
return $this->state == 'fin';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getState(): string
|
||||
{
|
||||
return $this->state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $state
|
||||
* @return DeviceMaintenanceTask
|
||||
*/
|
||||
public function setState(string $state): DeviceMaintenanceTask
|
||||
{
|
||||
$this->state = $state;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* device.name + device.workDescription + task.month + task.week
|
||||
* @return string
|
||||
* @deprecated
|
||||
*/
|
||||
public function getLegacyHash(): string
|
||||
{
|
||||
$dirty = $this->device->getName()
|
||||
. $this->device->getWorkDescription()
|
||||
. $this->getMonth() . $this->getWeek();
|
||||
$cleanBaseName = str_replace(" ", "", $dirty);
|
||||
return md5($cleanBaseName);
|
||||
}
|
||||
|
||||
/**
|
||||
* year + device.name + device.workDescription + task.month + task.week
|
||||
* @return string
|
||||
*/
|
||||
public function getHash(): string
|
||||
{
|
||||
$dirty = $this->getYear()
|
||||
. sprintf('%02d', $this->getMonth()) . sprintf('%02d', $this->getWeek())
|
||||
. $this->device->getName()
|
||||
. $this->device->getWorkDescription();
|
||||
$cleanBaseName = str_replace(" ", "", $dirty);
|
||||
return md5($cleanBaseName);
|
||||
}
|
||||
|
||||
public function getDevice(): Device
|
||||
{
|
||||
return $this->device;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify data which should be serialized to JSON
|
||||
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
|
||||
* @return mixed data which can be serialized by <b>json_encode</b>,
|
||||
* which is a value of any type other than a resource.
|
||||
* @since 5.4.0
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return [
|
||||
'year' => $this->getYear(),
|
||||
'month' => $this->getMonth(),
|
||||
'week' => $this->getWeek(),
|
||||
'workerCount' => $this->getWorkerCount(),
|
||||
'timeCost' => $this->getTimeCost(),
|
||||
'shouldStartAt' => $this->getShouldStartAt()->format("Y-m-d"),
|
||||
'shouldBeDoneBy' => $this->getShouldBeDoneBy()->format("Y-m-d"),
|
||||
'done' => $this->isDone(),
|
||||
'state' => $this->getState(),
|
||||
'hash' => $this->getHash(),
|
||||
'legacyHash' => $this->getLegacyHash(),
|
||||
];
|
||||
}
|
||||
}
|
||||
154
src/App/Entity/ErrorCategory.php
Normal file
154
src/App/Entity/ErrorCategory.php
Normal file
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use JsonSerializable;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(
|
||||
* name="error_categories",
|
||||
* indexes={
|
||||
* @ORM\Index(name="EC_type_idx", columns={"type"}),
|
||||
* @ORM\Index(name="EC_active_idx", columns={"active"})
|
||||
* },
|
||||
* uniqueConstraints={
|
||||
* @ORM\UniqueConstraint(name="EC_name_idx", columns={"name"})
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class ErrorCategory implements JsonSerializable
|
||||
{
|
||||
|
||||
const TYPE_MACHINERY = 'machinery';
|
||||
const TYPE_ELECTRIC = 'electric';
|
||||
const TYPE_BUILDING = 'building';
|
||||
const TYPE_OTHER = 'other';
|
||||
|
||||
private $typeMap = [
|
||||
self::TYPE_MACHINERY => 'gépész',
|
||||
self::TYPE_ELECTRIC => 'elektromos',
|
||||
self::TYPE_BUILDING => 'építész',
|
||||
self::TYPE_OTHER => 'egyéb',
|
||||
];
|
||||
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\GeneratedValue(strategy="IDENTITY")
|
||||
* @var int
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="name", type="string", length=250, nullable=false)
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="type", type="string", length=10, nullable=false)
|
||||
* @var string
|
||||
*/
|
||||
private $type;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="active", type="boolean", options={"default": true})
|
||||
* @var bool
|
||||
*/
|
||||
private $active = true;
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return ErrorCategory
|
||||
*/
|
||||
public function setId(int $id): ErrorCategory
|
||||
{
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return ErrorCategory
|
||||
*/
|
||||
public function setName(string $name): ErrorCategory
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMappedType(): string
|
||||
{
|
||||
return $this->typeMap[$this->getType()];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @return ErrorCategory
|
||||
*/
|
||||
public function setType(string $type): ErrorCategory
|
||||
{
|
||||
$this->type = $type;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function getActive(): bool
|
||||
{
|
||||
return $this->active;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $active
|
||||
* @return ErrorCategory
|
||||
*/
|
||||
public function setActive(bool $active): ErrorCategory
|
||||
{
|
||||
$this->active = $active;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'type' => $this->type,
|
||||
'active' => $this->active,
|
||||
];
|
||||
}
|
||||
}
|
||||
134
src/App/Entity/ErrorOrigin.php
Normal file
134
src/App/Entity/ErrorOrigin.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use JsonSerializable;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(
|
||||
* name="error_origins",
|
||||
* indexes={
|
||||
* @ORM\Index(name="EO_active_idx", columns={"active"})
|
||||
* },
|
||||
* uniqueConstraints={
|
||||
* @ORM\UniqueConstraint(name="EO_name_idx", columns={"name"}),
|
||||
* @ORM\UniqueConstraint(name="EO_code_idx", columns={"code"})
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class ErrorOrigin implements JsonSerializable
|
||||
{
|
||||
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\GeneratedValue(strategy="IDENTITY")
|
||||
* @var int
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="code", type="string", length=1)
|
||||
* @var string
|
||||
*/
|
||||
private $code;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="name", type="string", length=150, nullable=false)
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="active", type="boolean", options={"default": true})
|
||||
* @var bool
|
||||
*/
|
||||
private $active = true;
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return ErrorOrigin
|
||||
*/
|
||||
public function setId(int $id)
|
||||
{
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCode(): string
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @return ErrorOrigin
|
||||
*/
|
||||
public function setCode(string $code): ErrorOrigin
|
||||
{
|
||||
$this->code = $code;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return ErrorOrigin
|
||||
*/
|
||||
public function setName(string $name): ErrorOrigin
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function getActive(): bool
|
||||
{
|
||||
return $this->active;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $active
|
||||
* @return ErrorOrigin
|
||||
*/
|
||||
public function setActive(bool $active): ErrorOrigin
|
||||
{
|
||||
$this->active = $active;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'code' => $this->code,
|
||||
'name' => $this->name,
|
||||
'active' => $this->active,
|
||||
];
|
||||
}
|
||||
}
|
||||
224
src/App/Entity/FacilityLocation.php
Normal file
224
src/App/Entity/FacilityLocation.php
Normal file
@@ -0,0 +1,224 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Gedmo\Mapping\Annotation as Gedmo;
|
||||
use JsonSerializable;
|
||||
|
||||
/**
|
||||
* @Gedmo\Tree(type="closure")
|
||||
* @Gedmo\TreeClosure(class="App\Entity\FacilityLocationClosure")
|
||||
* @ORM\Entity(repositoryClass="Gedmo\Tree\Entity\Repository\ClosureTreeRepository")
|
||||
* @ORM\Table(
|
||||
* name="facility_locations",
|
||||
* indexes={
|
||||
* @ORM\Index(name="FL_active_idx", columns={"active"}),
|
||||
* @ORM\Index(name="FL_name_idx", columns={"name"})
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class FacilityLocation implements JsonSerializable
|
||||
{
|
||||
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\GeneratedValue(strategy="IDENTITY")
|
||||
* @var int
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="room_number", type="string", length=10, nullable=false)
|
||||
* @var string
|
||||
*/
|
||||
private $roomNumber;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="name", type="string", length=250, nullable=false)
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="size", type="float", nullable=false)
|
||||
* @var float
|
||||
*/
|
||||
private $size;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="integer", nullable=true)
|
||||
* @Gedmo\TreeLevel
|
||||
* @var int
|
||||
*/
|
||||
private $level;
|
||||
|
||||
/**
|
||||
* @Gedmo\TreeParent
|
||||
* @ORM\JoinColumn(referencedColumnName="id", onDelete="CASCADE")
|
||||
* @ORM\ManyToOne(targetEntity="FacilityLocation", inversedBy="children")
|
||||
* @var FacilityLocation
|
||||
*/
|
||||
private $parent;
|
||||
|
||||
/**
|
||||
* @var FacilityLocationClosure[]
|
||||
*/
|
||||
private $closures = [];
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="active", type="boolean", options={"default": true})
|
||||
* @var bool
|
||||
*/
|
||||
private $active = true;
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return FacilityLocation
|
||||
*/
|
||||
public function setId(int $id): FacilityLocation
|
||||
{
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRoomNumber(): string
|
||||
{
|
||||
return $this->roomNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $roomNumber
|
||||
* @return FacilityLocation
|
||||
*/
|
||||
public function setRoomNumber(string $roomNumber): FacilityLocation
|
||||
{
|
||||
$this->roomNumber = $roomNumber;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return FacilityLocation
|
||||
*/
|
||||
public function setName(string $name): FacilityLocation
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getSize(): float
|
||||
{
|
||||
return $this->size;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $size
|
||||
* @return FacilityLocation
|
||||
*/
|
||||
public function setSize(float $size): FacilityLocation
|
||||
{
|
||||
$this->size = $size;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getLevel()
|
||||
{
|
||||
return $this->level;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $level
|
||||
* @return FacilityLocation
|
||||
*/
|
||||
public function setLevel($level)
|
||||
{
|
||||
$this->level = $level;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
return $this->parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $parent
|
||||
* @return FacilityLocation
|
||||
*/
|
||||
public function setParent($parent)
|
||||
{
|
||||
$this->parent = $parent;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FacilityLocationClosure $closure
|
||||
*/
|
||||
public function addClosure(FacilityLocationClosure $closure)
|
||||
{
|
||||
$this->closures[] = $closure;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function getActive(): bool
|
||||
{
|
||||
return $this->active;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $active
|
||||
* @return FacilityLocation
|
||||
*/
|
||||
public function setActive(bool $active): FacilityLocation
|
||||
{
|
||||
$this->active = $active;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return [
|
||||
'id' => $this->getId(),
|
||||
'roomNumber' => $this->getRoomNumber(),
|
||||
'name' => $this->getName(),
|
||||
'size' => $this->getSize(),
|
||||
'level' => $this->getLevel(),
|
||||
'active' => $this->getActive(),
|
||||
];
|
||||
}
|
||||
}
|
||||
15
src/App/Entity/FacilityLocationClosure.php
Normal file
15
src/App/Entity/FacilityLocationClosure.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Gedmo\Tree\Entity\MappedSuperclass\AbstractClosure;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="facility_locations__closure")
|
||||
*/
|
||||
class FacilityLocationClosure extends AbstractClosure
|
||||
{
|
||||
|
||||
}
|
||||
940
src/App/Entity/Fault.php
Normal file
940
src/App/Entity/Fault.php
Normal file
@@ -0,0 +1,940 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Gedmo\Mapping\Annotation as Gedmo;
|
||||
use JsonSerializable;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(
|
||||
* name="fault",
|
||||
* indexes={
|
||||
* @ORM\Index(name="F_facilityloc_idx", columns={"facility_location_id"}),
|
||||
* @ORM\Index(name="F_errorcat_idx", columns={"error_category_id"}),
|
||||
* @ORM\Index(name="F_errororig_idx", columns={"error_origin_id"}),
|
||||
* @ORM\Index(name="F_soltimeinterval_idx", columns={"solution_time_interval_id"})
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class Fault implements JsonSerializable
|
||||
{
|
||||
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\GeneratedValue(strategy="IDENTITY")
|
||||
* @var int
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="worksheet_number", type="string", length=30, nullable=true)
|
||||
* @var string
|
||||
*/
|
||||
private $worksheetNumber;
|
||||
|
||||
/**
|
||||
* @ORM\JoinColumn(name="facility_location_id", nullable=false)
|
||||
* @ORM\ManyToOne(targetEntity="FacilityLocation", inversedBy="faults")
|
||||
* @var FacilityLocation
|
||||
*/
|
||||
private $facilityLocation;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="facility_location_description", type="text", length=65535, nullable=true)
|
||||
* @var string
|
||||
*/
|
||||
private $facilityLocationDescription;
|
||||
|
||||
/**
|
||||
* @ORM\JoinColumn(name="error_category_id", nullable=false)
|
||||
* @ORM\ManyToOne(targetEntity="ErrorCategory", inversedBy="faults")
|
||||
* @var ErrorCategory
|
||||
*/
|
||||
private $errorCategory;
|
||||
|
||||
/**
|
||||
* @ORM\JoinColumn(name="error_origin_id", nullable=false)
|
||||
* @ORM\ManyToOne(targetEntity="ErrorOrigin", inversedBy="faults")
|
||||
* @var ErrorOrigin
|
||||
*/
|
||||
private $errorOrigin;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="error_description", type="text", length=65535, nullable=true)
|
||||
* @var string
|
||||
*/
|
||||
private $errorDescription;
|
||||
|
||||
/**
|
||||
* @ORM\JoinColumn(name="solution_time_interval_id", nullable=false)
|
||||
* @ORM\ManyToOne(targetEntity="SolutionTimeInterval", inversedBy="faults")
|
||||
* @var SolutionTimeInterval
|
||||
*/
|
||||
private $solutionTimeInterval;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="solution_time_interval_other", type="text", length=65535, nullable=true)
|
||||
* @var string
|
||||
*/
|
||||
private $solutionTimeIntervalOther;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="state", type="string", length=15, nullable=true)
|
||||
* @var string
|
||||
*/
|
||||
private $state = "new";
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Attachment", mappedBy="fault")
|
||||
* @var Attachment[]
|
||||
*/
|
||||
private $attachments;
|
||||
|
||||
/**
|
||||
* @ORM\JoinColumn(name="reporter_id", nullable=true)
|
||||
* @ORM\ManyToOne(targetEntity="User", inversedBy="reportedFaults")
|
||||
* @var User
|
||||
*/
|
||||
private $reporter;
|
||||
|
||||
/**
|
||||
* @ORM\JoinColumn(name="worker_id", nullable=true)
|
||||
* @ORM\ManyToOne(targetEntity="User", inversedBy="workingOnFaults")
|
||||
* @var User
|
||||
*/
|
||||
private $worker;
|
||||
|
||||
/**
|
||||
* @ORM\JoinColumn(name="confirmer_id", nullable=true)
|
||||
* @ORM\ManyToOne(targetEntity="User", inversedBy="confirmedFaults")
|
||||
* @var User
|
||||
*/
|
||||
private $confirmer;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="confirmed_at", type="datetime", nullable=true)
|
||||
* @var \DateTime
|
||||
*/
|
||||
private $confirmedAt;
|
||||
|
||||
/**
|
||||
* @ORM\JoinColumn(name="acknowledger_id", nullable=true)
|
||||
* @ORM\ManyToOne(targetEntity="User", inversedBy="acknowledgedFaults")
|
||||
* @var User
|
||||
*/
|
||||
private $acknowledgedBy;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="acknowledged_at", type="datetime", nullable=true)
|
||||
* @var \DateTime
|
||||
*/
|
||||
private $acknowledgedAt;
|
||||
|
||||
/**
|
||||
* @ORM\JoinColumn(name="approver_id", nullable=true)
|
||||
* @ORM\ManyToOne(targetEntity="User", inversedBy="approvedFaults")
|
||||
* @var User
|
||||
*/
|
||||
private $approvedBy;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="approved_at", type="datetime", nullable=true)
|
||||
* @var \DateTime
|
||||
*/
|
||||
private $approvedAt;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="report_accepted", type="datetime", nullable=true)
|
||||
* @var \DateTime
|
||||
* @todo possibly unused
|
||||
*/
|
||||
private $reportAccepted;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="work_started", type="datetime", nullable=true)
|
||||
* @var \DateTime
|
||||
*/
|
||||
private $workStarted;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="work_finished", type="datetime", nullable=true)
|
||||
* @var \DateTime
|
||||
*/
|
||||
private $workFinished;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="time_spent", type="float", nullable=true)
|
||||
* @var float
|
||||
*/
|
||||
private $timeSpent;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="work_cost_estimate", type="integer", nullable=true)
|
||||
* @var int
|
||||
*/
|
||||
private $workCostEstimate;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="material_cost_estimate", type="integer", nullable=true)
|
||||
* @var int
|
||||
*/
|
||||
private $materialCostEstimate;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="used_materials", type="array", length=65535, nullable=true)
|
||||
* @var mixed
|
||||
*/
|
||||
private $usedMaterials;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="work_done", type="array", length=65535, nullable=true)
|
||||
* @var mixed
|
||||
*/
|
||||
private $workDone;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="created_at", type="datetime", nullable=true)
|
||||
* @Gedmo\Timestampable(on="create")
|
||||
* @var \DateTime
|
||||
*/
|
||||
private $createdAt;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="FaultSnapshot", mappedBy="fault")
|
||||
* @var FaultSnapshot[]
|
||||
*/
|
||||
private $snapshots;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="FaultComment", mappedBy="fault")
|
||||
* @var FaultComment[]
|
||||
*/
|
||||
private $comments;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="must_lower_cost", type="boolean", options={"default": false})
|
||||
* @var bool
|
||||
*/
|
||||
private $mustLowerCost = false;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="allocated_expense", type="integer", options={"default": 0})
|
||||
* @var int
|
||||
*/
|
||||
private $allocatedExpense = 0;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->attachments = new ArrayCollection();
|
||||
$this->snapshots = new ArrayCollection();
|
||||
$this->comments = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return Fault
|
||||
*/
|
||||
public function setId(int $id): Fault
|
||||
{
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getWorksheetNumber(): ?string
|
||||
{
|
||||
return $this->worksheetNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $worksheetNumber
|
||||
* @return Fault
|
||||
*/
|
||||
public function setWorksheetNumber(?string $worksheetNumber): Fault
|
||||
{
|
||||
$this->worksheetNumber = $worksheetNumber;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FacilityLocation
|
||||
*/
|
||||
public function getFacilityLocation(): FacilityLocation
|
||||
{
|
||||
return $this->facilityLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FacilityLocation $facilityLocation
|
||||
* @return Fault
|
||||
*/
|
||||
public function setFacilityLocation(FacilityLocation $facilityLocation): Fault
|
||||
{
|
||||
$this->facilityLocation = $facilityLocation;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFacilityLocationDescription()
|
||||
{
|
||||
return $this->facilityLocationDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $facilityLocationDescription
|
||||
* @return Fault
|
||||
*/
|
||||
public function setFacilityLocationDescription(string $facilityLocationDescription): Fault
|
||||
{
|
||||
$this->facilityLocationDescription = $facilityLocationDescription;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ErrorCategory
|
||||
*/
|
||||
public function getErrorCategory(): ErrorCategory
|
||||
{
|
||||
return $this->errorCategory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ErrorCategory $errorCategory
|
||||
* @return Fault
|
||||
*/
|
||||
public function setErrorCategory(ErrorCategory $errorCategory): Fault
|
||||
{
|
||||
$this->errorCategory = $errorCategory;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ErrorOrigin
|
||||
*/
|
||||
public function getErrorOrigin(): ErrorOrigin
|
||||
{
|
||||
return $this->errorOrigin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ErrorOrigin $errorOrigin
|
||||
* @return Fault
|
||||
*/
|
||||
public function setErrorOrigin(ErrorOrigin $errorOrigin): Fault
|
||||
{
|
||||
$this->errorOrigin = $errorOrigin;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getErrorDescription()
|
||||
{
|
||||
return $this->errorDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $errorDescription
|
||||
* @return Fault
|
||||
*/
|
||||
public function setErrorDescription(string $errorDescription): Fault
|
||||
{
|
||||
$this->errorDescription = $errorDescription;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SolutionTimeInterval
|
||||
*/
|
||||
public function getSolutionTimeInterval(): SolutionTimeInterval
|
||||
{
|
||||
return $this->solutionTimeInterval;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SolutionTimeInterval $solutionTimeInterval
|
||||
* @return Fault
|
||||
*/
|
||||
public function setSolutionTimeInterval(SolutionTimeInterval $solutionTimeInterval): Fault
|
||||
{
|
||||
$this->solutionTimeInterval = $solutionTimeInterval;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSolutionTimeIntervalOther()
|
||||
{
|
||||
return $this->solutionTimeIntervalOther;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $solutionTimeIntervalOther
|
||||
* @return Fault
|
||||
*/
|
||||
public function setSolutionTimeIntervalOther(string $solutionTimeIntervalOther): Fault
|
||||
{
|
||||
$this->solutionTimeIntervalOther = $solutionTimeIntervalOther;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getState(): string
|
||||
{
|
||||
return $this->state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $state
|
||||
* @return Fault
|
||||
*/
|
||||
public function setState(string $state): Fault
|
||||
{
|
||||
$this->state = $state;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ArrayCollection
|
||||
*/
|
||||
public function getAttachments()
|
||||
{
|
||||
return $this->attachments;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
* @return Fault
|
||||
*/
|
||||
public function addAttachment(Attachment $attachment): Fault
|
||||
{
|
||||
$this->attachments->add($attachment);
|
||||
$attachment->setFault($this);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addAttachments(Collection $attachments): Fault
|
||||
{
|
||||
foreach ($attachments as $attachment) {
|
||||
$this->addAttachment($attachment);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Attachment $attachment
|
||||
* @return Fault
|
||||
*/
|
||||
public function removeAttachment(Attachment $attachment): Fault
|
||||
{
|
||||
$this->attachments->removeElement($attachment);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeAttachments(Collection $attachments): Fault
|
||||
{
|
||||
foreach ($attachments as $attachment) {
|
||||
$this->removeAttachment($attachment);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
public function getReporter()
|
||||
{
|
||||
return $this->reporter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $reporter
|
||||
* @return Fault
|
||||
*/
|
||||
public function setReporter(User $reporter)
|
||||
{
|
||||
$this->reporter = $reporter;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
public function getWorker()
|
||||
{
|
||||
return $this->worker;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $worker
|
||||
* @return Fault
|
||||
*/
|
||||
public function setWorker($worker)
|
||||
{
|
||||
$this->worker = $worker;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
public function getConfirmer(): ?User
|
||||
{
|
||||
return $this->confirmer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $confirmer
|
||||
* @return Fault
|
||||
*/
|
||||
public function setConfirmer(?User $confirmer): Fault
|
||||
{
|
||||
$this->confirmer = $confirmer;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getConfirmedAt(): ?\DateTime
|
||||
{
|
||||
return $this->confirmedAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $confirmedAt
|
||||
* @return Fault
|
||||
*/
|
||||
public function setConfirmedAt(?\DateTime $confirmedAt): Fault
|
||||
{
|
||||
$this->confirmedAt = $confirmedAt;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
public function getAcknowledgedBy(): ?User
|
||||
{
|
||||
return $this->acknowledgedBy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $acknowledgedBy
|
||||
* @return Fault
|
||||
*/
|
||||
public function setAcknowledgedBy(?User $acknowledgedBy): Fault
|
||||
{
|
||||
$this->acknowledgedBy = $acknowledgedBy;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getAcknowledgedAt(): ?\DateTime
|
||||
{
|
||||
return $this->acknowledgedAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $acknowledgedAt
|
||||
* @return Fault
|
||||
*/
|
||||
public function setAcknowledgedAt(?\DateTime $acknowledgedAt): Fault
|
||||
{
|
||||
$this->acknowledgedAt = $acknowledgedAt;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
public function getApprovedBy(): ?User
|
||||
{
|
||||
return $this->approvedBy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $approvedBy
|
||||
* @return Fault
|
||||
*/
|
||||
public function setApprovedBy(?User $approvedBy): Fault
|
||||
{
|
||||
$this->approvedBy = $approvedBy;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getApprovedAt(): ?\DateTime
|
||||
{
|
||||
return $this->approvedAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $approvedAt
|
||||
* @return Fault
|
||||
*/
|
||||
public function setApprovedAt(?\DateTime $approvedAt): Fault
|
||||
{
|
||||
$this->approvedAt = $approvedAt;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getReportAccepted(): ?\DateTime
|
||||
{
|
||||
return $this->reportAccepted;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $reportAccepted
|
||||
* @return Fault
|
||||
*/
|
||||
public function setReportAccepted(?\DateTime $reportAccepted): Fault
|
||||
{
|
||||
$this->reportAccepted = $reportAccepted;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getWorkStarted()
|
||||
{
|
||||
return $this->workStarted;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $workStarted
|
||||
* @return Fault
|
||||
*/
|
||||
public function setWorkStarted(\DateTime $workStarted): Fault
|
||||
{
|
||||
$this->workStarted = $workStarted;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getWorkFinished()
|
||||
{
|
||||
return $this->workFinished;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $workFinished
|
||||
* @return Fault
|
||||
*/
|
||||
public function setWorkFinished(\DateTime $workFinished): Fault
|
||||
{
|
||||
$this->workFinished = $workFinished;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getTimeSpent(): ?float
|
||||
{
|
||||
return $this->timeSpent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $timeSpent
|
||||
* @return Fault
|
||||
*/
|
||||
public function setTimeSpent(?float $timeSpent): Fault
|
||||
{
|
||||
$this->timeSpent = $timeSpent;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getWorkCostEstimate(): ?int
|
||||
{
|
||||
return $this->workCostEstimate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $workCostEstimate
|
||||
* @return Fault
|
||||
*/
|
||||
public function setWorkCostEstimate(?int $workCostEstimate): Fault
|
||||
{
|
||||
$this->workCostEstimate = $workCostEstimate;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getMaterialCostEstimate(): ?int
|
||||
{
|
||||
return $this->materialCostEstimate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $materialCostEstimate
|
||||
* @return Fault
|
||||
*/
|
||||
public function setMaterialCostEstimate(?int $materialCostEstimate): Fault
|
||||
{
|
||||
$this->materialCostEstimate = $materialCostEstimate;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getUsedMaterials()
|
||||
{
|
||||
return $this->usedMaterials;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $usedMaterials
|
||||
* @return Fault
|
||||
*/
|
||||
public function setUsedMaterials($usedMaterials)
|
||||
{
|
||||
$this->usedMaterials = $usedMaterials;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getWorkDone()
|
||||
{
|
||||
return $this->workDone;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $workDone
|
||||
* @return Fault
|
||||
*/
|
||||
public function setWorkDone($workDone)
|
||||
{
|
||||
$this->workDone = $workDone;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getCreatedAt()
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $createdAt
|
||||
* @return Fault
|
||||
*/
|
||||
public function setCreatedAt(\DateTime $createdAt): Fault
|
||||
{
|
||||
$this->createdAt = $createdAt;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ArrayCollection
|
||||
*/
|
||||
public function getSnapshots()
|
||||
{
|
||||
return $this->snapshots;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return ArrayCollection
|
||||
*/
|
||||
public function getComments()
|
||||
{
|
||||
return $this->comments;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FaultComment $comment
|
||||
* @return Fault
|
||||
*/
|
||||
public function addComment(FaultComment $comment): Fault
|
||||
{
|
||||
if (!$this->comments->contains($comment)) {
|
||||
$this->comments->add($comment);
|
||||
$comment->setFault($this);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addComments(Collection $comments): Fault
|
||||
{
|
||||
foreach ($comments as $comment) {
|
||||
$this->addComment($comment);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FaultComment $comment
|
||||
* @return Fault
|
||||
*/
|
||||
public function removeComment(FaultComment $comment): Fault
|
||||
{
|
||||
if ($this->comments->contains($comment)) {
|
||||
$this->comments->removeElement($comment);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeComments(Collection $comments): Fault
|
||||
{
|
||||
foreach ($comments as $comment) {
|
||||
$this->removeComment($comment);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isMustLowerCost(): ?bool
|
||||
{
|
||||
return $this->mustLowerCost;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $mustLowerCost
|
||||
* @return Fault
|
||||
*/
|
||||
public function setMustLowerCost(?bool $mustLowerCost): Fault
|
||||
{
|
||||
$this->mustLowerCost = $mustLowerCost;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getAllocatedExpense(): ?int
|
||||
{
|
||||
return $this->allocatedExpense;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $allocatedExpense
|
||||
* @return Fault
|
||||
*/
|
||||
public function setAllocatedExpense(?int $allocatedExpense): Fault
|
||||
{
|
||||
$this->allocatedExpense = $allocatedExpense;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'facilityLocation' => $this->getFacilityLocation(),
|
||||
'facilityLocationDescription' => $this->getFacilityLocationDescription(),
|
||||
'errorCategory' => $this->getErrorCategory(),
|
||||
'errorOrigin' => $this->getErrorOrigin(),
|
||||
'errorDescription' => $this->getErrorDescription(),
|
||||
'solutionTimeInterval' => $this->getSolutionTimeInterval(),
|
||||
'solutionTimeIntervalOther' => $this->getSolutionTimeIntervalOther(),
|
||||
'state' => $this->getState(),
|
||||
'attachments' => $this->getAttachments()->getValues() ?? [],
|
||||
'worker' => $this->getWorker(),
|
||||
'confirmer' => $this->getConfirmer(),
|
||||
'confirmedAt' => $this->getConfirmedAt(),
|
||||
'acknowledgedBy' => $this->getAcknowledgedBy(),
|
||||
'acknowledgedAt' => $this->getAcknowledgedAt(),
|
||||
'approvedBy' => $this->getApprovedBy(),
|
||||
'approvedAt' => $this->getApprovedAt(),
|
||||
'reportAccepted' => $this->getReportAccepted(),
|
||||
'workStarted' => $this->getWorkStarted(),
|
||||
'workFinished' => $this->getWorkFinished(),
|
||||
'worksheetNumber' => $this->getWorksheetNumber(),
|
||||
'timeSpent' => $this->getTimeSpent(),
|
||||
'workCostEstimate' => $this->getWorkCostEstimate(),
|
||||
'materialCostEstimate' => $this->getMaterialCostEstimate(),
|
||||
'usedMaterials' => $this->getUsedMaterials() ?? [],
|
||||
'workDone' => $this->getWorkDone() ?? [],
|
||||
'createdAt' => $this->getCreatedAt(),
|
||||
'faultSnapshots' => $this->getSnapshots()->toArray() ?? [],
|
||||
'comments' => $this->getComments()->toArray() ?? [],
|
||||
'mustLowerCost' => $this->isMustLowerCost(),
|
||||
'allocatedExpense' => $this->getAllocatedExpense(),
|
||||
];
|
||||
}
|
||||
|
||||
public function getFlatValues()
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'facilityLocation' => $this->getFacilityLocation()->getId(),
|
||||
'facilityLocationDescription' => $this->getFacilityLocationDescription(),
|
||||
'errorCategory' => $this->getErrorCategory()->getId(),
|
||||
'errorOrigin' => $this->getErrorOrigin()->getId(),
|
||||
'errorDescription' => $this->getErrorDescription(),
|
||||
'solutionTimeInterval' => $this->getSolutionTimeInterval()->getId(),
|
||||
'solutionTimeIntervalOther' => $this->getSolutionTimeIntervalOther(),
|
||||
'state' => $this->getState(),
|
||||
'attachments' => $this->getAttachments()->getValues() ?? [],
|
||||
'worker' => $this->getWorker() ? $this->getWorker()->getId() : null,
|
||||
'confirmer' => $this->getConfirmer() ? $this->getConfirmer()->getId() : null,
|
||||
'confirmedAt' => $this->getConfirmedAt(),
|
||||
'acknowledgedBy' => $this->getAcknowledgedBy() ? $this->getAcknowledgedBy()->getId() : null,
|
||||
'acknowledgedAt' => $this->getAcknowledgedAt(),
|
||||
'approvedBy' => $this->getApprovedBy() ? $this->getApprovedBy()->getId() : null,
|
||||
'approvedAt' => $this->getApprovedAt(),
|
||||
'reportAccepted' => $this->getReportAccepted(),
|
||||
'workStarted' => $this->getWorkStarted(),
|
||||
'workFinished' => $this->getWorkFinished(),
|
||||
'worksheetNumber' => $this->getWorksheetNumber(),
|
||||
'timeSpent' => $this->getTimeSpent(),
|
||||
'workCostEstimate' => $this->getWorkCostEstimate(),
|
||||
'materialCostEstimate' => $this->getMaterialCostEstimate(),
|
||||
'usedMaterials' => $this->getUsedMaterials() ?? [],
|
||||
'workDone' => $this->getWorkDone() ?? [],
|
||||
'createdAt' => $this->getCreatedAt(),
|
||||
'faultSnapshots' => $this->getSnapshots()->toArray() ?? [],
|
||||
'comments' => $this->getComments()->toArray() ?? [],
|
||||
'mustLowerCost' => $this->isMustLowerCost(),
|
||||
'allocatedExpense' => $this->getAllocatedExpense(),
|
||||
];
|
||||
}
|
||||
}
|
||||
164
src/App/Entity/FaultComment.php
Normal file
164
src/App/Entity/FaultComment.php
Normal file
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Gedmo\Mapping\Annotation as Gedmo;
|
||||
use JsonSerializable;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(
|
||||
* name="fault_comments",
|
||||
* indexes={
|
||||
* @ORM\Index(name="FS_created_at", columns={"created_at"})
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class FaultComment implements JsonSerializable
|
||||
{
|
||||
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\GeneratedValue(strategy="IDENTITY")
|
||||
* @var int
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\JoinColumn(name="fault_id", nullable=false)
|
||||
* @ORM\ManyToOne(targetEntity="Fault", inversedBy="comments")
|
||||
* @var Fault
|
||||
*/
|
||||
private $fault;
|
||||
|
||||
/**
|
||||
* @ORM\JoinColumn(name="user_id", nullable=false)
|
||||
* @ORM\ManyToOne(targetEntity="User", inversedBy="faultComments")
|
||||
* @var User
|
||||
*/
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="comment", type="text", length=65535, nullable=true)
|
||||
* @var string
|
||||
*/
|
||||
private $comment;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="created_at", type="datetime", nullable=true)
|
||||
* @Gedmo\Timestampable(on="create")
|
||||
* @var \DateTime
|
||||
*/
|
||||
private $createdAt;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return FaultComment
|
||||
*/
|
||||
public function setId(int $id): FaultComment
|
||||
{
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Fault
|
||||
*/
|
||||
public function getFault(): Fault
|
||||
{
|
||||
return $this->fault;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Fault $fault
|
||||
* @return FaultComment
|
||||
*/
|
||||
public function setFault(Fault $fault): FaultComment
|
||||
{
|
||||
$this->fault = $fault;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
public function getUser(): User
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @return FaultComment
|
||||
*/
|
||||
public function setUser(User $user): FaultComment
|
||||
{
|
||||
$this->user = $user;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getComment(): string
|
||||
{
|
||||
return $this->comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $comment
|
||||
* @return FaultComment
|
||||
*/
|
||||
public function setComment(string $comment): FaultComment
|
||||
{
|
||||
$this->comment = $comment;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getCreatedAt(): \DateTime
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $createdAt
|
||||
* @return FaultComment
|
||||
*/
|
||||
public function setCreatedAt(\DateTime $createdAt): FaultComment
|
||||
{
|
||||
$this->createdAt = $createdAt;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'user' => $this->getUser(),
|
||||
'comment' => $this->getComment(),
|
||||
'createdAt' => $this->getCreatedAt(),
|
||||
];
|
||||
}
|
||||
}
|
||||
239
src/App/Entity/FaultSnapshot.php
Normal file
239
src/App/Entity/FaultSnapshot.php
Normal file
@@ -0,0 +1,239 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Gedmo\Mapping\Annotation as Gedmo;
|
||||
use JsonSerializable;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(
|
||||
* name="fault_snapshot",
|
||||
* indexes={
|
||||
* @ORM\Index(name="FS_oldstate_idx", columns={"old_state"}),
|
||||
* @ORM\Index(name="FS_newstate_idx", columns={"new_state"})
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class FaultSnapshot implements JsonSerializable
|
||||
{
|
||||
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\GeneratedValue(strategy="IDENTITY")
|
||||
* @var int
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\JoinColumn(name="fault_id", nullable=false)
|
||||
* @ORM\ManyToOne(targetEntity="Fault", inversedBy="snapshots")
|
||||
* @var Fault
|
||||
*/
|
||||
private $fault;
|
||||
|
||||
/**
|
||||
* @ORM\JoinColumn(name="user_id", nullable=false)
|
||||
* @ORM\ManyToOne(targetEntity="User", inversedBy="faultSnapshots")
|
||||
* @var User
|
||||
*/
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="old_state", type="string", length=15, nullable=true)
|
||||
* @var string
|
||||
*/
|
||||
private $oldState;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="new_state", type="string", length=15, nullable=true)
|
||||
* @var string
|
||||
*/
|
||||
private $newState;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="payload", type="json", length=65535, nullable=true)
|
||||
* @var mixed
|
||||
*/
|
||||
private $payload;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="comment", type="text", length=65535, nullable=true)
|
||||
* @var string
|
||||
*/
|
||||
private $comment;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="created_at", type="datetime", nullable=true)
|
||||
* @Gedmo\Timestampable(on="create")
|
||||
* @var \DateTime
|
||||
*/
|
||||
private $createdAt;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return FaultSnapshot
|
||||
*/
|
||||
public function setId(int $id): FaultSnapshot
|
||||
{
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Fault
|
||||
*/
|
||||
public function getFault(): Fault
|
||||
{
|
||||
return $this->fault;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Fault $fault
|
||||
* @return FaultSnapshot
|
||||
*/
|
||||
public function setFault(Fault $fault): FaultSnapshot
|
||||
{
|
||||
$this->fault = $fault;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
public function getUser(): User
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @return FaultSnapshot
|
||||
*/
|
||||
public function setUser(User $user): FaultSnapshot
|
||||
{
|
||||
$this->user = $user;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getOldState(): ?string
|
||||
{
|
||||
return $this->oldState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $oldState
|
||||
* @return FaultSnapshot
|
||||
*/
|
||||
public function setOldState(string $oldState): FaultSnapshot
|
||||
{
|
||||
$this->oldState = $oldState;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getNewState(): ?string
|
||||
{
|
||||
return $this->newState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $newState
|
||||
* @return FaultSnapshot
|
||||
*/
|
||||
public function setNewState(string $newState): FaultSnapshot
|
||||
{
|
||||
$this->newState = $newState;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPayload()
|
||||
{
|
||||
return $this->payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $payload
|
||||
* @return FaultSnapshot
|
||||
*/
|
||||
public function setPayload($payload)
|
||||
{
|
||||
$this->payload = $payload;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getComment(): ?string
|
||||
{
|
||||
return $this->comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $comment
|
||||
* @return FaultSnapshot
|
||||
*/
|
||||
public function setComment(string $comment): FaultSnapshot
|
||||
{
|
||||
$this->comment = $comment;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCreatedAt(): ?\DateTime
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $createdAt
|
||||
* @return FaultSnapshot
|
||||
*/
|
||||
public function setCreatedAt(\DateTime $createdAt)
|
||||
{
|
||||
$this->createdAt = $createdAt;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'user' => $this->getUser(),
|
||||
'oldState' => $this->getOldState(),
|
||||
'newState' => $this->getNewState(),
|
||||
'payload' => $this->getPayload(),
|
||||
'comment' => $this->getComment(),
|
||||
'createdAt' => $this->getCreatedAt(),
|
||||
];
|
||||
}
|
||||
}
|
||||
649
src/App/Entity/Maintenance.php
Normal file
649
src/App/Entity/Maintenance.php
Normal file
@@ -0,0 +1,649 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Gedmo\Mapping\Annotation as Gedmo;
|
||||
use JsonSerializable;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(
|
||||
* name="maintenance"
|
||||
* )
|
||||
*/
|
||||
class Maintenance implements JsonSerializable
|
||||
{
|
||||
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(name="hash", type="string", length=250, nullable=false)
|
||||
* @var string
|
||||
*/
|
||||
private $hash;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="old_hash", type="string", length=250)
|
||||
* @var string
|
||||
*/
|
||||
private $oldHash;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="device_name", type="string", length=250, nullable=true)
|
||||
* @var string
|
||||
*/
|
||||
private $deviceName;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="component_name", type="string", length=250, nullable=true)
|
||||
* @var string
|
||||
*/
|
||||
private $componentName;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="responsible", type="string", length=250, nullable=true)
|
||||
* @var string
|
||||
*/
|
||||
private $responsible;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="work_description", type="text", length=5000, nullable=true)
|
||||
* @var string
|
||||
*/
|
||||
private $workDescription;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="device_count", type="integer")
|
||||
* @var int
|
||||
*/
|
||||
private $count;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="work_year", type="integer")
|
||||
* @var int
|
||||
*/
|
||||
private $year;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="work_month", type="integer")
|
||||
* @var int
|
||||
*/
|
||||
private $month;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="work_week", type="integer")
|
||||
* @var int
|
||||
*/
|
||||
private $week;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="worker_count", type="integer")
|
||||
* @var int
|
||||
*/
|
||||
private $workerCount;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="time_cost", type="float")
|
||||
* @var float
|
||||
*/
|
||||
private $timeCost;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="should_start_at", type="datetime", nullable=true)
|
||||
* @var \DateTime
|
||||
*/
|
||||
private $shouldStartAt;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="should_be_done_by", type="datetime", nullable=true)
|
||||
* @var \DateTime
|
||||
*/
|
||||
private $shouldBeDoneBy;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="state", type="string", length=15, nullable=true)
|
||||
* @var string
|
||||
*/
|
||||
private $state = "new";
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="worksheet_number", type="string", length=30, nullable=true)
|
||||
* @var string
|
||||
*/
|
||||
private $worksheetNumber;
|
||||
|
||||
/**
|
||||
* @ORM\JoinColumn(name="worker_id", nullable=true)
|
||||
* @ORM\ManyToOne(targetEntity="User", inversedBy="workingOnMaintenances")
|
||||
* @var User
|
||||
*/
|
||||
private $worker;
|
||||
|
||||
/**
|
||||
* @ORM\JoinColumn(name="approver_id", nullable=true)
|
||||
* @ORM\ManyToOne(targetEntity="User", inversedBy="approvedMaintenances")
|
||||
* @var User
|
||||
*/
|
||||
private $approvedBy;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="approved_at", type="datetime", nullable=true)
|
||||
* @var \DateTime
|
||||
*/
|
||||
private $approvedAt;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="work_started", type="datetime", nullable=true)
|
||||
* @var \DateTime
|
||||
*/
|
||||
private $workStarted;
|
||||
|
||||
/**
|
||||
* @ORM\JoinColumn(name="started_by", nullable=true)
|
||||
* @ORM\ManyToOne(targetEntity="User", inversedBy="startedMaintenances")
|
||||
* @var User
|
||||
*/
|
||||
private $startedBy;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="work_finished", type="datetime", nullable=true)
|
||||
* @var \DateTime
|
||||
*/
|
||||
private $workFinished;
|
||||
|
||||
/**
|
||||
* @ORM\JoinColumn(name="finished_by", nullable=true)
|
||||
* @ORM\ManyToOne(targetEntity="User", inversedBy="finishedMaintenances")
|
||||
* @var User
|
||||
*/
|
||||
private $finishedBy;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getHash(): string
|
||||
{
|
||||
return $this->hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $hash
|
||||
* @return Maintenance
|
||||
*/
|
||||
public function setHash(string $hash): Maintenance
|
||||
{
|
||||
$this->hash = $hash;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getOldHash(): string
|
||||
{
|
||||
return $this->oldHash;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $oldHash
|
||||
* @return Maintenance
|
||||
*/
|
||||
public function setOldHash(string $oldHash): Maintenance
|
||||
{
|
||||
$this->oldHash = $oldHash;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDeviceName(): string
|
||||
{
|
||||
return $this->deviceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $deviceName
|
||||
* @return Maintenance
|
||||
*/
|
||||
public function setDeviceName(string $deviceName): Maintenance
|
||||
{
|
||||
$this->deviceName = $deviceName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getComponentName(): string
|
||||
{
|
||||
return $this->componentName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $componentName
|
||||
* @return Maintenance
|
||||
*/
|
||||
public function setComponentName(string $componentName): Maintenance
|
||||
{
|
||||
$this->componentName = $componentName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getResponsible(): string
|
||||
{
|
||||
return $this->responsible;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $responsible
|
||||
* @return Maintenance
|
||||
*/
|
||||
public function setResponsible(string $responsible): Maintenance
|
||||
{
|
||||
$this->responsible = $responsible;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getWorkDescription(): string
|
||||
{
|
||||
return $this->workDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $workDescription
|
||||
* @return Maintenance
|
||||
*/
|
||||
public function setWorkDescription(string $workDescription): Maintenance
|
||||
{
|
||||
$this->workDescription = $workDescription;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getCount(): int
|
||||
{
|
||||
return $this->count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $count
|
||||
* @return Maintenance
|
||||
*/
|
||||
public function setCount(int $count): Maintenance
|
||||
{
|
||||
$this->count = $count;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getYear(): int
|
||||
{
|
||||
return $this->year;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $year
|
||||
* @return Maintenance
|
||||
*/
|
||||
public function setYear(int $year): Maintenance
|
||||
{
|
||||
$this->year = $year;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getMonth(): int
|
||||
{
|
||||
return $this->month;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $month
|
||||
* @return Maintenance
|
||||
*/
|
||||
public function setMonth(int $month): Maintenance
|
||||
{
|
||||
$this->month = $month;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getWeek(): int
|
||||
{
|
||||
return $this->week;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $week
|
||||
* @return Maintenance
|
||||
*/
|
||||
public function setWeek(int $week): Maintenance
|
||||
{
|
||||
$this->week = $week;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getWorkerCount(): int
|
||||
{
|
||||
return $this->workerCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $workerCount
|
||||
* @return Maintenance
|
||||
*/
|
||||
public function setWorkerCount(int $workerCount): Maintenance
|
||||
{
|
||||
$this->workerCount = $workerCount;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getTimeCost(): float
|
||||
{
|
||||
return $this->timeCost;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $timeCost
|
||||
* @return Maintenance
|
||||
*/
|
||||
public function setTimeCost(float $timeCost): Maintenance
|
||||
{
|
||||
$this->timeCost = $timeCost;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getShouldStartAt(): \DateTime
|
||||
{
|
||||
return $this->shouldStartAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $shouldStartAt
|
||||
* @return Maintenance
|
||||
*/
|
||||
public function setShouldStartAt(\DateTime $shouldStartAt): Maintenance
|
||||
{
|
||||
$this->shouldStartAt = $shouldStartAt;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getShouldBeDoneBy(): \DateTime
|
||||
{
|
||||
return $this->shouldBeDoneBy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $shouldBeDoneBy
|
||||
* @return Maintenance
|
||||
*/
|
||||
public function setShouldBeDoneBy(\DateTime $shouldBeDoneBy): Maintenance
|
||||
{
|
||||
$this->shouldBeDoneBy = $shouldBeDoneBy;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getWorksheetNumber(): ?string
|
||||
{
|
||||
return $this->worksheetNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $worksheetNumber
|
||||
* @return Maintenance
|
||||
*/
|
||||
public function setWorksheetNumber(?string $worksheetNumber): Maintenance
|
||||
{
|
||||
$this->worksheetNumber = $worksheetNumber;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getState(): string
|
||||
{
|
||||
return $this->state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $state
|
||||
* @return Maintenance
|
||||
*/
|
||||
public function setState(string $state): Maintenance
|
||||
{
|
||||
$this->state = $state;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
public function getWorker()
|
||||
{
|
||||
return $this->worker;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $worker
|
||||
* @return Maintenance
|
||||
*/
|
||||
public function setWorker($worker): Maintenance
|
||||
{
|
||||
$this->worker = $worker;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
public function getApprovedBy(): ?User
|
||||
{
|
||||
return $this->approvedBy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $approvedBy
|
||||
* @return Maintenance
|
||||
*/
|
||||
public function setApprovedBy(?User $approvedBy): Maintenance
|
||||
{
|
||||
$this->approvedBy = $approvedBy;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getApprovedAt(): ?\DateTime
|
||||
{
|
||||
return $this->approvedAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $approvedAt
|
||||
* @return Maintenance
|
||||
*/
|
||||
public function setApprovedAt(?\DateTime $approvedAt): Maintenance
|
||||
{
|
||||
$this->approvedAt = $approvedAt;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getWorkStarted(): ?\DateTime
|
||||
{
|
||||
return $this->workStarted;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $workStarted
|
||||
* @return Maintenance
|
||||
*/
|
||||
public function setWorkStarted(?\DateTime $workStarted): Maintenance
|
||||
{
|
||||
$this->workStarted = $workStarted;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
public function getStartedBy(): ?User
|
||||
{
|
||||
return $this->startedBy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $startedBy
|
||||
* @return Maintenance
|
||||
*/
|
||||
public function setStartedBy(User $startedBy): Maintenance
|
||||
{
|
||||
$this->startedBy = $startedBy;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getWorkFinished(): ?\DateTime
|
||||
{
|
||||
return $this->workFinished;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $workFinished
|
||||
* @return Maintenance
|
||||
*/
|
||||
public function setWorkFinished(?\DateTime $workFinished): Maintenance
|
||||
{
|
||||
$this->workFinished = $workFinished;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
public function getFinishedBy(): ?User
|
||||
{
|
||||
return $this->finishedBy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $finishedBy
|
||||
* @return Maintenance
|
||||
*/
|
||||
public function setFinishedBy(User $finishedBy): Maintenance
|
||||
{
|
||||
$this->finishedBy = $finishedBy;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
$formatString = "Y-m-d H:i";
|
||||
return [
|
||||
'hash' => $this->getHash(),
|
||||
'deviceName' => $this->getDeviceName(),
|
||||
'componentName' => $this->getComponentName(),
|
||||
'responsible' => $this->getResponsible(),
|
||||
'workDescription' => $this->getWorkDescription(),
|
||||
'count' => $this->getCount(),
|
||||
'year' => $this->getYear(),
|
||||
'month' => $this->getMonth(),
|
||||
'week' => $this->getWeek(),
|
||||
'workerCount' => $this->getWorkerCount(),
|
||||
'timeCost' => $this->getTimeCost(),
|
||||
'shouldStartAt' => $this->getShouldStartAt()
|
||||
? $this->getShouldStartAt()->format($formatString) : null,
|
||||
'shouldBeDoneBy' => $this->getShouldBeDoneBy()
|
||||
? $this->getShouldBeDoneBy()->format($formatString) : null,
|
||||
'state' => $this->getState(),
|
||||
'worker' => $this->getWorker(),
|
||||
'approvedBy' => $this->getApprovedBy(),
|
||||
'approvedAt' => $this->getApprovedAt()
|
||||
? $this->getApprovedAt()->format($formatString) : null,
|
||||
'workStarted' => $this->getWorkStarted()
|
||||
? $this->getWorkStarted()->format($formatString) : null,
|
||||
'staretedBy' => $this->getStartedBy(),
|
||||
'workFinished' => $this->getWorkFinished()
|
||||
? $this->getWorkFinished()->format($formatString) : null,
|
||||
'finishedBy' => $this->getFinishedBy(),
|
||||
'worksheetNumber' => $this->getWorksheetNumber(),
|
||||
];
|
||||
}
|
||||
|
||||
public function getFlatValues()
|
||||
{
|
||||
$formatString = "Y-m-d H:i";
|
||||
return [
|
||||
'hash' => $this->getHash(),
|
||||
'deviceName' => $this->getDeviceName(),
|
||||
'componentName' => $this->getComponentName(),
|
||||
'responsible' => $this->getResponsible(),
|
||||
'workDescription' => $this->getWorkDescription(),
|
||||
'count' => $this->getCount(),
|
||||
'year' => $this->getYear(),
|
||||
'month' => $this->getMonth(),
|
||||
'week' => $this->getWeek(),
|
||||
'workerCount' => $this->getWorkerCount(),
|
||||
'timeCost' => $this->getTimeCost(),
|
||||
'shouldStartAt' => $this->getShouldStartAt()
|
||||
? $this->getShouldStartAt()->format($formatString) : null,
|
||||
'shouldBeDoneBy' => $this->getShouldBeDoneBy()
|
||||
? $this->getShouldBeDoneBy()->format($formatString) : null,
|
||||
'state' => $this->getState(),
|
||||
'worker' => $this->getWorker() ? $this->getWorker()->getId() : null,
|
||||
'approvedBy' => $this->getApprovedBy() ? $this->getApprovedBy()->getId() : null,
|
||||
'approvedAt' => $this->getApprovedAt()
|
||||
? $this->getApprovedAt()->format($formatString) : null,
|
||||
'workStarted' => $this->getWorkStarted()
|
||||
? $this->getWorkStarted()->format($formatString) : null,
|
||||
'staretedBy' => $this->getStartedBy(),
|
||||
'workFinished' => $this->getWorkFinished()
|
||||
? $this->getWorkFinished()->format($formatString) : null,
|
||||
'finishedBy' => $this->getFinishedBy(),
|
||||
'worksheetNumber' => $this->getWorksheetNumber(),
|
||||
];
|
||||
}
|
||||
}
|
||||
133
src/App/Entity/SolutionTimeInterval.php
Normal file
133
src/App/Entity/SolutionTimeInterval.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use JsonSerializable;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(
|
||||
* name="solution_time_intervals",
|
||||
* indexes={
|
||||
* @ORM\Index(name="ST_active_idx", columns={"active"})
|
||||
* },
|
||||
* uniqueConstraints={
|
||||
* @ORM\UniqueConstraint(name="ST_name_idx", columns={"name"})
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class SolutionTimeInterval implements JsonSerializable
|
||||
{
|
||||
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\GeneratedValue(strategy="IDENTITY")
|
||||
* @var int
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="name", type="string", length=150, nullable=false)
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="code", type="string", length=2, nullable=false)
|
||||
* @var string
|
||||
*/
|
||||
private $code;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="active", type="boolean", options={"default": true})
|
||||
* @var bool
|
||||
*/
|
||||
private $active = true;
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return SolutionTimeInterval
|
||||
*/
|
||||
public function setId(int $id): SolutionTimeInterval
|
||||
{
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return SolutionTimeInterval
|
||||
*/
|
||||
public function setName(string $name): SolutionTimeInterval
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCode(): string
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @return SolutionTimeInterval
|
||||
*/
|
||||
public function setCode(string $code): SolutionTimeInterval
|
||||
{
|
||||
$this->code = $code;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function getActive(): bool
|
||||
{
|
||||
return $this->active;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $active
|
||||
* @return SolutionTimeInterval
|
||||
*/
|
||||
public function setActive(bool $active): SolutionTimeInterval
|
||||
{
|
||||
$this->active = $active;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'code' => $this->code,
|
||||
'active' => $this->active,
|
||||
];
|
||||
}
|
||||
}
|
||||
354
src/App/Entity/User.php
Normal file
354
src/App/Entity/User.php
Normal file
@@ -0,0 +1,354 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use JsonSerializable;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(
|
||||
* name="user",
|
||||
* indexes={
|
||||
* @ORM\Index(name="U_search_idx", columns={"name", "email"}),
|
||||
* @ORM\Index(name="U_wants_eml_idx", columns={"wants_email"}),
|
||||
* @ORM\Index(name="U_pwmc_idx", columns={"password_must_change"}),
|
||||
* @ORM\Index(name="U_canpwchng_idx", columns={"can_change_password"}),
|
||||
* @ORM\Index(name="U_active_idx", columns={"active"})
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class User implements JsonSerializable
|
||||
{
|
||||
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\GeneratedValue(strategy="IDENTITY")
|
||||
* @var int
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="name", type="string", length=150, nullable=false)
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="email", type="string", length=150, nullable=false)
|
||||
* @var string
|
||||
*/
|
||||
private $email;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="wants_email", type="boolean", options={"default": true})
|
||||
* @var bool
|
||||
*/
|
||||
private $wantsEmail;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="job", type="string", length=150, nullable=true)
|
||||
* @var string
|
||||
*/
|
||||
private $job;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="phone", type="string", length=20, nullable=true)
|
||||
* @var string
|
||||
*/
|
||||
private $phone;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="password", type="string", length=128, nullable=true)
|
||||
* @var string
|
||||
*/
|
||||
private $password;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="roles", type="simple_array", nullable=true)
|
||||
* @var mixed
|
||||
*/
|
||||
private $roles;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="Fault", mappedBy="reporter")
|
||||
* @var Fault[]
|
||||
*/
|
||||
private $reportedFaults;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="password_must_change", type="boolean", options={"default": true})
|
||||
* @var bool
|
||||
*/
|
||||
private $passwordMustChange = true;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="can_change_password", type="boolean", options={"default": true})
|
||||
* @var bool
|
||||
*/
|
||||
private $canChangePassword = true;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="active", type="boolean", options={"default": true})
|
||||
* @var bool
|
||||
*/
|
||||
private $active = true;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->reportedFaults = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return User
|
||||
*/
|
||||
public function setId(int $id): User
|
||||
{
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return User
|
||||
*/
|
||||
public function setName(string $name): User
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getEmail()
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $email
|
||||
* @return User
|
||||
*/
|
||||
public function setEmail(string $email): User
|
||||
{
|
||||
$this->email = $email;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isWantsEmail()
|
||||
{
|
||||
return $this->wantsEmail;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $wantsEmail
|
||||
* @return User
|
||||
*/
|
||||
public function setWantsEmail(bool $wantsEmail): User
|
||||
{
|
||||
$this->wantsEmail = $wantsEmail;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getJob(): string
|
||||
{
|
||||
return $this->job;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $job
|
||||
* @return User
|
||||
*/
|
||||
public function setJob(string $job): User
|
||||
{
|
||||
$this->job = $job;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPhone(): string
|
||||
{
|
||||
return $this->phone;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $phone
|
||||
* @return User
|
||||
*/
|
||||
public function setPhone(string $phone): User
|
||||
{
|
||||
$this->phone = $phone;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPassword(): string
|
||||
{
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $password
|
||||
* @return User
|
||||
*/
|
||||
public function setPassword(string $password): User
|
||||
{
|
||||
$this->password = $password;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getRoles()
|
||||
{
|
||||
return $this->roles;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $roles
|
||||
* @return User
|
||||
*/
|
||||
public function setRoles($roles)
|
||||
{
|
||||
$this->roles = $roles;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Fault[]|ArrayCollection
|
||||
*/
|
||||
public function getReportedFaults(): ArrayCollection
|
||||
{
|
||||
return $this->reportedFaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Fault $reportedFault
|
||||
* @return User
|
||||
*/
|
||||
public function addReportedFault(Fault $reportedFault): User
|
||||
{
|
||||
if (!$this->reportedFaults->contains($reportedFault)) {
|
||||
$this->reportedFaults->add($reportedFault);
|
||||
$reportedFault->setReporter($this);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Fault $reportedFault
|
||||
* @return User
|
||||
*/
|
||||
public function removeReportedFault(Fault $reportedFault): User
|
||||
{
|
||||
if ($this->reportedFaults->contains($reportedFault)) {
|
||||
$this->reportedFaults->removeElement($reportedFault);
|
||||
$reportedFault->setReporter(null);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isPasswordMustChange(): bool
|
||||
{
|
||||
return $this->passwordMustChange;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $passwordMustChange
|
||||
* @return User
|
||||
*/
|
||||
public function setPasswordMustChange(bool $passwordMustChange): User
|
||||
{
|
||||
$this->passwordMustChange = $passwordMustChange;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getCanChangePassword(): bool
|
||||
{
|
||||
return $this->canChangePassword;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $canChangePassword
|
||||
* @return User
|
||||
*/
|
||||
public function setCanChangePassword(bool $canChangePassword): User
|
||||
{
|
||||
$this->canChangePassword = $canChangePassword;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function getActive(): bool
|
||||
{
|
||||
return $this->active;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $active
|
||||
* @return User
|
||||
*/
|
||||
public function setActive(bool $active): User
|
||||
{
|
||||
$this->active = $active;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return [
|
||||
'id' => $this->getId(),
|
||||
'name' => $this->getName(),
|
||||
'email' => $this->getEmail(),
|
||||
'wantsEmail' => $this->isWantsEmail(),
|
||||
'job' => $this->getJob(),
|
||||
'phone' => $this->getPhone(),
|
||||
'roles' => $this->getRoles(),
|
||||
'passwordMustChange' => $this->isPasswordMustChange(),
|
||||
'canChangePassword' => $this->getCanChangePassword(),
|
||||
'active' => $this->getActive(),
|
||||
];
|
||||
}
|
||||
}
|
||||
57
src/App/Fixture/ErrorCategoryLoader.php
Normal file
57
src/App/Fixture/ErrorCategoryLoader.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Fixture;
|
||||
|
||||
use App\Entity\ErrorCategory;
|
||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
use Doctrine\ORM\Id\AssignedGenerator;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class ErrorCategoryLoader extends AbstractFixture implements OrderedFixtureInterface
|
||||
{
|
||||
/**
|
||||
* @var OutputInterface
|
||||
*/
|
||||
private $output;
|
||||
|
||||
public function __construct(OutputInterface $output)
|
||||
{
|
||||
$this->output = $output;
|
||||
}
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
$inputFileContents = file_get_contents("data/fixture/error-category.yml");
|
||||
$yamlData = Yaml::parse($inputFileContents);
|
||||
|
||||
/** @var \Doctrine\ORM\Mapping\ClassMetadata $metadata */
|
||||
$metadata = $manager->getClassMetadata(ErrorCategory::class);
|
||||
$metadata->setIdGenerator(new AssignedGenerator());
|
||||
$metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE);
|
||||
|
||||
$this->output->writeln(sprintf(" > %s BEGIN", __CLASS__));
|
||||
foreach ($yamlData['ErrorCategories'] as $entityId => $entityData) {
|
||||
$entity = new ErrorCategory();
|
||||
$entity->setId($entityData['id'])
|
||||
->setName($entityData['name'])
|
||||
->setType($entityData['type'])
|
||||
->setActive($entityData['active']);
|
||||
|
||||
$this->addReference($entityId, $entity);
|
||||
|
||||
$manager->persist($entity);
|
||||
$this->output->writeln(" * " . $entityId);
|
||||
}
|
||||
$manager->flush();
|
||||
$this->output->writeln(sprintf(" > %s END", __CLASS__));
|
||||
}
|
||||
|
||||
public function getOrder()
|
||||
{
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
57
src/App/Fixture/ErrorOriginLoader.php
Normal file
57
src/App/Fixture/ErrorOriginLoader.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Fixture;
|
||||
|
||||
use App\Entity\ErrorOrigin;
|
||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
use Doctrine\ORM\Id\AssignedGenerator;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class ErrorOriginLoader extends AbstractFixture implements OrderedFixtureInterface
|
||||
{
|
||||
/**
|
||||
* @var OutputInterface
|
||||
*/
|
||||
private $output;
|
||||
|
||||
public function __construct(OutputInterface $output)
|
||||
{
|
||||
$this->output = $output;
|
||||
}
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
$inputFileContents = file_get_contents("data/fixture/error-origin.yml");
|
||||
$yamlData = Yaml::parse($inputFileContents);
|
||||
|
||||
/** @var \Doctrine\ORM\Mapping\ClassMetadata $metadata */
|
||||
$metadata = $manager->getClassMetadata(ErrorOrigin::class);
|
||||
$metadata->setIdGenerator(new AssignedGenerator());
|
||||
$metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE);
|
||||
|
||||
$this->output->writeln(sprintf(" > %s BEGIN", __CLASS__));
|
||||
foreach ($yamlData['ErrorOrigins'] as $entityId => $entityData) {
|
||||
$entity = new ErrorOrigin();
|
||||
$entity->setId($entityData['id'])
|
||||
->setName($entityData['name'])
|
||||
->setCode($entityData['code'])
|
||||
->setActive($entityData['active']);
|
||||
|
||||
$this->addReference($entityId, $entity);
|
||||
|
||||
$manager->persist($entity);
|
||||
$this->output->writeln(" * " . $entityId);
|
||||
}
|
||||
$manager->flush();
|
||||
$this->output->writeln(sprintf(" > %s END", __CLASS__));
|
||||
}
|
||||
|
||||
public function getOrder()
|
||||
{
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
55
src/App/Fixture/FacilityLocationLoader.php
Normal file
55
src/App/Fixture/FacilityLocationLoader.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Fixture;
|
||||
|
||||
use App\Entity\FacilityLocation;
|
||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
use Gedmo\Tree\Entity\Repository\ClosureTreeRepository;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class FacilityLocationLoader extends AbstractFixture implements OrderedFixtureInterface
|
||||
{
|
||||
/**
|
||||
* @var OutputInterface
|
||||
*/
|
||||
private $output;
|
||||
|
||||
public function __construct(OutputInterface $output)
|
||||
{
|
||||
$this->output = $output;
|
||||
}
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
$inputFileContents = file_get_contents("data/fixture/facility-location.yml");
|
||||
$yamlData = Yaml::parse($inputFileContents);
|
||||
|
||||
$this->output->writeln(sprintf(" > %s BEGIN", __CLASS__));
|
||||
foreach ($yamlData['FacilityLocations'] as $entityId => $entityData) {
|
||||
$entity = new FacilityLocation();
|
||||
$entity
|
||||
->setRoomNumber($entityData['roomNumber'])
|
||||
->setName($entityData['name'])
|
||||
->setSize($entityData['size']);
|
||||
|
||||
if ($entityData['parent']) {
|
||||
$entity->setParent($this->getReference($entityData['parent']));
|
||||
}
|
||||
|
||||
$this->addReference($entityId, $entity);
|
||||
|
||||
$manager->persist($entity);
|
||||
$this->output->writeln(" * " . $entityId);
|
||||
}
|
||||
$manager->flush();
|
||||
$this->output->writeln(sprintf(" > %s END", __CLASS__));
|
||||
}
|
||||
|
||||
public function getOrder()
|
||||
{
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
57
src/App/Fixture/SolutionTimeIntervalLoader.php
Normal file
57
src/App/Fixture/SolutionTimeIntervalLoader.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Fixture;
|
||||
|
||||
use App\Entity\SolutionTimeInterval;
|
||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
use Doctrine\ORM\Id\AssignedGenerator;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class SolutionTimeIntervalLoader extends AbstractFixture implements OrderedFixtureInterface
|
||||
{
|
||||
/**
|
||||
* @var OutputInterface
|
||||
*/
|
||||
private $output;
|
||||
|
||||
public function __construct(OutputInterface $output)
|
||||
{
|
||||
$this->output = $output;
|
||||
}
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
$inputFileContents = file_get_contents("data/fixture/solution-time-interval.yml");
|
||||
$yamlData = Yaml::parse($inputFileContents);
|
||||
|
||||
/** @var \Doctrine\ORM\Mapping\ClassMetadata $metadata */
|
||||
$metadata = $manager->getClassMetadata(SolutionTimeInterval::class);
|
||||
$metadata->setIdGenerator(new AssignedGenerator());
|
||||
$metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE);
|
||||
|
||||
$this->output->writeln(sprintf(" > %s BEGIN", __CLASS__));
|
||||
foreach ($yamlData['SolutionTimeIntervals'] as $entityId => $entityData) {
|
||||
$entity = new SolutionTimeInterval();
|
||||
$entity->setId($entityData['id'])
|
||||
->setName($entityData['name'])
|
||||
->setCode($entityData['code'])
|
||||
->setActive($entityData['active']);
|
||||
|
||||
$this->addReference($entityId, $entity);
|
||||
|
||||
$manager->persist($entity);
|
||||
$this->output->writeln(" * " . $entityId);
|
||||
}
|
||||
$manager->flush();
|
||||
$this->output->writeln(sprintf(" > %s END", __CLASS__));
|
||||
}
|
||||
|
||||
public function getOrder()
|
||||
{
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
91
src/App/Fixture/UserLoader.php
Normal file
91
src/App/Fixture/UserLoader.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace App\Fixture;
|
||||
|
||||
use App\Entity\User;
|
||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
use Doctrine\ORM\Id\AssignedGenerator;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
use Zend\Crypt\Password\Bcrypt;
|
||||
|
||||
class UserLoader extends AbstractFixture implements OrderedFixtureInterface
|
||||
{
|
||||
const GEN_PW_FILE = 'data/passwords-generated.txt';
|
||||
const PASSWORD_COST = 14;
|
||||
|
||||
/**
|
||||
* @var OutputInterface
|
||||
*/
|
||||
private $output;
|
||||
|
||||
|
||||
public function __construct(OutputInterface $output)
|
||||
{
|
||||
$this->output = $output;
|
||||
}
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
$inputFileContents = file_get_contents("data/fixture/user.yml");
|
||||
$yamlData = Yaml::parse($inputFileContents);
|
||||
|
||||
/** @var \Doctrine\ORM\Mapping\ClassMetadata $metadata */
|
||||
$metadata = $manager->getClassMetadata(User::class);
|
||||
$metadata->setIdGenerator(new AssignedGenerator());
|
||||
$metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE);
|
||||
|
||||
$this->output->writeln(sprintf(" > %s BEGIN", __CLASS__));
|
||||
|
||||
$crypt = new Bcrypt();
|
||||
$crypt->setCost(self::PASSWORD_COST);
|
||||
|
||||
if (file_exists(self::GEN_PW_FILE)) {
|
||||
unlink(self::GEN_PW_FILE);
|
||||
}
|
||||
|
||||
foreach ($yamlData['Users'] as $entityId => $entityData) {
|
||||
$canChangePassword = $entityData['canChangePassword'] ?? true;
|
||||
if (!$canChangePassword) {
|
||||
$entityData['password'] = substr(md5(uniqid()), 0, 8);
|
||||
file_put_contents(self::GEN_PW_FILE, sprintf(
|
||||
"%s : %s\n",
|
||||
$entityData['name'],
|
||||
$entityData['password']
|
||||
), FILE_APPEND);
|
||||
}
|
||||
|
||||
$entity = new User();
|
||||
$entity->setId($entityData['id'])
|
||||
->setName($entityData['name'])
|
||||
->setEmail($entityData['email'])
|
||||
->setWantsEmail($entityData['wantsEmail'])
|
||||
->setJob($entityData['job'])
|
||||
->setPhone($entityData['phone'])
|
||||
->setPassword($crypt->create(isset($entityData['password']) ? $entityData['password'] : '1234'))
|
||||
->setRoles(explode(',', $entityData['roles']))
|
||||
->setCanChangePassword($canChangePassword)
|
||||
->setActive($entityData['active']);
|
||||
|
||||
$this->addReference($entityId, $entity);
|
||||
|
||||
$manager->persist($entity);
|
||||
$this->output->writeln(" * " . $entityId);
|
||||
}
|
||||
$manager->flush();
|
||||
$this->output->writeln(sprintf(" > %s END", __CLASS__));
|
||||
}
|
||||
|
||||
/**
|
||||
* Used as fixture load order
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getOrder()
|
||||
{
|
||||
return 9;
|
||||
}
|
||||
}
|
||||
594
src/App/Hydrator/DoctrineObject.php
Normal file
594
src/App/Hydrator/DoctrineObject.php
Normal file
@@ -0,0 +1,594 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace App\Hydrator;
|
||||
|
||||
use DateTime;
|
||||
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
use Doctrine\Common\Util\Inflector;
|
||||
use InvalidArgumentException;
|
||||
use RuntimeException;
|
||||
use Traversable;
|
||||
use Zend\Stdlib\ArrayUtils;
|
||||
use Zend\Hydrator\AbstractHydrator;
|
||||
use Zend\Hydrator\Filter\FilterProviderInterface;
|
||||
|
||||
/**
|
||||
* This hydrator has been completely refactored for DoctrineModule 0.7.0. It provides an easy and powerful way
|
||||
* of extracting/hydrator objects in Doctrine, by handling most associations types.
|
||||
*
|
||||
* Starting from DoctrineModule 0.8.0, the hydrator can be used multiple times with different objects
|
||||
*
|
||||
* @license MIT
|
||||
* @link http://www.doctrine-project.org/
|
||||
* @since 0.7.0
|
||||
* @author Michael Gallego <mic.gallego@gmail.com>
|
||||
*/
|
||||
class DoctrineObject extends AbstractHydrator
|
||||
{
|
||||
/**
|
||||
* @var ObjectManager
|
||||
*/
|
||||
protected $objectManager;
|
||||
|
||||
/**
|
||||
* @var ClassMetadata
|
||||
*/
|
||||
protected $metadata;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $byValue = true;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param ObjectManager $objectManager The ObjectManager to use
|
||||
* @param bool $byValue If set to true, hydrator will always use entity's public API
|
||||
*/
|
||||
public function __construct(ObjectManager $objectManager, $byValue = true)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->objectManager = $objectManager;
|
||||
$this->byValue = (bool) $byValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract values from an object
|
||||
*
|
||||
* @param object $object
|
||||
* @return array
|
||||
*/
|
||||
public function extract($object)
|
||||
{
|
||||
$this->prepare($object);
|
||||
|
||||
if ($this->byValue) {
|
||||
return $this->extractByValue($object);
|
||||
}
|
||||
|
||||
return $this->extractByReference($object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hydrate $object with the provided $data.
|
||||
*
|
||||
* @param array $data
|
||||
* @param object $object
|
||||
* @return object
|
||||
*/
|
||||
public function hydrate(array $data, $object)
|
||||
{
|
||||
$this->prepare($object);
|
||||
|
||||
if ($this->byValue) {
|
||||
return $this->hydrateByValue($data, $object);
|
||||
}
|
||||
|
||||
return $this->hydrateByReference($data, $object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the hydrator by adding strategies to every collection valued associations
|
||||
*
|
||||
* @param object $object
|
||||
* @return void
|
||||
*/
|
||||
protected function prepare($object)
|
||||
{
|
||||
$this->metadata = $this->objectManager->getClassMetadata(get_class($object));
|
||||
$this->prepareStrategies();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare strategies before the hydrator is used
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareStrategies()
|
||||
{
|
||||
$associations = $this->metadata->getAssociationNames();
|
||||
|
||||
foreach ($associations as $association) {
|
||||
if ($this->metadata->isCollectionValuedAssociation($association)) {
|
||||
// Add a strategy if the association has none set by user
|
||||
if (!$this->hasStrategy($association)) {
|
||||
if ($this->byValue) {
|
||||
$this->addStrategy($association, new Strategy\AllowRemoveByValue());
|
||||
} else {
|
||||
$this->addStrategy($association, new Strategy\AllowRemoveByReference());
|
||||
}
|
||||
}
|
||||
|
||||
$strategy = $this->getStrategy($association);
|
||||
|
||||
if (!$strategy instanceof Strategy\AbstractCollectionStrategy) {
|
||||
throw new InvalidArgumentException(
|
||||
sprintf(
|
||||
'Strategies used for collections valued associations must inherit from '
|
||||
. 'Strategy\AbstractCollectionStrategy, %s given',
|
||||
get_class($strategy)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$strategy->setCollectionName($association)
|
||||
->setClassMetadata($this->metadata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract values from an object using a by-value logic (this means that it uses the entity
|
||||
* API, in this case, getters)
|
||||
*
|
||||
* @param object $object
|
||||
* @throws RuntimeException
|
||||
* @return array
|
||||
*/
|
||||
protected function extractByValue($object)
|
||||
{
|
||||
$fieldNames = array_merge($this->metadata->getFieldNames(), $this->metadata->getAssociationNames());
|
||||
$methods = get_class_methods($object);
|
||||
$filter = $object instanceof FilterProviderInterface
|
||||
? $object->getFilter()
|
||||
: $this->filterComposite;
|
||||
|
||||
$data = [];
|
||||
foreach ($fieldNames as $fieldName) {
|
||||
if ($filter && !$filter->filter($fieldName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$getter = 'get' . Inflector::classify($fieldName);
|
||||
$isser = 'is' . Inflector::classify($fieldName);
|
||||
|
||||
$dataFieldName = $this->computeExtractFieldName($fieldName);
|
||||
if (in_array($getter, $methods)) {
|
||||
$data[$dataFieldName] = $this->extractValue($fieldName, $object->$getter(), $object);
|
||||
} elseif (in_array($isser, $methods)) {
|
||||
$data[$dataFieldName] = $this->extractValue($fieldName, $object->$isser(), $object);
|
||||
} elseif (substr($fieldName, 0, 2) === 'is'
|
||||
&& ctype_upper(substr($fieldName, 2, 1))
|
||||
&& in_array($fieldName, $methods)) {
|
||||
$data[$dataFieldName] = $this->extractValue($fieldName, $object->$fieldName(), $object);
|
||||
}
|
||||
|
||||
// Unknown fields are ignored
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract values from an object using a by-reference logic (this means that values are
|
||||
* directly fetched without using the public API of the entity, in this case, getters)
|
||||
*
|
||||
* @param object $object
|
||||
* @return array
|
||||
*/
|
||||
protected function extractByReference($object)
|
||||
{
|
||||
$fieldNames = array_merge($this->metadata->getFieldNames(), $this->metadata->getAssociationNames());
|
||||
$refl = $this->metadata->getReflectionClass();
|
||||
$filter = $object instanceof FilterProviderInterface
|
||||
? $object->getFilter()
|
||||
: $this->filterComposite;
|
||||
|
||||
$data = [];
|
||||
foreach ($fieldNames as $fieldName) {
|
||||
if ($filter && !$filter->filter($fieldName)) {
|
||||
continue;
|
||||
}
|
||||
$reflProperty = $refl->getProperty($fieldName);
|
||||
$reflProperty->setAccessible(true);
|
||||
|
||||
$dataFieldName = $this->computeExtractFieldName($fieldName);
|
||||
$data[$dataFieldName] = $this->extractValue($fieldName, $reflProperty->getValue($object), $object);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hydrate the object using a by-value logic (this means that it uses the entity API, in this
|
||||
* case, setters)
|
||||
*
|
||||
* @param array $data
|
||||
* @param object $object
|
||||
* @throws RuntimeException
|
||||
* @return object
|
||||
*/
|
||||
protected function hydrateByValue(array $data, $object)
|
||||
{
|
||||
$tryObject = $this->tryConvertArrayToObject($data, $object);
|
||||
$metadata = $this->metadata;
|
||||
|
||||
if (is_object($tryObject)) {
|
||||
$object = $tryObject;
|
||||
}
|
||||
|
||||
foreach ($data as $field => $value) {
|
||||
$field = $this->computeHydrateFieldName($field);
|
||||
$value = $this->handleTypeConversions($value, $metadata->getTypeOfField($field));
|
||||
$setter = 'set' . Inflector::classify($field);
|
||||
|
||||
if ($metadata->hasAssociation($field)) {
|
||||
$target = $metadata->getAssociationTargetClass($field);
|
||||
|
||||
if ($metadata->isSingleValuedAssociation($field)) {
|
||||
if (! method_exists($object, $setter)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$value = $this->toOne($target, $this->hydrateValue($field, $value, $data));
|
||||
|
||||
if (null === $value
|
||||
&& !current($metadata->getReflectionClass()->getMethod($setter)->getParameters())->allowsNull()
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$object->$setter($value);
|
||||
} elseif ($metadata->isCollectionValuedAssociation($field)) {
|
||||
$this->toMany($object, $field, $target, $value);
|
||||
}
|
||||
} else {
|
||||
if (! method_exists($object, $setter)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$object->$setter($this->hydrateValue($field, $value, $data));
|
||||
}
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hydrate the object using a by-reference logic (this means that values are modified directly without
|
||||
* using the public API, in this case setters, and hence override any logic that could be done in those
|
||||
* setters)
|
||||
*
|
||||
* @param array $data
|
||||
* @param object $object
|
||||
* @return object
|
||||
*/
|
||||
protected function hydrateByReference(array $data, $object)
|
||||
{
|
||||
$tryObject = $this->tryConvertArrayToObject($data, $object);
|
||||
$metadata = $this->metadata;
|
||||
$refl = $metadata->getReflectionClass();
|
||||
|
||||
if (is_object($tryObject)) {
|
||||
$object = $tryObject;
|
||||
}
|
||||
|
||||
foreach ($data as $field => $value) {
|
||||
$field = $this->computeHydrateFieldName($field);
|
||||
|
||||
// Ignore unknown fields
|
||||
if (!$refl->hasProperty($field)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$value = $this->handleTypeConversions($value, $metadata->getTypeOfField($field));
|
||||
$reflProperty = $refl->getProperty($field);
|
||||
$reflProperty->setAccessible(true);
|
||||
|
||||
if ($metadata->hasAssociation($field)) {
|
||||
$target = $metadata->getAssociationTargetClass($field);
|
||||
|
||||
if ($metadata->isSingleValuedAssociation($field)) {
|
||||
$value = $this->toOne($target, $this->hydrateValue($field, $value, $data));
|
||||
$reflProperty->setValue($object, $value);
|
||||
} elseif ($metadata->isCollectionValuedAssociation($field)) {
|
||||
$this->toMany($object, $field, $target, $value);
|
||||
}
|
||||
} else {
|
||||
$reflProperty->setValue($object, $this->hydrateValue($field, $value, $data));
|
||||
}
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function tries, given an array of data, to convert it to an object if the given array contains
|
||||
* an identifier for the object. This is useful in a context of updating existing entities, without ugly
|
||||
* tricks like setting manually the existing id directly into the entity
|
||||
*
|
||||
* @param array $data The data that may contain identifiers keys
|
||||
* @param object $object
|
||||
* @return object
|
||||
*/
|
||||
protected function tryConvertArrayToObject($data, $object)
|
||||
{
|
||||
$metadata = $this->metadata;
|
||||
$identifierNames = $metadata->getIdentifierFieldNames($object);
|
||||
$identifierValues = [];
|
||||
|
||||
if (empty($identifierNames)) {
|
||||
return $object;
|
||||
}
|
||||
|
||||
foreach ($identifierNames as $identifierName) {
|
||||
if (!isset($data[$identifierName])) {
|
||||
return $object;
|
||||
}
|
||||
|
||||
$identifierValues[$identifierName] = $data[$identifierName];
|
||||
}
|
||||
|
||||
return $this->find($identifierValues, $metadata->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle ToOne associations
|
||||
*
|
||||
* When $value is an array but is not the $target's identifiers, $value is
|
||||
* most likely an array of fieldset data. The identifiers will be determined
|
||||
* and a target instance will be initialized and then hydrated. The hydrated
|
||||
* target will be returned.
|
||||
*
|
||||
* @param string $target
|
||||
* @param mixed $value
|
||||
* @return object
|
||||
*/
|
||||
protected function toOne($target, $value)
|
||||
{
|
||||
$metadata = $this->objectManager->getClassMetadata($target);
|
||||
|
||||
if (is_array($value) && array_keys($value) != $metadata->getIdentifier()) {
|
||||
// $value is most likely an array of fieldset data
|
||||
$identifiers = array_intersect_key(
|
||||
$value,
|
||||
array_flip($metadata->getIdentifier())
|
||||
);
|
||||
$object = $this->find($identifiers, $target) ?: new $target;
|
||||
return $this->hydrate($value, $object);
|
||||
}
|
||||
|
||||
return $this->find($value, $target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle ToMany associations. In proper Doctrine design, Collections should not be swapped, so
|
||||
* collections are always handled by reference. Internally, every collection is handled using specials
|
||||
* strategies that inherit from AbstractCollectionStrategy class, and that add or remove elements but without
|
||||
* changing the collection of the object
|
||||
*
|
||||
* @param object $object
|
||||
* @param mixed $collectionName
|
||||
* @param string $target
|
||||
* @param mixed $values
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function toMany($object, $collectionName, $target, $values)
|
||||
{
|
||||
$metadata = $this->objectManager->getClassMetadata(ltrim($target, '\\'));
|
||||
$identifier = $metadata->getIdentifier();
|
||||
|
||||
if (!is_array($values) && !$values instanceof Traversable) {
|
||||
$values = (array)$values;
|
||||
}
|
||||
|
||||
$collection = [];
|
||||
|
||||
// If the collection contains identifiers, fetch the objects from database
|
||||
foreach ($values as $value) {
|
||||
if ($value instanceof $target) {
|
||||
// assumes modifications have already taken place in object
|
||||
$collection[] = $value;
|
||||
continue;
|
||||
} elseif (empty($value)) {
|
||||
// assumes no id and retrieves new $target
|
||||
$collection[] = $this->find($value, $target);
|
||||
continue;
|
||||
}
|
||||
|
||||
$find = [];
|
||||
if (is_array($identifier)) {
|
||||
foreach ($identifier as $field) {
|
||||
switch (gettype($value)) {
|
||||
case 'object':
|
||||
$getter = 'get' . ucfirst($field);
|
||||
if (method_exists($value, $getter)) {
|
||||
$find[$field] = $value->$getter();
|
||||
} elseif (property_exists($value, $field)) {
|
||||
$find[$field] = $value->$field;
|
||||
}
|
||||
break;
|
||||
case 'array':
|
||||
if (array_key_exists($field, $value) && $value[$field] != null) {
|
||||
$find[$field] = $value[$field];
|
||||
unset($value[$field]); // removed identifier from persistable data
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$find[$field] = $value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($find) && $found = $this->find($find, $target)) {
|
||||
$collection[] = (is_array($value)) ? $this->hydrate($value, $found) : $found;
|
||||
} else {
|
||||
$collection[] = (is_array($value)) ? $this->hydrate($value, new $target) : new $target;
|
||||
}
|
||||
}
|
||||
|
||||
$collection = array_filter(
|
||||
$collection,
|
||||
function ($item) {
|
||||
return null !== $item;
|
||||
}
|
||||
);
|
||||
|
||||
// Set the object so that the strategy can extract the Collection from it
|
||||
|
||||
/** @var \DoctrineModule\Stdlib\Hydrator\Strategy\AbstractCollectionStrategy $collectionStrategy */
|
||||
$collectionStrategy = $this->getStrategy($collectionName);
|
||||
$collectionStrategy->setObject($object);
|
||||
|
||||
// We could directly call hydrate method from the strategy, but if people want to override
|
||||
// hydrateValue function, they can do it and do their own stuff
|
||||
$this->hydrateValue($collectionName, $collection, $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle various type conversions that should be supported natively by Doctrine (like DateTime)
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param string $typeOfField
|
||||
* @return DateTime
|
||||
*/
|
||||
protected function handleTypeConversions($value, $typeOfField)
|
||||
{
|
||||
switch ($typeOfField) {
|
||||
case 'datetimetz':
|
||||
case 'datetime':
|
||||
case 'time':
|
||||
case 'date':
|
||||
if ('' === $value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_int($value)) {
|
||||
$dateTime = new DateTime();
|
||||
$dateTime->setTimestamp($value);
|
||||
$value = $dateTime;
|
||||
} elseif (is_string($value)) {
|
||||
$value = new DateTime($value);
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find an object by a given target class and identifier
|
||||
*
|
||||
* @param mixed $identifiers
|
||||
* @param string $targetClass
|
||||
*
|
||||
* @return object|null
|
||||
*/
|
||||
protected function find($identifiers, $targetClass)
|
||||
{
|
||||
if ($identifiers instanceof $targetClass) {
|
||||
return $identifiers;
|
||||
}
|
||||
|
||||
if ($this->isNullIdentifier($identifiers)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->objectManager->find($targetClass, $identifiers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies if a provided identifier is to be considered null
|
||||
*
|
||||
* @param mixed $identifier
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isNullIdentifier($identifier)
|
||||
{
|
||||
if (null === $identifier) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($identifier instanceof Traversable || is_array($identifier)) {
|
||||
$nonNullIdentifiers = array_filter(
|
||||
ArrayUtils::iteratorToArray($identifier),
|
||||
function ($value) {
|
||||
return null !== $value;
|
||||
}
|
||||
);
|
||||
|
||||
return empty($nonNullIdentifiers);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the naming strategy if there is one set
|
||||
*
|
||||
* @param string $field
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function computeHydrateFieldName($field)
|
||||
{
|
||||
if ($this->hasNamingStrategy()) {
|
||||
$field = $this->getNamingStrategy()->hydrate($field);
|
||||
}
|
||||
return $field;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the naming strategy if there is one set
|
||||
*
|
||||
* @param string $field
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function computeExtractFieldName($field)
|
||||
{
|
||||
if ($this->hasNamingStrategy()) {
|
||||
$field = $this->getNamingStrategy()->extract($field);
|
||||
}
|
||||
return $field;
|
||||
}
|
||||
}
|
||||
15
src/App/Hydrator/DoctrineObjectFactory.php
Normal file
15
src/App/Hydrator/DoctrineObjectFactory.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Hydrator;
|
||||
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class DoctrineObjectFactory
|
||||
{
|
||||
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$em = $container->get('doctrine.entity_manager.orm_default');
|
||||
return new DoctrineObject($em);
|
||||
}
|
||||
}
|
||||
66
src/App/Hydrator/Filter/PropertyName.php
Normal file
66
src/App/Hydrator/Filter/PropertyName.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace App\Hydrator\Filter;
|
||||
|
||||
use Zend\Hydrator\Filter\FilterInterface;
|
||||
|
||||
/**
|
||||
* Provides a filter to restrict returned fields by whitelisting or
|
||||
* blacklisting property names.
|
||||
*
|
||||
* @license MIT
|
||||
* @link http://www.doctrine-project.org/
|
||||
* @author Liam O'Boyle <liam@ontheroad.net.nz>
|
||||
*/
|
||||
class PropertyName implements FilterInterface
|
||||
{
|
||||
/**
|
||||
* The propteries to exclude.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $properties = [];
|
||||
|
||||
/**
|
||||
* Either an exclude or an include.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $exclude = null;
|
||||
|
||||
/**
|
||||
* @param [ string | array ] $properties The properties to exclude or include.
|
||||
* @param bool $exclude If the method should be excluded
|
||||
*/
|
||||
public function __construct($properties, $exclude = true)
|
||||
{
|
||||
$this->exclude = $exclude;
|
||||
$this->properties = is_array($properties)
|
||||
? $properties
|
||||
: [$properties];
|
||||
}
|
||||
|
||||
public function filter($property)
|
||||
{
|
||||
return in_array($property, $this->properties)
|
||||
? !$this->exclude
|
||||
: $this->exclude;
|
||||
}
|
||||
}
|
||||
190
src/App/Hydrator/Strategy/AbstractCollectionStrategy.php
Normal file
190
src/App/Hydrator/Strategy/AbstractCollectionStrategy.php
Normal file
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace App\Hydrator\Strategy;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
|
||||
use Zend\Hydrator\Strategy\StrategyInterface;
|
||||
|
||||
/**
|
||||
* @license MIT
|
||||
* @link http://www.doctrine-project.org/
|
||||
* @since 0.7.0
|
||||
* @author Michael Gallego <mic.gallego@gmail.com>
|
||||
*/
|
||||
abstract class AbstractCollectionStrategy implements StrategyInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $collectionName;
|
||||
|
||||
/**
|
||||
* @var ClassMetadata
|
||||
*/
|
||||
protected $metadata;
|
||||
|
||||
/**
|
||||
* @var object
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
|
||||
/**
|
||||
* Set the name of the collection
|
||||
*
|
||||
* @param string $collectionName
|
||||
* @return AbstractCollectionStrategy
|
||||
*/
|
||||
public function setCollectionName($collectionName)
|
||||
{
|
||||
$this->collectionName = (string) $collectionName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the collection
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCollectionName()
|
||||
{
|
||||
return $this->collectionName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the class metadata
|
||||
*
|
||||
* @param ClassMetadata $classMetadata
|
||||
* @return AbstractCollectionStrategy
|
||||
*/
|
||||
public function setClassMetadata(ClassMetadata $classMetadata)
|
||||
{
|
||||
$this->metadata = $classMetadata;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the class metadata
|
||||
*
|
||||
* @return ClassMetadata
|
||||
*/
|
||||
public function getClassMetadata()
|
||||
{
|
||||
return $this->metadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the object
|
||||
*
|
||||
* @param object $object
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return AbstractCollectionStrategy
|
||||
*/
|
||||
public function setObject($object)
|
||||
{
|
||||
if (!is_object($object)) {
|
||||
throw new InvalidArgumentException(
|
||||
sprintf('The parameter given to setObject method of %s class is not an object', get_called_class())
|
||||
);
|
||||
}
|
||||
|
||||
$this->object = $object;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the object
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function getObject()
|
||||
{
|
||||
return $this->object;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function extract($value)
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the collection by value (using the public API)
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
protected function getCollectionFromObjectByValue()
|
||||
{
|
||||
$object = $this->getObject();
|
||||
$getter = 'get' . ucfirst($this->getCollectionName());
|
||||
|
||||
if (!method_exists($object, $getter)) {
|
||||
throw new InvalidArgumentException(
|
||||
sprintf(
|
||||
'The getter %s to access collection %s in object %s does not exist',
|
||||
$getter,
|
||||
$this->getCollectionName(),
|
||||
get_class($object)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return $object->$getter();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the collection by reference (not using the public API)
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
protected function getCollectionFromObjectByReference()
|
||||
{
|
||||
$object = $this->getObject();
|
||||
$refl = $this->getClassMetadata()->getReflectionClass();
|
||||
$reflProperty = $refl->getProperty($this->getCollectionName());
|
||||
|
||||
$reflProperty->setAccessible(true);
|
||||
|
||||
return $reflProperty->getValue($object);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method is used internally by array_udiff to check if two objects are equal, according to their
|
||||
* SPL hash. This is needed because the native array_diff only compare strings
|
||||
*
|
||||
* @param object $a
|
||||
* @param object $b
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function compareObjects($a, $b)
|
||||
{
|
||||
return strcmp(spl_object_hash($a), spl_object_hash($b));
|
||||
}
|
||||
}
|
||||
58
src/App/Hydrator/Strategy/AllowRemoveByReference.php
Normal file
58
src/App/Hydrator/Strategy/AllowRemoveByReference.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace App\Hydrator\Strategy;
|
||||
|
||||
/**
|
||||
* When this strategy is used for Collections, if the new collection does not contain elements that are present in
|
||||
* the original collection, then this strategy remove elements from the original collection. For instance, if the
|
||||
* collection initially contains elements A and B, and that the new collection contains elements B and C, then the
|
||||
* final collection will contain elements B and C (while element A will be asked to be removed).
|
||||
*
|
||||
* This strategy is by reference, this means it won't use public API to add/remove elements to the collection
|
||||
*
|
||||
* @license MIT
|
||||
* @link http://www.doctrine-project.org/
|
||||
* @since 0.7.0
|
||||
* @author Michael Gallego <mic.gallego@gmail.com>
|
||||
*/
|
||||
class AllowRemoveByReference extends AbstractCollectionStrategy
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function hydrate($value)
|
||||
{
|
||||
$collection = $this->getCollectionFromObjectByReference();
|
||||
$collectionArray = $collection->toArray();
|
||||
|
||||
$toAdd = array_udiff($value, $collectionArray, [$this, 'compareObjects']);
|
||||
$toRemove = array_udiff($collectionArray, $value, [$this, 'compareObjects']);
|
||||
|
||||
foreach ($toAdd as $element) {
|
||||
$collection->add($element);
|
||||
}
|
||||
|
||||
foreach ($toRemove as $element) {
|
||||
$collection->removeElement($element);
|
||||
}
|
||||
|
||||
return $collection;
|
||||
}
|
||||
}
|
||||
76
src/App/Hydrator/Strategy/AllowRemoveByValue.php
Normal file
76
src/App/Hydrator/Strategy/AllowRemoveByValue.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace App\Hydrator\Strategy;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use LogicException;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
/**
|
||||
* When this strategy is used for Collections, if the new collection does not contain elements that are present in
|
||||
* the original collection, then this strategy remove elements from the original collection. For instance, if the
|
||||
* collection initially contains elements A and B, and that the new collection contains elements B and C, then the
|
||||
* final collection will contain elements B and C (while element A will be asked to be removed).
|
||||
*
|
||||
* This strategy is by value, this means it will use the public API (in this case, adder and remover)
|
||||
*
|
||||
* @license MIT
|
||||
* @link http://www.doctrine-project.org/
|
||||
* @since 0.7.0
|
||||
* @author Michael Gallego <mic.gallego@gmail.com>
|
||||
*/
|
||||
class AllowRemoveByValue extends AbstractCollectionStrategy
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function hydrate($value)
|
||||
{
|
||||
// AllowRemove strategy need "adder" and "remover"
|
||||
$adder = 'add' . ucfirst($this->collectionName);
|
||||
$remover = 'remove' . ucfirst($this->collectionName);
|
||||
|
||||
if (!method_exists($this->object, $adder) || !method_exists($this->object, $remover)) {
|
||||
throw new LogicException(
|
||||
sprintf(
|
||||
'AllowRemove strategy for DoctrineModule hydrator requires both %s and %s to be defined in %s
|
||||
entity domain code, but one or both seem to be missing',
|
||||
$adder,
|
||||
$remover,
|
||||
get_class($this->object)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$collection = $this->getCollectionFromObjectByValue();
|
||||
|
||||
if ($collection instanceof Collection) {
|
||||
$collection = $collection->toArray();
|
||||
}
|
||||
|
||||
$toAdd = new ArrayCollection(array_udiff($value, $collection, [$this, 'compareObjects']));
|
||||
$toRemove = new ArrayCollection(array_udiff($collection, $value, [$this, 'compareObjects']));
|
||||
|
||||
$this->object->$adder($toAdd);
|
||||
$this->object->$remover($toRemove);
|
||||
|
||||
return $collection;
|
||||
}
|
||||
}
|
||||
53
src/App/Hydrator/Strategy/DisallowRemoveByReference.php
Normal file
53
src/App/Hydrator/Strategy/DisallowRemoveByReference.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace App\Hydrator\Strategy;
|
||||
|
||||
/**
|
||||
* When this strategy is used for Collections, if the new collection does not contain elements that are present in
|
||||
* the original collection, then this strategy will not remove those elements. At most, it will add new elements. For
|
||||
* instance, if the collection initially contains elements A and B, and that the new collection contains elements B
|
||||
* and C, then the final collection will contain elements A, B and C.
|
||||
*
|
||||
* This strategy is by reference, this means it won't use the public API to remove elements
|
||||
*
|
||||
* @license MIT
|
||||
* @link http://www.doctrine-project.org/
|
||||
* @since 0.7.0
|
||||
* @author Michael Gallego <mic.gallego@gmail.com>
|
||||
*/
|
||||
class DisallowRemoveByReference extends AbstractCollectionStrategy
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function hydrate($value)
|
||||
{
|
||||
$collection = $this->getCollectionFromObjectByReference();
|
||||
$collectionArray = $collection->toArray();
|
||||
|
||||
$toAdd = array_udiff($value, $collectionArray, [$this, 'compareObjects']);
|
||||
|
||||
foreach ($toAdd as $element) {
|
||||
$collection->add($element);
|
||||
}
|
||||
|
||||
return $collection;
|
||||
}
|
||||
}
|
||||
72
src/App/Hydrator/Strategy/DisallowRemoveByValue.php
Normal file
72
src/App/Hydrator/Strategy/DisallowRemoveByValue.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the MIT license. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace App\Hydrator\Strategy;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use LogicException;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
/**
|
||||
* When this strategy is used for Collections, if the new collection does not contain elements that are present in
|
||||
* the original collection, then this strategy will not remove those elements. At most, it will add new elements. For
|
||||
* instance, if the collection initially contains elements A and B, and that the new collection contains elements B
|
||||
* and C, then the final collection will contain elements A, B and C.
|
||||
*
|
||||
* This strategy is by value, this means it will use the public API (in this case, remover)
|
||||
*
|
||||
* @license MIT
|
||||
* @link http://www.doctrine-project.org/
|
||||
* @since 0.7.0
|
||||
* @author Michael Gallego <mic.gallego@gmail.com>
|
||||
*/
|
||||
class DisallowRemoveByValue extends AbstractCollectionStrategy
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function hydrate($value)
|
||||
{
|
||||
// AllowRemove strategy need "adder"
|
||||
$adder = 'add' . ucfirst($this->collectionName);
|
||||
|
||||
if (!method_exists($this->object, $adder)) {
|
||||
throw new LogicException(
|
||||
sprintf(
|
||||
'DisallowRemove strategy for DoctrineModule hydrator requires %s to
|
||||
be defined in %s entity domain code, but it seems to be missing',
|
||||
$adder,
|
||||
get_class($this->object)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$collection = $this->getCollectionFromObjectByValue();
|
||||
|
||||
if ($collection instanceof Collection) {
|
||||
$collection = $collection->toArray();
|
||||
}
|
||||
|
||||
$toAdd = new ArrayCollection(array_udiff($value, $collection, [$this, 'compareObjects']));
|
||||
|
||||
$this->object->$adder($toAdd);
|
||||
|
||||
return $collection;
|
||||
}
|
||||
}
|
||||
45
src/App/Middleware/CorsMiddlewareFactory.php
Normal file
45
src/App/Middleware/CorsMiddlewareFactory.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Middleware;
|
||||
|
||||
use Interop\Container\ContainerInterface;
|
||||
use Tuupola\Middleware\Cors;
|
||||
|
||||
class CorsMiddlewareFactory
|
||||
{
|
||||
const CORS_ALLOW_HEADERS = [
|
||||
'DNT',
|
||||
'X-CustomHeader',
|
||||
'Keep-Alive',
|
||||
'User-Agent',
|
||||
'X-Requested-With',
|
||||
'If-Modified-Since',
|
||||
'Cache-Control',
|
||||
'Content-Type',
|
||||
'Authorization',
|
||||
];
|
||||
|
||||
public function __invoke(ContainerInterface $container): Cors
|
||||
{
|
||||
return new Cors([
|
||||
"origin" => ["*"],
|
||||
"methods" => ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
|
||||
"headers.allow" => [
|
||||
'DNT',
|
||||
'X-CustomHeader',
|
||||
'Keep-Alive',
|
||||
'User-Agent',
|
||||
'X-Requested-With',
|
||||
'If-Match',
|
||||
'If-Modified-Since',
|
||||
'If-Unmodified-Since',
|
||||
'Cache-Control',
|
||||
'Content-Type',
|
||||
'Authorization',
|
||||
],
|
||||
"headers.expose" => ["Etag"],
|
||||
"credentials" => true,
|
||||
// "cache" => 86400
|
||||
]);
|
||||
}
|
||||
}
|
||||
69
src/App/Middleware/JwtAuthenticationFactory.php
Normal file
69
src/App/Middleware/JwtAuthenticationFactory.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Middleware;
|
||||
|
||||
use App\Response\JsonCorsResponse;
|
||||
use Interop\Container\ContainerInterface;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Slim\Middleware\JwtAuthentication;
|
||||
use Zend\Config\Config;
|
||||
use Zend\Expressive\Application;
|
||||
use Zend\Expressive\Router\Route;
|
||||
|
||||
class JwtAuthenticationFactory
|
||||
{
|
||||
const DEFAULT_HMAC = 'thisShouldBeChangedForReal';
|
||||
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
public function __invoke(ContainerInterface $container): JwtAuthentication
|
||||
{
|
||||
$config = $container->get('config');
|
||||
$this->config = (new Config($config))->get('acl_config');
|
||||
return new JwtAuthentication([
|
||||
"secret" => $this->config->get('hmac_key', self::DEFAULT_HMAC),
|
||||
"path" => "/api",
|
||||
"passthrough" => $this->getPassThroughRoutes($container),
|
||||
"secure" => true,
|
||||
"relaxed" => [
|
||||
"localhost",
|
||||
"wnapi.yvan.hu",
|
||||
],
|
||||
"error" => function (RequestInterface $request, ResponseInterface $response, $arguments) {
|
||||
$data["status"] = "error";
|
||||
$data["message"] = $arguments["message"];
|
||||
return new JsonCorsResponse($data, 401);
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContainerInterface $container
|
||||
* @return array
|
||||
*/
|
||||
private function getPassThroughRoutes(ContainerInterface $container)
|
||||
{
|
||||
$passThroughRoutes = [];
|
||||
|
||||
/** @var Application $app */
|
||||
$app = $container->get(Application::class);
|
||||
$appRoutes = $app->getRoutes();
|
||||
|
||||
$unguardedRoutes = $this->config->get('unguarded_routes', new Config([]))->toArray();
|
||||
/** @var Route $route */
|
||||
foreach ($appRoutes as $route) {
|
||||
if (in_array($route->getName(), $unguardedRoutes)) {
|
||||
$passThroughRoutes[] = $route->getPath();
|
||||
}
|
||||
}
|
||||
$passThroughRoutes[] = '/show-attachment';
|
||||
$passThroughRoutes[] = '/hibajegy-pdf';
|
||||
$passThroughRoutes[] = '/havi-riport-pdf';
|
||||
|
||||
return $passThroughRoutes;
|
||||
}
|
||||
}
|
||||
75
src/App/Middleware/RouteAuthorization.php
Normal file
75
src/App/Middleware/RouteAuthorization.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Middleware;
|
||||
|
||||
use App\Response\JsonCorsResponse;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Config\Config;
|
||||
use Zend\Expressive\Router\RouteResult;
|
||||
use Zend\Permissions\Rbac\Rbac;
|
||||
|
||||
class RouteAuthorization
|
||||
{
|
||||
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var Rbac
|
||||
*/
|
||||
private $aclService;
|
||||
|
||||
public function __construct(Config $config, Rbac $aclService)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->aclService = $aclService;
|
||||
}
|
||||
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
|
||||
{
|
||||
if ($request->getMethod() == 'OPTIONS') {
|
||||
return $next($request, $response);
|
||||
}
|
||||
|
||||
/** @var RouteResult $routeResult */
|
||||
$routeResult = $request->getAttribute(RouteResult::class, false);
|
||||
$token = $request->getAttribute('token');
|
||||
|
||||
if ($this->hasRouteAccess($routeResult->getMatchedRouteName(), $token->roles ?? [])) {
|
||||
return $next($request, $response);
|
||||
}
|
||||
|
||||
return new JsonCorsResponse([
|
||||
'status' => 'err',
|
||||
'message' => "Access denied to " . $routeResult->getMatchedRouteName(),
|
||||
], 401);
|
||||
}
|
||||
|
||||
private function hasRouteAccess(string $route, $roles = [])
|
||||
{
|
||||
// admin role has full access
|
||||
if (in_array('admin', $roles)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// bail out if route is white listed
|
||||
$unguardedRoutes = $this->config->get('unguarded_routes', new Config([]))->toArray();
|
||||
if (in_array($route, $unguardedRoutes)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// check configuration for other options
|
||||
foreach ($roles as $role) {
|
||||
if ($this->roleCanAccessRoute($role, $route)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function roleCanAccessRoute(string $role, string $routeName)
|
||||
{
|
||||
return $this->aclService->isGranted($role, $routeName);
|
||||
}
|
||||
}
|
||||
19
src/App/Middleware/RouteAuthorizationFactory.php
Normal file
19
src/App/Middleware/RouteAuthorizationFactory.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Middleware;
|
||||
|
||||
use Interop\Container\ContainerInterface;
|
||||
use Zend\Config\Config;
|
||||
use Zend\Permissions\Rbac\Rbac;
|
||||
|
||||
class RouteAuthorizationFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container): RouteAuthorization
|
||||
{
|
||||
/** @var Config $config */
|
||||
$config = new Config($container->get('config')['acl_config']);
|
||||
/** @var Rbac $aclService */
|
||||
$aclService = $container->get('service.acl');
|
||||
return new RouteAuthorization($config, $aclService);
|
||||
}
|
||||
}
|
||||
32
src/App/Response/JsonCorsResponse.php
Normal file
32
src/App/Response/JsonCorsResponse.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Response;
|
||||
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class JsonCorsResponse extends JsonResponse
|
||||
{
|
||||
const ALLOW_HEADERS = [
|
||||
'DNT',
|
||||
'X-CustomHeader',
|
||||
'Keep-Alive',
|
||||
'User-Agent',
|
||||
'X-Requested-With',
|
||||
'If-Modified-Since',
|
||||
'Cache-Control',
|
||||
'Content-Type',
|
||||
'Authorization',
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
$data,
|
||||
$status = 200,
|
||||
array $headers = [],
|
||||
$encodingOptions = self::DEFAULT_JSON_FLAGS
|
||||
) {
|
||||
$headers['Access-Control-Allow-Origin'] = '*';
|
||||
$headers['Access-Control-Allow-Methods'] = 'OPTIONS,GET,POST,PUT,PATCH,DELETE';
|
||||
$headers['Access-Control-Allow-Headers'] = implode(",", self::ALLOW_HEADERS);
|
||||
parent::__construct($data, $status, $headers, $encodingOptions);
|
||||
}
|
||||
}
|
||||
140
src/App/Service/AuthService.php
Normal file
140
src/App/Service/AuthService.php
Normal file
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Entity\AuthResponse;
|
||||
use App\Entity\User;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\NoResultException;
|
||||
use Lcobucci\JWT\Builder;
|
||||
use Lcobucci\JWT\Signer\Hmac\Sha512;
|
||||
use Lcobucci\JWT\Token;
|
||||
use Zend\Config\Config;
|
||||
use Zend\Crypt\Password\Bcrypt;
|
||||
|
||||
class AuthService
|
||||
{
|
||||
const CONFIG_KEY_NAME = 'hmac_key';
|
||||
const PASSWORD_COST = 14;
|
||||
|
||||
/**
|
||||
* @var EntityManager
|
||||
*/
|
||||
private $entityManager;
|
||||
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
public function __construct(
|
||||
EntityManager $em,
|
||||
Config $config
|
||||
) {
|
||||
|
||||
$this->entityManager = $em;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $users
|
||||
* @param string $pass
|
||||
* @return AuthResponse
|
||||
* @throws NoResultException
|
||||
*/
|
||||
public function authenticate(string $users, string $pass): AuthResponse
|
||||
{
|
||||
$response = new AuthResponse();
|
||||
|
||||
$crypt = new Bcrypt();
|
||||
$crypt->setCost(self::PASSWORD_COST);
|
||||
|
||||
/**
|
||||
* Extremely bad idea, but client requested this implementation regardless of the warnings.
|
||||
* As an extra security measure "shared" type users can't change their password
|
||||
*/
|
||||
|
||||
/** @var User[] $users */
|
||||
$users = $this->entityManager->getRepository(User::class)->findBy([
|
||||
'email' => $users,
|
||||
'active' => true,
|
||||
]);
|
||||
if (null === $users || empty($users)) {
|
||||
throw new NoResultException();
|
||||
}
|
||||
shuffle($users);
|
||||
|
||||
foreach ($users as $user) {
|
||||
if ($crypt->verify($pass, $user->getPassword())) {
|
||||
$token = (string)$this->generateJWT($user);
|
||||
$response->setToken($token)
|
||||
->setMessage('login');
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
throw new NoResultException();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $token
|
||||
* @return AuthResponse
|
||||
*/
|
||||
public function renewToken($token): AuthResponse
|
||||
{
|
||||
$response = new AuthResponse();
|
||||
$response->setMessage('renew')
|
||||
->setToken((string)$this->renewJWT($token));
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @return Token
|
||||
*/
|
||||
private function generateJwt(User $user): Token
|
||||
{
|
||||
/** @var string $hmacKey */
|
||||
$hmacKey = $this->config->get('hmac_key');
|
||||
|
||||
$signer = new Sha512();
|
||||
$builder = new Builder();
|
||||
|
||||
return $builder
|
||||
->setId(base64_encode(uniqid()), true)
|
||||
->setIssuedAt(time())
|
||||
->setNotBefore(time())
|
||||
->setExpiration(time() + 3600)
|
||||
->set('uid', $user->getId())
|
||||
->set('name', $user->getName())
|
||||
->set('email', $user->getEmail())
|
||||
->set('roles', $user->getRoles())
|
||||
->sign($signer, $hmacKey)
|
||||
->getToken();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $token
|
||||
* @return Token
|
||||
*/
|
||||
private function renewJWT($token): Token
|
||||
{
|
||||
/** @var string $hmacKey */
|
||||
$hmacKey = $this->config->get('hmac_key');
|
||||
|
||||
$signer = new Sha512();
|
||||
$builder = new Builder();
|
||||
|
||||
return $builder
|
||||
->setId($token->jti, true)
|
||||
->setIssuedAt(time())
|
||||
->setNotBefore(time())
|
||||
->setExpiration(time() + 3600)
|
||||
->set('uid', $token->uid)
|
||||
->set('name', $token->name)
|
||||
->set('email', $token->email)
|
||||
->set('roles', $token->roles)
|
||||
->sign($signer, $hmacKey)
|
||||
->getToken();
|
||||
}
|
||||
}
|
||||
17
src/App/Service/AuthServiceFactory.php
Normal file
17
src/App/Service/AuthServiceFactory.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use Interop\Container\ContainerInterface;
|
||||
use Zend\Config\Config;
|
||||
|
||||
class AuthServiceFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$em = $container->get('doctrine.entity_manager.orm_default');
|
||||
$configArr = $container->get('config')['acl_config'];
|
||||
$config = new Config($configArr);
|
||||
return new AuthService($em, $config);
|
||||
}
|
||||
}
|
||||
32
src/App/Service/ErrorCategoryService.php
Normal file
32
src/App/Service/ErrorCategoryService.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Entity\ErrorCategory;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
|
||||
class ErrorCategoryService
|
||||
{
|
||||
/**
|
||||
* @var EntityManager
|
||||
*/
|
||||
private $em;
|
||||
|
||||
public function __construct(EntityManager $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return FacilityLocations in a tree form
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getList()
|
||||
{
|
||||
/** @var EntityRepository $treeRepository */
|
||||
$repository = $this->em->getRepository(ErrorCategory::class);
|
||||
return $repository->findAll();
|
||||
}
|
||||
}
|
||||
16
src/App/Service/ErrorCategoryServiceFactory.php
Normal file
16
src/App/Service/ErrorCategoryServiceFactory.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class ErrorCategoryServiceFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
/** @var EntityManager $em */
|
||||
$em = $container->get('doctrine.entity_manager.orm_default');
|
||||
return new ErrorCategoryService($em);
|
||||
}
|
||||
}
|
||||
32
src/App/Service/ErrorOriginService.php
Normal file
32
src/App/Service/ErrorOriginService.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Entity\ErrorOrigin;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
|
||||
class ErrorOriginService
|
||||
{
|
||||
/**
|
||||
* @var EntityManager
|
||||
*/
|
||||
private $em;
|
||||
|
||||
public function __construct(EntityManager $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return FacilityLocations in a tree form
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getList()
|
||||
{
|
||||
/** @var EntityRepository $treeRepository */
|
||||
$repository = $this->em->getRepository(ErrorOrigin::class);
|
||||
return $repository->findAll();
|
||||
}
|
||||
}
|
||||
16
src/App/Service/ErrorOriginServiceFactory.php
Normal file
16
src/App/Service/ErrorOriginServiceFactory.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class ErrorOriginServiceFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
/** @var EntityManager $em */
|
||||
$em = $container->get('doctrine.entity_manager.orm_default');
|
||||
return new ErrorOriginService($em);
|
||||
}
|
||||
}
|
||||
61
src/App/Service/FacilityLocationService.php
Normal file
61
src/App/Service/FacilityLocationService.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Entity\FacilityLocation;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Gedmo\Tree\Entity\Repository\ClosureTreeRepository;
|
||||
|
||||
class FacilityLocationService
|
||||
{
|
||||
/**
|
||||
* @var EntityManager
|
||||
*/
|
||||
private $em;
|
||||
|
||||
public function __construct(EntityManager $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return FacilityLocations in a tree form
|
||||
* @return array
|
||||
*/
|
||||
public function getFacilityLocationListTree()
|
||||
{
|
||||
/** @var ClosureTreeRepository $treeRepository */
|
||||
$treeRepository = $this->em->getRepository(FacilityLocation::class);
|
||||
$rootNode = $treeRepository->findOneBy(['name' => 'root']);
|
||||
return $treeRepository->childrenHierarchy($rootNode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getFacilityLocationListFlat()
|
||||
{
|
||||
$result = [];
|
||||
$tree = $this->getFacilityLocationListTree();
|
||||
return $this->flatner($tree, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $items
|
||||
* @param $result
|
||||
* @return array
|
||||
*/
|
||||
private function flatner($items, &$result)
|
||||
{
|
||||
foreach ($items as $item) {
|
||||
$children = $item['__children'];
|
||||
unset($item['__children']);
|
||||
$result[] = $item;
|
||||
if ($children) {
|
||||
$this->flatner($children, $result);
|
||||
}
|
||||
unset($children);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
16
src/App/Service/FacilityLocationServiceFactory.php
Normal file
16
src/App/Service/FacilityLocationServiceFactory.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class FacilityLocationServiceFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
/** @var EntityManager $em */
|
||||
$em = $container->get('doctrine.entity_manager.orm_default');
|
||||
return new FacilityLocationService($em);
|
||||
}
|
||||
}
|
||||
168
src/App/Service/FaultAttachmentService.php
Normal file
168
src/App/Service/FaultAttachmentService.php
Normal file
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\ApiResponse;
|
||||
use App\Entity\Attachment;
|
||||
use App\Entity\Fault;
|
||||
use App\Entity\User;
|
||||
use App\Hydrator\DoctrineObject;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\NonUniqueResultException;
|
||||
use Doctrine\ORM\NoResultException;
|
||||
use Doctrine\ORM\Query;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
|
||||
class FaultAttachmentService
|
||||
{
|
||||
|
||||
/**
|
||||
* @var EntityManager
|
||||
*/
|
||||
private $em;
|
||||
|
||||
/**
|
||||
* @var DoctrineObject
|
||||
*/
|
||||
private $hydrator;
|
||||
|
||||
/**
|
||||
* @var AuthService
|
||||
*/
|
||||
private $authService;
|
||||
|
||||
/**
|
||||
* @var MailerService
|
||||
*/
|
||||
private $mailer;
|
||||
|
||||
/**
|
||||
* @var UserService
|
||||
*/
|
||||
private $userService;
|
||||
|
||||
/**
|
||||
* @param EntityManager $em
|
||||
* @param DoctrineObject $hydrator
|
||||
* @param AuthService $authService
|
||||
* @param MailerService $mailer
|
||||
* @param UserService $userService
|
||||
*/
|
||||
public function __construct(
|
||||
EntityManager $em,
|
||||
DoctrineObject $hydrator,
|
||||
AuthService $authService,
|
||||
MailerService $mailer,
|
||||
UserService $userService
|
||||
) {
|
||||
|
||||
$this->em = $em;
|
||||
$this->hydrator = $hydrator;
|
||||
$this->authService = $authService;
|
||||
$this->mailer = $mailer;
|
||||
$this->userService = $userService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return Attachment[]|null
|
||||
*/
|
||||
public function getList(int $id)
|
||||
{
|
||||
$qb = $this->em->createQueryBuilder();
|
||||
$entities = $qb->select('p')
|
||||
->from(Attachment::class, 'p')
|
||||
->leftJoin('p.fault', 'f')
|
||||
->where('f.id = :fid')
|
||||
->setParameter('fid', $id)
|
||||
->getQuery()
|
||||
->getResult();
|
||||
return $entities;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $id
|
||||
* @return Attachment
|
||||
* @throws NonUniqueResultException
|
||||
* @throws NoResultException
|
||||
*/
|
||||
public function get(int $id)
|
||||
{
|
||||
$qb = $this->em->createQueryBuilder();
|
||||
|
||||
$entity = $qb->select('p')
|
||||
->from(Attachment::class, 'p')
|
||||
->where('p.id = :id')
|
||||
->setParameter('id', $id)
|
||||
->getQuery()
|
||||
->getSingleResult(Query::HYDRATE_OBJECT);
|
||||
|
||||
return $entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $faultId
|
||||
* @param UploadedFileInterface[] $files
|
||||
* @param int $uid
|
||||
* @param string $type Type can be image or invoice
|
||||
* @return Fault
|
||||
*/
|
||||
public function createAttachments(int $faultId, array $files, int $uid, $type = 'image'): Fault
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->em->find(User::class, $uid);
|
||||
/** @var Fault $fault */
|
||||
$fault = $this->em->find(Fault::class, $faultId);
|
||||
foreach ($files as $file) {
|
||||
$attachment = new Attachment();
|
||||
$attachment->setFault($fault)
|
||||
->setUser($user)
|
||||
->setType($type)
|
||||
->setRawFileData($file->getStream()->getContents());
|
||||
$this->em->persist($attachment);
|
||||
}
|
||||
$this->em->flush();
|
||||
if ($type=='image') {
|
||||
$this->sendPhotoAttachedMail($fault, $user);
|
||||
}
|
||||
return $fault;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send message if new photo was attached to a Fault
|
||||
*
|
||||
* @param Fault $fault
|
||||
* @param User $user
|
||||
*/
|
||||
private function sendPhotoAttachedMail(Fault $fault, User $user)
|
||||
{
|
||||
$recipientsUsers = $this->userService->getAllUsersOfRole('ufo');
|
||||
$recipientsUsers[] = $fault->getReporter();
|
||||
$recipients = $this->getMailAddresses($recipientsUsers);
|
||||
|
||||
$this->mailer->sendFaultMail(
|
||||
$recipients,
|
||||
sprintf("[WN] Kép feltöltés - %s", $fault->getWorksheetNumber()),
|
||||
$fault,
|
||||
sprintf("%s új képet csatolt az hibához.", $user->getName())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User[] $mailRecipientUsers
|
||||
* @return string[]
|
||||
*/
|
||||
private function getMailAddresses(array $mailRecipientUsers): array
|
||||
{
|
||||
$usersWhoWantEmail = array_filter($mailRecipientUsers, function (User $user) {
|
||||
return $user->isWantsEmail();
|
||||
});
|
||||
|
||||
$recipients = array_map(function (User $user) {
|
||||
return $user->getEmail();
|
||||
}, $usersWhoWantEmail);
|
||||
|
||||
return array_unique($recipients);
|
||||
}
|
||||
}
|
||||
26
src/App/Service/FaultAttachmentServiceFactory.php
Normal file
26
src/App/Service/FaultAttachmentServiceFactory.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Hydrator\DoctrineObject;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class FaultAttachmentServiceFactory
|
||||
{
|
||||
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
/** @var EntityManager $em */
|
||||
$em = $container->get('doctrine.entity_manager.orm_default');
|
||||
/** @var DoctrineObject $hydrator */
|
||||
$hydrator = $container->get('doctrine.hydrator');
|
||||
/** @var AuthService $authService */
|
||||
$authService = $container->get(AuthService::class);
|
||||
/** @var MailerService $mailer */
|
||||
$mailer = $container->get(MailerService::class);
|
||||
/** @var UserService $userService */
|
||||
$userService = $container->get(UserService::class);
|
||||
return new FaultAttachmentService($em, $hydrator, $authService, $mailer, $userService);
|
||||
}
|
||||
}
|
||||
470
src/App/Service/FaultManagerService.php
Normal file
470
src/App/Service/FaultManagerService.php
Normal file
@@ -0,0 +1,470 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Entity\Fault;
|
||||
use App\Entity\FaultComment;
|
||||
use App\Entity\FaultSnapshot;
|
||||
use App\Entity\User;
|
||||
use App\Hydrator\DoctrineObject;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\Query;
|
||||
|
||||
class FaultManagerService
|
||||
{
|
||||
/**
|
||||
* @var EntityManager
|
||||
*/
|
||||
private $em;
|
||||
|
||||
/**
|
||||
* @var DoctrineObject
|
||||
*/
|
||||
private $hydrator;
|
||||
|
||||
/**
|
||||
* @var AuthService
|
||||
*/
|
||||
private $authService;
|
||||
|
||||
/**
|
||||
* @var MailerService
|
||||
*/
|
||||
private $mailer;
|
||||
|
||||
/**
|
||||
* @var UserService
|
||||
*/
|
||||
private $userService;
|
||||
|
||||
public function __construct(
|
||||
EntityManager $em,
|
||||
DoctrineObject $hydrator,
|
||||
AuthService $authService,
|
||||
MailerService $mailer,
|
||||
UserService $userService
|
||||
) {
|
||||
|
||||
$this->em = $em;
|
||||
$this->hydrator = $hydrator;
|
||||
$this->authService = $authService;
|
||||
$this->mailer = $mailer;
|
||||
$this->userService = $userService;
|
||||
}
|
||||
|
||||
public function getFaultList()
|
||||
{
|
||||
$faults = $this->em->getRepository(Fault::class)->findBy([], [
|
||||
'createdAt' => 'DESC',
|
||||
]);
|
||||
// @todo queryBuilder might be better here?
|
||||
return $faults;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return Fault|null
|
||||
*/
|
||||
public function getFault(int $id): ?Fault
|
||||
{
|
||||
/** @var Fault $fault */
|
||||
$fault = $this->em->find(Fault::class, $id);
|
||||
return $fault;
|
||||
}
|
||||
|
||||
public function createFault($data, $uid): Fault
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->em->find(User::class, $uid);
|
||||
/** @var Fault $fault */
|
||||
$fault = $this->hydrator->hydrate($data, new Fault());
|
||||
// @todo validate user permissions versus the data before persisting
|
||||
$fault->setReporter($user);
|
||||
$this->em->persist($fault);
|
||||
$this->em->flush();
|
||||
|
||||
$this->sendNewMail($fault);
|
||||
|
||||
return $fault;
|
||||
}
|
||||
|
||||
/**
|
||||
* States:
|
||||
* new - fault was just created
|
||||
* cnf - fault confirmed, repair ongoing
|
||||
* exp - fault is high expense, needs approval
|
||||
* wip - fault is being worked on
|
||||
* fin - repair is finished, acknowledged
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
* @param int $uid
|
||||
* @return Fault
|
||||
*/
|
||||
public function updateFault(int $id, array $data, int $uid): Fault
|
||||
{
|
||||
// @todo validate user permissions versus the data before persisting
|
||||
/** @var User $user */
|
||||
$user = $this->em->find(User::class, $uid);
|
||||
$oldFault = $this->getFault($id);
|
||||
$prevState = $oldFault->getState();
|
||||
$this->snapshotHandler($oldFault, $user, $data['state']);
|
||||
/** @var Fault $fault */
|
||||
$fault = $this->hydrator->hydrate($data, $oldFault);
|
||||
// fault is confirmed
|
||||
$now = new \DateTime();
|
||||
if ($prevState == 'new' && in_array($data['state'], ['cnf','exp'])) {
|
||||
$fault->setConfirmer($user)
|
||||
->setConfirmedAt($now);
|
||||
}
|
||||
// high expense approved
|
||||
if ($prevState == 'exp' && $data['state'] == 'cnf') {
|
||||
$fault->setApprovedBy($user)
|
||||
->setApprovedAt($now);
|
||||
}
|
||||
if ($data['state'] == 'fin') {
|
||||
$fault->setAcknowledgedBy($user)
|
||||
->setAcknowledgedAt($now)
|
||||
->setWorkFinished($now);
|
||||
}
|
||||
if ($fault->getWorksheetNumber() == null && $fault->getState() == 'cnf') {
|
||||
$fault->setWorksheetNumber($this->generateWorksheetId());
|
||||
}
|
||||
$this->em->persist($fault);
|
||||
$this->em->flush();
|
||||
|
||||
switch ($fault->getState()) {
|
||||
case 'cnf':
|
||||
if ($prevState == 'exp') {
|
||||
$this->sendExpensiveConfirmedMail($fault, $user);
|
||||
}
|
||||
if ($prevState == 'new') {
|
||||
$this->sendConfirmedMail($fault, $user);
|
||||
}
|
||||
break;
|
||||
case 'exp':
|
||||
$this->sendHighExpenseFaultMail($fault, $user);
|
||||
break;
|
||||
case 'wip':
|
||||
if ($prevState == 'cnf') {
|
||||
$this->sendDoneEmail($fault, $user);
|
||||
}
|
||||
if ($prevState == 'fin') {
|
||||
$this->sendNotFinishedMail($fault, $user);
|
||||
}
|
||||
// if($prevState == 'wip') {
|
||||
// }
|
||||
break;
|
||||
case 'fin':
|
||||
$this->sendFinishedMail($fault, $user);
|
||||
break;
|
||||
}
|
||||
|
||||
return $fault;
|
||||
}
|
||||
|
||||
/**
|
||||
* Faults are not meant to be deleted at any point
|
||||
*
|
||||
* @param int $id
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteFault(int $id): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function addFaultComment(int $id, $data, int $uid): Fault
|
||||
{
|
||||
/** @var Fault $fault */
|
||||
$fault = $this->em->find(Fault::class, $id);
|
||||
/** @var User $user */
|
||||
$user = $this->em->find(User::class, $uid);
|
||||
/** @var FaultComment $faultComment */
|
||||
$faultComment = $this->hydrator->hydrate($data, new FaultComment());
|
||||
// @todo validate user permissions versus the data before persisting
|
||||
$faultComment->setFault($fault)->setUser($user);
|
||||
$this->em->persist($faultComment);
|
||||
$this->em->flush();
|
||||
$this->sendNewCommentOnFaultMail($fault, $user, $faultComment);
|
||||
return $fault;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param $data
|
||||
* @param int $uid
|
||||
* @return Fault
|
||||
*/
|
||||
public function rejectFault(int $id, $data, int $uid): Fault
|
||||
{
|
||||
$rejectReason = $data['__reason'] ?? "";
|
||||
/** @var User $user */
|
||||
$user = $this->em->find(User::class, $uid);
|
||||
/** @var Fault $fault */
|
||||
$fault = $this->em->find(Fault::class, $id);
|
||||
$this->snapshotHandler($fault, $user, $data['state'], $rejectReason);
|
||||
$fault->setState($data['state']);
|
||||
$rejectComment = new FaultComment();
|
||||
$rejectComment->setUser($user)
|
||||
->setComment(sprintf("Elutasítva:\n%s", $rejectReason));
|
||||
$fault->addComment($rejectComment);
|
||||
$this->em->persist($rejectComment);
|
||||
$this->em->flush();
|
||||
|
||||
$this->sendRejectedMail($fault, $user);
|
||||
|
||||
return $fault;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create fault snapshots, provide Fault object before modification
|
||||
*
|
||||
* @param Fault $fault
|
||||
* @param User $user
|
||||
* @param $newState
|
||||
* @param string $comment
|
||||
*/
|
||||
private function snapshotHandler(Fault $fault, User $user, $newState, $comment = '')
|
||||
{
|
||||
$snapShot = new FaultSnapshot();
|
||||
$faultSerialized = $fault->jsonSerialize();
|
||||
unset($faultSerialized['faultSnapshots']);
|
||||
$snapShot->setUser($user)
|
||||
->setFault($fault)
|
||||
->setOldState($fault->getState())
|
||||
->setNewState($newState)
|
||||
->setComment($comment)
|
||||
->setPayload($faultSerialized);
|
||||
$this->em->persist($snapShot);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function generateWorksheetId(): string
|
||||
{
|
||||
$year = date("Y");
|
||||
$yearsFaultCount = $this->em->createQueryBuilder()
|
||||
->select('count(f.id)')
|
||||
->from(Fault::class, 'f')
|
||||
->where('YEAR(f.createdAt) = :thisYear')
|
||||
->andWhere('f.createdAt IS NOT null')
|
||||
->andWhere('f.worksheetNumber IS NOT null')
|
||||
->setParameter('thisYear', $year)
|
||||
->getQuery()
|
||||
->setHydrationMode(Query::HYDRATE_SINGLE_SCALAR)
|
||||
->execute();
|
||||
return sprintf("%s/%s", $year, $yearsFaultCount+1);
|
||||
}
|
||||
|
||||
/**
|
||||
* ->new
|
||||
* @param Fault $fault
|
||||
*/
|
||||
private function sendNewMail(Fault $fault)
|
||||
{
|
||||
$ufoUsers = $this->userService->getAllUsersOfRole('ufo');
|
||||
$pvUsers = $this->userService->getAllUsersOfRole('projektvezeto');
|
||||
$recipientsUsers = array_merge($ufoUsers, $pvUsers);
|
||||
$recipients = $this->getMailAddresses($recipientsUsers);
|
||||
|
||||
$this->mailer->sendFaultMail(
|
||||
array_unique($recipients),
|
||||
"[WN] Új hibabejelentés",
|
||||
$fault
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* new -> cnf
|
||||
* @param Fault $fault
|
||||
* @param User $user
|
||||
*/
|
||||
private function sendConfirmedMail(Fault $fault, User $user)
|
||||
{
|
||||
$recipientsUsers = $this->userService->getAllUsersOfRole('ufo');
|
||||
$recipientsUsers[] = $fault->getReporter();
|
||||
$recipients = $this->getMailAddresses($recipientsUsers);
|
||||
|
||||
$this->mailer->sendFaultMail(
|
||||
$recipients,
|
||||
sprintf("[WN] Kisértékű munka - %s", $fault->getWorksheetNumber()),
|
||||
$fault,
|
||||
sprintf(
|
||||
"Becsült munkaköltség: %s\nBecsült alapanyagköltség: %s\nVisszaigazolta: %s",
|
||||
$fault->getWorkCostEstimate(),
|
||||
$fault->getMaterialCostEstimate(),
|
||||
$user->getName()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* new -> exp
|
||||
* @param Fault $fault
|
||||
* @param User $user
|
||||
*/
|
||||
private function sendHighExpenseFaultMail(Fault $fault, User $user)
|
||||
{
|
||||
$recipientsUsers = $this->userService->getAllUsersOfRole('ufo');
|
||||
$recipientsUsers[] = $fault->getReporter();
|
||||
$recipients = $this->getMailAddresses($recipientsUsers);
|
||||
|
||||
$this->mailer->sendFaultMail(
|
||||
$recipients,
|
||||
"[WN] Nagyértékű munka",
|
||||
$fault,
|
||||
sprintf(
|
||||
"Becsült munkaköltség: %s\nBecsült alapanyagköltség: %s\nVisszaigazolta: %s",
|
||||
$fault->getWorkCostEstimate(),
|
||||
$fault->getMaterialCostEstimate(),
|
||||
$user->getName()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* exp -> cnf
|
||||
* @param Fault $fault
|
||||
* @param User $user
|
||||
*/
|
||||
private function sendExpensiveConfirmedMail(Fault $fault, User $user)
|
||||
{
|
||||
$recipientsUsers = $this->userService->getAllUsersOfRole('ufo');
|
||||
$recipientsUsers[] = $fault->getReporter();
|
||||
$recipients = $this->getMailAddresses($recipientsUsers);
|
||||
|
||||
$this->mailer->sendFaultMail(
|
||||
$recipients,
|
||||
sprintf("[WN] Nagyértékű munka jóváhagyva - %s", $fault->getWorksheetNumber()),
|
||||
$fault,
|
||||
sprintf(
|
||||
"Becsült munkaköltség: %s\nBecsült alapanyagköltség: %s\nJóváhagyta: %s",
|
||||
$fault->getWorkCostEstimate(),
|
||||
$fault->getMaterialCostEstimate(),
|
||||
$user->getName()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* exp -> rej
|
||||
* @param Fault $fault
|
||||
* @param User $user
|
||||
*/
|
||||
private function sendRejectedMail(Fault $fault, User $user)
|
||||
{
|
||||
$recipientsUsers = $this->userService->getAllUsersOfRole('projektvezeto');
|
||||
$recipientsUsers[] = $fault->getReporter();
|
||||
$recipients = $this->getMailAddresses($recipientsUsers);
|
||||
|
||||
$this->mailer->sendFaultMail(
|
||||
$recipients,
|
||||
"[WN] Nagyértékű munka elutasítva",
|
||||
$fault,
|
||||
sprintf("A hiba javítását %s elutasította", $user->getName())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an email to all users involved in fault communication
|
||||
*
|
||||
* @param Fault $fault
|
||||
* @param User $user
|
||||
*/
|
||||
private function sendNewCommentOnFaultMail(Fault $fault, User $user, FaultComment $comment)
|
||||
{
|
||||
$ufoUsers = $this->userService->getAllUsersOfRole('ufo');
|
||||
$comments = $fault->getComments()->toArray();
|
||||
$involvedUsers = array_map(function (FaultComment $comment) {
|
||||
return $comment->getUser();
|
||||
}, $comments);
|
||||
$recipientsUsers = array_merge($ufoUsers, $involvedUsers);
|
||||
$recipients = $this->getMailAddresses($recipientsUsers);
|
||||
|
||||
$this->mailer->sendFaultMail(
|
||||
$recipients,
|
||||
sprintf("[WN] Új hozzászólás - %s", $fault->getWorksheetNumber()),
|
||||
$fault,
|
||||
sprintf("Hozzászólt: %s\n%s", $comment->getUser()->getName(), $comment->getComment())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* cnf -> wip
|
||||
* @param Fault $fault
|
||||
* @param User $user
|
||||
*/
|
||||
private function sendDoneEmail(Fault $fault, User $user)
|
||||
{
|
||||
$recipientsUsers = $this->userService->getAllUsersOfRole('ufo');
|
||||
$recipientsUsers[] = $fault->getReporter();
|
||||
$recipients = $this->getMailAddresses($recipientsUsers);
|
||||
|
||||
$this->mailer->sendFaultMail(
|
||||
$recipients,
|
||||
sprintf("[WN] Hiba javítása elkészült - %s", $fault->getWorksheetNumber()),
|
||||
$fault,
|
||||
sprintf("A hiba javítást lezárta: %s", $user->getName())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* wip -> fin
|
||||
* @param Fault $fault
|
||||
* @param User $user
|
||||
*/
|
||||
private function sendFinishedMail(Fault $fault, User $user)
|
||||
{
|
||||
$ufoUsers = $this->userService->getAllUsersOfRole('ufo');
|
||||
$pvUsers = $this->userService->getAllUsersOfRole('projektvezeto');
|
||||
$recipientsUsers = array_merge($ufoUsers, $pvUsers);
|
||||
$recipients = $this->getMailAddresses($recipientsUsers);
|
||||
|
||||
$this->mailer->sendFaultMail(
|
||||
$recipients,
|
||||
sprintf("[WN] Hiba javítása visszaigazolva - %s", $fault->getWorksheetNumber()),
|
||||
$fault,
|
||||
sprintf("A hiba javítást visszaigazolta: %s", $user->getName())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* fin -> wip
|
||||
* @param Fault $fault
|
||||
* @param User $user
|
||||
*/
|
||||
private function sendNotFinishedMail(Fault $fault, User $user)
|
||||
{
|
||||
$ufoUsers = $this->userService->getAllUsersOfRole('ufo');
|
||||
$pvUsers = $this->userService->getAllUsersOfRole('projektvezeto');
|
||||
$recipientsUsers = array_merge($ufoUsers, $pvUsers);
|
||||
$recipients = $this->getMailAddresses($recipientsUsers);
|
||||
|
||||
$this->mailer->sendFaultMail(
|
||||
$recipients,
|
||||
sprintf("[WN] Hiba javítása elutasítva - %s", $fault->getWorksheetNumber()),
|
||||
$fault,
|
||||
sprintf("A hiba javítást visszaigazolta: %s", $user->getName())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User[] $mailRecipientUsers
|
||||
* @return string[]
|
||||
*/
|
||||
private function getMailAddresses(array $mailRecipientUsers): array
|
||||
{
|
||||
$usersWhoWantEmail = array_filter($mailRecipientUsers, function (User $user) {
|
||||
return $user->isWantsEmail();
|
||||
});
|
||||
|
||||
$recipients = array_map(function (User $user) {
|
||||
return $user->getEmail();
|
||||
}, $usersWhoWantEmail);
|
||||
|
||||
return array_unique($recipients);
|
||||
}
|
||||
}
|
||||
25
src/App/Service/FaultManagerServiceFactory.php
Normal file
25
src/App/Service/FaultManagerServiceFactory.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Hydrator\DoctrineObject;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class FaultManagerServiceFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
/** @var EntityManager $em */
|
||||
$em = $container->get('doctrine.entity_manager.orm_default');
|
||||
/** @var DoctrineObject $hydrator */
|
||||
$hydrator = $container->get('doctrine.hydrator');
|
||||
/** @var AuthService $authService */
|
||||
$authService = $container->get(AuthService::class);
|
||||
/** @var MailerService $mailer */
|
||||
$mailer = $container->get(MailerService::class);
|
||||
/** @var UserService $userService */
|
||||
$userService = $container->get(UserService::class);
|
||||
return new FaultManagerService($em, $hydrator, $authService, $mailer, $userService);
|
||||
}
|
||||
}
|
||||
44
src/App/Service/FixtureLoaderService.php
Normal file
44
src/App/Service/FixtureLoaderService.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Fixture\ErrorCategoryLoader;
|
||||
use App\Fixture\ErrorOriginLoader;
|
||||
use App\Fixture\FacilityLocationLoader;
|
||||
use App\Fixture\SolutionTimeIntervalLoader;
|
||||
use App\Fixture\UserLoader;
|
||||
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
|
||||
use Doctrine\Common\DataFixtures\Loader;
|
||||
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class FixtureLoaderService
|
||||
{
|
||||
|
||||
/**
|
||||
* @var EntityManager
|
||||
*/
|
||||
private $em;
|
||||
|
||||
public function __construct(EntityManager $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
public function load(OutputInterface $output)
|
||||
{
|
||||
$loader = new Loader();
|
||||
$loader->addFixture(new ErrorCategoryLoader($output));
|
||||
$loader->addFixture(new ErrorOriginLoader($output));
|
||||
$loader->addFixture(new FacilityLocationLoader($output));
|
||||
$loader->addFixture(new SolutionTimeIntervalLoader($output));
|
||||
$loader->addFixture(new UserLoader($output));
|
||||
|
||||
$purger = new ORMPurger();
|
||||
$executor = new ORMExecutor($this->em, $purger);
|
||||
$executor->execute($loader->getFixtures());
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
17
src/App/Service/FixtureLoaderServiceFactory.php
Normal file
17
src/App/Service/FixtureLoaderServiceFactory.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class FixtureLoaderServiceFactory
|
||||
{
|
||||
|
||||
public function __invoke(ContainerInterface $container): FixtureLoaderService
|
||||
{
|
||||
/** @var EntityManager $em */
|
||||
$em = $container->get('doctrine.entity_manager.orm_default');
|
||||
return new FixtureLoaderService($em);
|
||||
}
|
||||
}
|
||||
23
src/App/Service/LoggerFactory.php
Normal file
23
src/App/Service/LoggerFactory.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use Interop\Container\ContainerInterface;
|
||||
use Monolog\Handler\ChromePHPHandler;
|
||||
use Monolog\Handler\StreamHandler;
|
||||
use Monolog\Logger;
|
||||
|
||||
class LoggerFactory
|
||||
{
|
||||
|
||||
public function __invoke(ContainerInterface $container): Logger
|
||||
{
|
||||
$config = $container->get('config');
|
||||
$logger = new Logger("webnaplo");
|
||||
$logger->pushHandler(new StreamHandler('data/log/application.log'));
|
||||
if ($config['debug']) {
|
||||
$logger->pushHandler(new ChromePHPHandler());
|
||||
}
|
||||
return $logger;
|
||||
}
|
||||
}
|
||||
130
src/App/Service/MailerService.php
Normal file
130
src/App/Service/MailerService.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Entity\Fault;
|
||||
use Monolog\Logger;
|
||||
use Zend\Mail\Message;
|
||||
use Zend\Mail\Transport\Exception\RuntimeException;
|
||||
use Zend\Mail\Transport\TransportInterface;
|
||||
|
||||
class MailerService
|
||||
{
|
||||
|
||||
const TEMPLATE_FAULT_HEADER = 'faultHeader';
|
||||
const TEMPLATE_FAULT_FOOTER = 'faultFooter';
|
||||
/**
|
||||
* @var TransportInterface
|
||||
*/
|
||||
private $transport;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var Logger
|
||||
*/
|
||||
private $logger;
|
||||
|
||||
/**
|
||||
* MailerService constructor.
|
||||
* @param TransportInterface $transport
|
||||
* @param array $config
|
||||
* @param Logger $logger
|
||||
*/
|
||||
public function __construct(
|
||||
TransportInterface $transport,
|
||||
array $config,
|
||||
Logger $logger
|
||||
) {
|
||||
|
||||
$this->config = $config;
|
||||
$this->transport = $transport;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $recipients
|
||||
* @param string $subject
|
||||
* @param string $body
|
||||
* @return bool
|
||||
*/
|
||||
public function sendMail($recipients, string $subject, string $body): bool
|
||||
{
|
||||
$message = new Message();
|
||||
$message->setEncoding("UTF-8")
|
||||
->setFrom($this->config['self']['sender'], "Webnapló")
|
||||
->setTo($recipients)
|
||||
->setSubject($subject)
|
||||
->setBody($body);
|
||||
try {
|
||||
$this->transport->send($message);
|
||||
} catch (RuntimeException $ex) {
|
||||
$this->logger->error($ex->getMessage(), [
|
||||
'recipients' => $recipients,
|
||||
'subject' => $subject,
|
||||
'body' => $body,
|
||||
]);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function sendFaultMail($recipients, string $subject, Fault $fault, string $body = ""): bool
|
||||
{
|
||||
$compiledBody = sprintf(
|
||||
"%s\n\n%s\n\n\n%s",
|
||||
$this->getFaultHeader($fault),
|
||||
$body,
|
||||
$this->getFaultFooter()
|
||||
);
|
||||
return $this->sendMail($recipients, $subject, $compiledBody);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Fault $fault
|
||||
* @return string
|
||||
*/
|
||||
private function getFaultHeader(Fault $fault): string
|
||||
{
|
||||
$replacements = [
|
||||
'%%FACILITY_LOCATION%%' => $fault->getFacilityLocation()->getName(),
|
||||
'%%FACILITY_LOCATION_DESCRIPTION%%' => $fault->getFacilityLocationDescription(),
|
||||
'%%ERROR_CATEGORY%%' => $fault->getErrorCategory()->getName(),
|
||||
'%%ERROR_ORIGIN%%' => $fault->getErrorOrigin()->getName(),
|
||||
'%%ERROR_DESCRIPTION%%' => $fault->getErrorDescription(),
|
||||
'%%SOLUTION_TIME%%' => $fault->getSolutionTimeInterval()->getId() == 3
|
||||
? $fault->getSolutionTimeIntervalOther()
|
||||
: $fault->getSolutionTimeInterval()->getName(),
|
||||
];
|
||||
$mailTemplate = $this->getTemplate(self::TEMPLATE_FAULT_HEADER);
|
||||
return str_replace(array_keys($replacements), array_values($replacements), $mailTemplate);
|
||||
}
|
||||
|
||||
private function getFaultFooter(): string
|
||||
{
|
||||
$replacements = [
|
||||
'%%WEBNAPLO_URI%%' => $this->config['self']['site-uri'],
|
||||
];
|
||||
$mailTemplate = $this->getTemplate(self::TEMPLATE_FAULT_FOOTER);
|
||||
return str_replace(array_keys($replacements), array_values($replacements), $mailTemplate);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
private function getTemplate(string $name): string
|
||||
{
|
||||
return file_get_contents(sprintf("data/mail-template/%s.txt", $name));
|
||||
}
|
||||
|
||||
public function sendTestMessage()
|
||||
{
|
||||
$this->sendMail([
|
||||
"danyi.david@gmail.com"
|
||||
], "Teszt levél", "Teszt levél tartalom");
|
||||
}
|
||||
}
|
||||
25
src/App/Service/MailerServiceFactory.php
Normal file
25
src/App/Service/MailerServiceFactory.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use Interop\Container\ContainerInterface;
|
||||
use Monolog\Logger;
|
||||
use Zend\Mail\Transport\File;
|
||||
use Zend\Mail\Transport\Smtp;
|
||||
|
||||
class MailerServiceFactory
|
||||
{
|
||||
|
||||
public function __invoke(ContainerInterface $container): MailerService
|
||||
{
|
||||
$config = $container->get('config');
|
||||
|
||||
/** @var Smtp|File $mailTransport */
|
||||
$mailTransport = new $config['mailer']['transportClass']();
|
||||
$transportOptions = new $config['mailer']['optionsClass']($config['mailer']['options']);
|
||||
$mailTransport->setOptions($transportOptions);
|
||||
/** @var Logger $logger */
|
||||
$logger = $container->get(Logger::class);
|
||||
return new MailerService($mailTransport, $config, $logger);
|
||||
}
|
||||
}
|
||||
250
src/App/Service/MaintenanceManagerService.php
Normal file
250
src/App/Service/MaintenanceManagerService.php
Normal file
@@ -0,0 +1,250 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Entity\Device;
|
||||
use App\Entity\DeviceGroup;
|
||||
use App\Entity\DeviceMaintenanceTask;
|
||||
use App\Entity\Maintenance;
|
||||
use App\Hydrator\DoctrineObject;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\Query;
|
||||
|
||||
class MaintenanceManagerService
|
||||
{
|
||||
/** @var EntityManager */
|
||||
private $em;
|
||||
|
||||
/** @var DoctrineObject */
|
||||
private $hydrator;
|
||||
|
||||
/** @var XlsxParserService */
|
||||
private $xlsxParserService;
|
||||
|
||||
/** @var UserService */
|
||||
private $userService;
|
||||
|
||||
/** @var int */
|
||||
private $year;
|
||||
|
||||
public function __construct(
|
||||
EntityManager $em,
|
||||
DoctrineObject $hydrator,
|
||||
XlsxParserService $xlsxParserService,
|
||||
UserService $userService
|
||||
) {
|
||||
// $this->year = date("Y");
|
||||
$this->year = 2018;
|
||||
$this->em = $em;
|
||||
$this->hydrator = $hydrator;
|
||||
$this->xlsxParserService = $xlsxParserService;
|
||||
$this->userService = $userService;
|
||||
}
|
||||
|
||||
public function getMaintenanceList(): ArrayCollection
|
||||
{
|
||||
return $this->getUpdatedXlsxData();
|
||||
}
|
||||
|
||||
public function getUpcomingMaintenanceList(): ArrayCollection
|
||||
{
|
||||
$firstDayOfThisWeek = new \DateTime("@" . strtotime(sprintf("-%s days", date("N") - 0)));
|
||||
$firstDayOfThisWeek
|
||||
->setTimezone(new \DateTimeZone(date_default_timezone_get()))
|
||||
->setTime(0, 0);
|
||||
$twoWeeksFromNow = (clone $firstDayOfThisWeek)->add(\DateInterval::createFromDateString("+14 days"));
|
||||
|
||||
$deviceGroups = $this->getUpdatedXlsxData();
|
||||
|
||||
foreach ($deviceGroups as $deviceGroup) {
|
||||
/** @var DeviceGroup $deviceGroup */
|
||||
foreach ($deviceGroup->getDevices() as $device) {
|
||||
$tasks = $device->getTasks()->filter(function (DeviceMaintenanceTask $task) use (
|
||||
$firstDayOfThisWeek,
|
||||
$twoWeeksFromNow
|
||||
) {
|
||||
return $task->getShouldStartAt() >= $firstDayOfThisWeek
|
||||
&& $task->getShouldStartAt() < $twoWeeksFromNow;
|
||||
});
|
||||
$device->setTasks($tasks);
|
||||
}
|
||||
|
||||
$devices = $deviceGroup->getDevices()->filter(function (Device $device) {
|
||||
return count($device->getTasks());
|
||||
});
|
||||
$deviceGroup->setDevices($devices);
|
||||
}
|
||||
|
||||
return $deviceGroups->filter(function (DeviceGroup $deviceGroup) {
|
||||
return count($deviceGroup->getDevices());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DeviceGroup[]|ArrayCollection
|
||||
*/
|
||||
private function getUpdatedXlsxData()
|
||||
{
|
||||
/** @var DeviceGroup[] $loadedCacheData */
|
||||
$loadedCacheData = $this->xlsxParserService->getXlsxData();
|
||||
|
||||
/** @var Maintenance[] $dbMaintenances */
|
||||
$dbMaintenances = $this->getMaintenancesInYear($this->year);
|
||||
foreach ($dbMaintenances as $maintenance) {
|
||||
foreach ($loadedCacheData as &$deviceGroup) {
|
||||
foreach ($deviceGroup->getDevices() as &$device) {
|
||||
foreach ($device->getTasks() as &$task) {
|
||||
if ($task->getHash() == $maintenance->getHash()) {
|
||||
$task->setState($maintenance->getState());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $loadedCacheData;
|
||||
}
|
||||
|
||||
public function getMaintenancesInYear($year): array
|
||||
{
|
||||
$qb = $this->em->createQueryBuilder();
|
||||
return $qb->select('m')
|
||||
->from(Maintenance::class, 'm')
|
||||
->where('m.year = :thisYear')
|
||||
->setParameter('thisYear', $year)
|
||||
->orderBy('m.month')
|
||||
->addOrderBy('m.week')
|
||||
->getQuery()
|
||||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $hash
|
||||
* @return Maintenance
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
* @throws \Doctrine\ORM\TransactionRequiredException
|
||||
*/
|
||||
public function get(string $hash): Maintenance
|
||||
{
|
||||
/** @var Maintenance $maintenance */
|
||||
if (null == ($maintenance = $this->em->find(Maintenance::class, $hash))) {
|
||||
$maintenance = $this->initMaintenanceInDatabase($hash);
|
||||
}
|
||||
return $maintenance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $hash
|
||||
* @param $data
|
||||
* @param int $uid
|
||||
* @return Maintenance
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
* @throws \Doctrine\ORM\TransactionRequiredException
|
||||
*/
|
||||
public function update(string $hash, $data, int $uid): Maintenance
|
||||
{
|
||||
$maintenance = $this->get($hash);
|
||||
/** @var Maintenance $maintenance */
|
||||
$maintenance = $this->hydrator->hydrate($data, $maintenance);
|
||||
if (null == $maintenance->getStartedBy()) {
|
||||
$maintenance->setStartedBy($this->userService->get($uid));
|
||||
}
|
||||
if (null == $maintenance->getFinishedBy() && $data['state'] == 'fin') {
|
||||
$maintenance->setFinishedBy($this->userService->get($uid));
|
||||
}
|
||||
if (null == $maintenance->getWorksheetNumber() && null != $maintenance->getShouldStartAt()) {
|
||||
$maintenance->setWorksheetNumber($this->generateWorksheetId($maintenance->getShouldStartAt()->format("Y")));
|
||||
}
|
||||
$this->em->flush();
|
||||
return $maintenance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
* @param string $state
|
||||
* @param int $uid
|
||||
* @return Maintenance
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
* @throws \Doctrine\ORM\TransactionRequiredException
|
||||
* @deprecated
|
||||
*/
|
||||
public function setStatus(string $id, string $state, int $uid): Maintenance
|
||||
{
|
||||
$user = $this->userService->get($uid);
|
||||
$maintenance = $this->get($id);
|
||||
$maintenance->setState($state);
|
||||
switch ($state) {
|
||||
case "wip":
|
||||
$maintenance->setWorkStarted(new \DateTime())
|
||||
->setWorksheetNumber($this->generateWorksheetId($maintenance->getShouldStartAt()->format("Y")))
|
||||
->setStartedBy($user);
|
||||
break;
|
||||
case "fin":
|
||||
$maintenance->setWorkFinished(new \DateTime())
|
||||
->setFinishedBy($user);
|
||||
break;
|
||||
}
|
||||
$this->em->flush();
|
||||
return $maintenance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
* @return Maintenance
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
*/
|
||||
private function initMaintenanceInDatabase(string $id): Maintenance
|
||||
{
|
||||
$taskFound = null;
|
||||
$loadedCacheData = $this->getUpdatedXlsxData();
|
||||
foreach ($loadedCacheData as $deviceGroup) {
|
||||
foreach ($deviceGroup->getDevices() as $device) {
|
||||
foreach ($device->getTasks() as $task) {
|
||||
if ($task->getHash() == $id) {
|
||||
$taskFound = $task;
|
||||
break 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$maintenance = new Maintenance();
|
||||
$maintenance->setHash($id)
|
||||
->setDeviceName($taskFound->getDevice()->getGroup()->getName())
|
||||
->setComponentName($taskFound->getDevice()->getName())
|
||||
->setResponsible($taskFound->getDevice()->getResponsible())
|
||||
->setCount($taskFound->getDevice()->getCount())
|
||||
->setWorkDescription($taskFound->getDevice()->getWorkDescription())
|
||||
->setYear($this->year)
|
||||
->setMonth($taskFound->getMonth())
|
||||
->setWeek($taskFound->getWeek())
|
||||
->setWorkerCount($taskFound->getWorkerCount())
|
||||
->setTimeCost($taskFound->getTimeCost())
|
||||
->setShouldStartAt($taskFound->getShouldStartAt())
|
||||
->setShouldBeDoneBy($taskFound->getShouldBeDoneBy());
|
||||
$this->em->persist($maintenance);
|
||||
$this->em->flush();
|
||||
return $maintenance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function generateWorksheetId($year): string
|
||||
{
|
||||
$yearsFaultCount = $this->em->createQueryBuilder()
|
||||
->select('count(f.hash)')
|
||||
->from(Maintenance::class, 'f')
|
||||
->where('YEAR(f.shouldStartAt) = :thisYear')
|
||||
// ->andWhere('f.shouldStartAt IS NOT null')
|
||||
->andWhere('f.worksheetNumber IS NOT null')
|
||||
->setParameter('thisYear', $year)
|
||||
->getQuery()
|
||||
->setHydrationMode(Query::HYDRATE_SINGLE_SCALAR)
|
||||
->execute();
|
||||
return sprintf("%s/%s", $this->year, $yearsFaultCount+1);
|
||||
}
|
||||
}
|
||||
29
src/App/Service/MaintenanceManagerServiceFactory.php
Normal file
29
src/App/Service/MaintenanceManagerServiceFactory.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Hydrator\DoctrineObject;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class MaintenanceManagerServiceFactory
|
||||
{
|
||||
/**
|
||||
* @param ContainerInterface $container
|
||||
* @return MaintenanceManagerService
|
||||
* @throws \Psr\Container\ContainerExceptionInterface
|
||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
||||
*/
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
/** @var EntityManager $em */
|
||||
$em = $container->get('doctrine.entity_manager.orm_default');
|
||||
/** @var DoctrineObject $hydrator */
|
||||
$hydrator = $container->get('doctrine.hydrator');
|
||||
/** @var XlsxParserService $xlsxParserService */
|
||||
$xlsxParserService = $container->get(XlsxParserService::class);
|
||||
/** @var UserService $userService */
|
||||
$userService = $container->get(UserService::class);
|
||||
return new MaintenanceManagerService($em, $hydrator, $xlsxParserService, $userService);
|
||||
}
|
||||
}
|
||||
405
src/App/Service/PdfService.php
Normal file
405
src/App/Service/PdfService.php
Normal file
@@ -0,0 +1,405 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Entity\Fault;
|
||||
use App\Entity\Maintenance;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use PHPPdf\Core\Configuration\LoaderImpl;
|
||||
use PHPPdf\Core\FacadeBuilder;
|
||||
|
||||
class PdfService
|
||||
{
|
||||
const WORKSHEET_TEMPLATE_FILE = 'data/pdf-template/worksheet.xml';
|
||||
const WORKSHEET_STYLESHEET_FILE = 'data/pdf-template/worksheet-style.xml';
|
||||
|
||||
const MAINTENANCESHEET_TEMPLATE_FILE = 'data/pdf-template/maintenanceSheet.xml';
|
||||
const MAINTENANCESHEET_STYLESHEET_FILE = 'data/pdf-template/maintenanceSheet-style.xml';
|
||||
|
||||
// const MONTHLY_REPORT_TEMPLATE_FILE = 'data/pdf-template/monthlyReport.xml';
|
||||
// const MONTHLY_REPORT_STYLESHEET_FILE = 'data/pdf-template/monthlyReport-style.xml';
|
||||
//
|
||||
// const MONTHLY_REPORT_INSTITUTE_TPL = 'data/pdf-template/monthlyReport/institute.xml';
|
||||
// const MONTHLY_REPORT_FAULT_TPL = 'data/pdf-template/monthlyReport/fault.xml';
|
||||
// const MONTHLY_REPORT_FAULT_COST_ITEM_TPL = 'data/pdf-template/monthlyReport/faultCostItem.xml';
|
||||
// const MONTHLY_REPORT_FAULT_COST_WORK_TPL = 'data/pdf-template/monthlyReport/faultCostWork.xml';
|
||||
// const MONTHLY_REPORT_FAULT_COST_LATE_TPL = 'data/pdf-template/monthlyReport/faultCostLate.xml';
|
||||
|
||||
|
||||
/**
|
||||
* @var EntityManager
|
||||
*/
|
||||
private $em;
|
||||
|
||||
/**
|
||||
* @var FaultManagerService
|
||||
*/
|
||||
private $faultManager;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @param EntityManager $em
|
||||
* @param FaultManagerService $faultManager
|
||||
*/
|
||||
public function __construct(EntityManager $em, FaultManagerService $faultManager, $config)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->faultManager = $faultManager;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return string
|
||||
* @throws \PHPPdf\Core\PHPPdf\Exception\Exception
|
||||
*/
|
||||
public function getWorksheet(int $id): string
|
||||
{
|
||||
/** @var Fault $faultEntity */
|
||||
$faultEntity = $this->em->getRepository(Fault::class)->find($id);
|
||||
|
||||
$pdfTemplate = $this->fillWorksheetTemplate(file_get_contents(self::WORKSHEET_TEMPLATE_FILE), $faultEntity);
|
||||
$styleData = file_get_contents(self::WORKSHEET_STYLESHEET_FILE);
|
||||
|
||||
$loader = new LoaderImpl();
|
||||
$loader->setFontFile("data/pdf-resources/config/font-config.xml");
|
||||
|
||||
$builder = FacadeBuilder::create($loader)
|
||||
->setCache('File', ['cache_dir' => 'data/cache'])
|
||||
->setEngineType('pdf');
|
||||
$pdfRenderer = $builder->build();
|
||||
|
||||
$oldErrorLevel = error_reporting();
|
||||
error_reporting($oldErrorLevel & ~E_NOTICE);
|
||||
$rendered = $pdfRenderer->render($pdfTemplate, $styleData);
|
||||
error_reporting($oldErrorLevel);
|
||||
return $rendered;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
* @return string
|
||||
* @throws \PHPPdf\Core\PHPPdf\Exception\Exception
|
||||
*/
|
||||
public function getMaintenanceSheet(string $id): string
|
||||
{
|
||||
/** @var Maintenance $maintenance */
|
||||
$maintenance = $this->em->getRepository(Maintenance::class)->find($id);
|
||||
|
||||
$pdfTemplate = $this->fillMaintenanceSheetTemplate(
|
||||
file_get_contents(self::MAINTENANCESHEET_TEMPLATE_FILE),
|
||||
$maintenance
|
||||
);
|
||||
$styleData = file_get_contents(self::MAINTENANCESHEET_STYLESHEET_FILE);
|
||||
|
||||
$loader = new LoaderImpl();
|
||||
$loader->setFontFile("data/pdf-resources/config/font-config.xml");
|
||||
|
||||
$builder = FacadeBuilder::create($loader)
|
||||
->setCache('File', ['cache_dir' => 'data/cache'])
|
||||
->setEngineType('pdf');
|
||||
$pdfRenderer = $builder->build();
|
||||
|
||||
$oldErrorLevel = error_reporting();
|
||||
error_reporting($oldErrorLevel & ~E_NOTICE);
|
||||
$rendered = $pdfRenderer->render($pdfTemplate, $styleData);
|
||||
error_reporting($oldErrorLevel);
|
||||
return $rendered;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $template
|
||||
* @param Fault $fault
|
||||
* @return string
|
||||
*/
|
||||
private function fillWorksheetTemplate(string $template, Fault $fault): string
|
||||
{
|
||||
$formatString = "Y.m.d H:i";
|
||||
$replacementMatches = [
|
||||
'%%WS_ID%%' => $fault->getWorksheetNumber(),
|
||||
|
||||
'%%REPORTED_AT%%' => $fault->getCreatedAt()->format($formatString),
|
||||
'%%FINISHED_AT%%' => $fault->getWorkFinished()
|
||||
? $fault->getWorkFinished()->format($formatString)
|
||||
: '',
|
||||
'%%APPROVED_AT%%' => $fault->getApprovedAt()
|
||||
? $fault->getApprovedAt()->format($formatString)
|
||||
: '',
|
||||
'%%CONFIRMED_AT%%' => $fault->getConfirmedAt()
|
||||
? $fault->getConfirmedAt()->format($formatString)
|
||||
: '',
|
||||
'%%ACKNOWLEDGED_AT%%' => $fault->getAcknowledgedAt()
|
||||
? $fault->getAcknowledgedAt()->format($formatString)
|
||||
: '',
|
||||
|
||||
'%%FAULT_DECISION%%' => $fault->isMustLowerCost()
|
||||
? 'költség csökkentés szükséges'
|
||||
: 'elfogadva',
|
||||
'%%ALLOCATED_EXPENSE%%' => $fault->getAllocatedExpense() ?? '',
|
||||
/**
|
||||
* @todo calculate real repair cost here when possible
|
||||
*/
|
||||
'%%REPAIR_COST%%' => $fault->getWorkCostEstimate() + $fault->getMaterialCostEstimate(),
|
||||
|
||||
'%%TIMESPENT_HOUR%%' => '',
|
||||
'%%TIMESPENT_DAY%%' => '',
|
||||
'%%FAULT_DURATION%%' => '',
|
||||
'%%LATE_FINE_PERCENT%%' => '',
|
||||
|
||||
// '%%APPROVE_YEAR%%' => $appYear,
|
||||
// '%%APPROVE_MONTH%%' => $appMonth,
|
||||
// '%%APPROVE_DAY%%' => $appDay,
|
||||
// '%%APPROVE_HOUR%%' => $appHour,
|
||||
// '%%APPROVE_MINUTE%%' => $appMinute,
|
||||
|
||||
'%%SELF_NAME%%' => $this->config['self']['name'],
|
||||
'%%SELF_ADDRESS%%' => $this->config['self']['address'],
|
||||
'%%SELF_TAXNUMBER%%' => $this->config['self']['tax_number'],
|
||||
// owner
|
||||
// '%%OWNER_SHORT%%' => $this->config['client']['short'],
|
||||
'%%OWNER_NAME%%' => $this->config['client']['name'],
|
||||
'%%OWNER_ADDRESS%%' => $this->config['client']['address'],
|
||||
'%%OWNER_TAXNUMBER%%' => $this->config['client']['tax_number'],
|
||||
// creator
|
||||
'%%CREATOR_NAME%%' => $fault->getReporter()->getName(),
|
||||
'%%CREATOR_JOB%%' => $fault->getReporter()->getJob(),
|
||||
// '%%CREATOR_EMAIL%%' => $fault->getReporter()->getEmail(),
|
||||
// '%%CREATOR_PHONE%%' => $fault->getReporter()->getPhone(),
|
||||
// confirmer
|
||||
'%%CONFIRMER_NAME%%' => $fault->getConfirmer()->getName(),
|
||||
'%%CONFIRMER_JOB%%' => $fault->getConfirmer()->getJob(),
|
||||
// worker
|
||||
'%%WORKER_NAME%%' => $fault->getConfirmer()->getName(),
|
||||
'%%WORKER_JOB%%' => $fault->getConfirmer()->getJob(),
|
||||
// cost approver
|
||||
'%%APPROVER_NAME%%' => $fault->getApprovedBy() ? $fault->getApprovedBy()->getName() : '',
|
||||
'%%APPROVER_JOB%%' => $fault->getApprovedBy() ? $fault->getApprovedBy()->getJob() : '',
|
||||
// repair acknowledged by
|
||||
'%%ACKNOWLEDGEDBY_NAME%%' => $fault->getAcknowledgedBy() ? $fault->getAcknowledgedBy()->getName() : '',
|
||||
'%%ACKNOWLEDGEDBY_JOB%%' => $fault->getAcknowledgedBy()? $fault->getAcknowledgedBy()->getJob() : '',
|
||||
// fault
|
||||
'%%FAULT_LOCATION_ROOMNUMBER%%' => $fault->getFacilityLocation()->getRoomNumber(),
|
||||
'%%FAULT_LOCATION_NAME%%' => $fault->getFacilityLocation()->getName(),
|
||||
'%%FAULT_LOCATION_SIZE%%' => $fault->getFacilityLocation()->getSize(),
|
||||
'%%FAULT_LOCATION_DESC%%' => $fault->getFacilityLocationDescription(),
|
||||
'%%FAULT_COST_TYPE%%' =>
|
||||
($fault->getWorkCostEstimate() > 100000 || $fault->getMaterialCostEstimate() > 200000)
|
||||
? 'NM'
|
||||
: 'KM',
|
||||
'%%FAULT_ERROR_CATEGORY_TYPE%%' => $fault->getErrorCategory()->getMappedType(),
|
||||
'%%FAULT_CODE%%' => $fault->getSolutionTimeInterval()->getCode(),
|
||||
'%%FAULT_ERROR_CATEGORY_ID%%' => $fault->getErrorCategory()->getId(),
|
||||
'%%FAULT_ERROR_CATEGORY_NAME%%' => $fault->getErrorCategory()->getName(),
|
||||
'%%FAULT_ERROR_DESC%%' => $fault->getErrorDescription(),
|
||||
'%%FAULT_ERROR_ORIGIN%%' => $fault->getErrorOrigin()->getName(),
|
||||
'%%FAULT_ERROR_URGENCY%%' => $fault->getSolutionTimeInterval()->getName(),
|
||||
];
|
||||
return str_replace(array_keys($replacementMatches), array_values($replacementMatches), $template);
|
||||
}
|
||||
|
||||
private function fillMaintenanceSheetTemplate(string $template, Maintenance $maintenance): string
|
||||
{
|
||||
$formatString = "Y.m.d H:i";
|
||||
$replacementMatches = [
|
||||
'%%SELF_NAME%%' => $this->config['self']['name'],
|
||||
'%%SELF_ADDRESS%%' => $this->config['self']['address'],
|
||||
'%%SELF_TAXNUMBER%%' => $this->config['self']['tax_number'],
|
||||
'%%OWNER_NAME%%' => $this->config['client']['name'],
|
||||
'%%OWNER_ADDRESS%%' => $this->config['client']['address'],
|
||||
'%%OWNER_TAXNUMBER%%' => $this->config['client']['tax_number'],
|
||||
|
||||
'%%MS_ID%%' => $maintenance->getWorksheetNumber(),
|
||||
'%%MAINTENANCE_GROUP%%' => $maintenance->getDeviceName(),
|
||||
'%%MAINTENANCE_DEVICE%%' => $maintenance->getComponentName(),
|
||||
'%%WORK_DESCRIPTION%%' => $maintenance->getWorkDescription(),
|
||||
|
||||
// '%%CONFIRMER_NAME%%' => $maintenance->getStartedBy()->getName(),
|
||||
// '%%CONFIRMER_JOB%%' => $maintenance->getStartedBy()->getJob(),
|
||||
'%%MAINTENER_NAME%%' => $maintenance->getResponsible(),
|
||||
'%%MAINTENER_JOB%%' => '',
|
||||
|
||||
'%%SHOULD_START_AT%%' => $maintenance->getShouldStartAt()->format($formatString),
|
||||
'%%SHOULDBE_DONE_BY%%' => $maintenance->getShouldBeDoneBy()->format($formatString),
|
||||
|
||||
'%%STARTED_AT%%' => '',
|
||||
// '%%STARTED_AT%%' => $maintenance->getWorkStarted()
|
||||
// ? $maintenance->getWorkStarted()->format($formatString) : '',
|
||||
'%%FINISHED_AT%%' => $maintenance->getWorkFinished()
|
||||
? $maintenance->getWorkStarted()->format($formatString) : '',
|
||||
|
||||
'%%TIMESPENT_HOUR%%' => '',
|
||||
'%%TIMESPENT_DAY%%' => '',
|
||||
|
||||
// '%%FINISHEDBY_NAME%%' => $maintenance->getFinishedBy()
|
||||
// ? $maintenance->getFinishedBy()->getName() : '',
|
||||
// '%%FINISHEDBY_JOB%%' => $maintenance->getFinishedBy()
|
||||
// ? $maintenance->getFinishedBy()->getJob() : '',
|
||||
'%%ACKNOWLEDGED_AT%%' => $maintenance->getWorkFinished()
|
||||
? $maintenance->getWorkStarted()->format($formatString) : '',
|
||||
];
|
||||
return str_replace(array_keys($replacementMatches), array_values($replacementMatches), $template);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @param int $year
|
||||
// * @param int $month
|
||||
// * @return string
|
||||
// */
|
||||
// public function getMonthlyReport($year, $month): string
|
||||
// {
|
||||
// $data = $this->getMonthlyReportData($year, $month);
|
||||
// $compiledData = $this->compileTableData($data);
|
||||
// setlocale(LC_TIME, "hu_HU.UTF-8");
|
||||
// $compiledData['reportDatePeriod'] = strftime("%Y. %B", strtotime("${year}-${month}"));
|
||||
//
|
||||
// $pdfTemplate = $this->fillMonthlyReportTemplate(
|
||||
// file_get_contents(self::MONTHLY_REPORT_TEMPLATE_FILE),
|
||||
// $compiledData
|
||||
// );
|
||||
// $styleData = file_get_contents(self::MONTHLY_REPORT_STYLESHEET_FILE);
|
||||
//
|
||||
// $loader = new LoaderImpl();
|
||||
// $loader->setFontFile("data/pdf-resources/config/font-config.xml");
|
||||
//
|
||||
// $builder = FacadeBuilder::create($loader)
|
||||
// ->setCache('File', ['cache_dir' => 'data/cache'])
|
||||
// ->setEngineType('pdf');
|
||||
// $pdfRenderer = $builder->build();
|
||||
//
|
||||
// return $pdfRenderer->render($pdfTemplate, $styleData);
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * @param string $template
|
||||
// * @param array $data
|
||||
// * @return string
|
||||
// */
|
||||
// private function fillMonthlyReportTemplate(string $template, array $data): string
|
||||
// {
|
||||
// $replacementMatches = [
|
||||
// '%%REPORT_DATE_PERIOD%%' => $data['reportDatePeriod'],
|
||||
// '%%REPORT_DATE_PRINTED%%' => date("Y-m-d"),
|
||||
//
|
||||
// '%%TABLE_DATA%%' => $data['itemTemplate'],
|
||||
//
|
||||
// '%%SUM_MATERIAL_COST%%' => $data['sumMaterialCost'],
|
||||
// '%%SUM_WORK_COST%%' => $data['sumWorkCost'],
|
||||
// '%%LATE_PENALTY_COST%%' => $data['lateFine'],
|
||||
// '%%SUM_NETT_COST%%' => $data['sumNettCost'],
|
||||
// '%%VAT_COST%%' => $data['vat'],
|
||||
// '%%BRUT_COST%%' => $data['sumTotalCost'],
|
||||
// ];
|
||||
// return str_replace(array_keys($replacementMatches), array_values($replacementMatches), $template);
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * @param $data
|
||||
// * @return array compiled data
|
||||
// * @todo late fine calculation
|
||||
// */
|
||||
// private function compileTableData($data)
|
||||
// {
|
||||
// /** @var FaultService $faultService */
|
||||
// $faultService = $this->container->get(FaultService::class);
|
||||
//
|
||||
// $sumMaterialCost = 0;
|
||||
// $sumWorkCost = 0;
|
||||
// $sumLateFine = 0;
|
||||
// $itemTemplate = '';
|
||||
//
|
||||
// $instituteTpl = file_get_contents(self::MONTHLY_REPORT_INSTITUTE_TPL);
|
||||
// $faultTpl = file_get_contents(self::MONTHLY_REPORT_FAULT_TPL);
|
||||
// $faultCostItemTpl = file_get_contents(self::MONTHLY_REPORT_FAULT_COST_ITEM_TPL);
|
||||
// $faultCostWorkTpl = file_get_contents(self::MONTHLY_REPORT_FAULT_COST_WORK_TPL);
|
||||
// $faultCostLateTpl = file_get_contents(self::MONTHLY_REPORT_FAULT_COST_LATE_TPL);
|
||||
//
|
||||
// /** @var Institute $institute */
|
||||
// foreach ($data as $institute) {
|
||||
// $itemTemplate .= sprintf(
|
||||
// $instituteTpl,
|
||||
// $institute->getId(),
|
||||
// $institute->getName(),
|
||||
// $institute->getAddress()
|
||||
// );
|
||||
//
|
||||
// foreach ($institute->getFaults() as $fault) {
|
||||
// $itemTemplate .= sprintf(
|
||||
// $faultTpl,
|
||||
// $fault->getWorksheetNumber(),
|
||||
// $fault->getErrorCategory()->getName(),
|
||||
// $fault->getFacilityLocation()->getName()
|
||||
// );
|
||||
//
|
||||
// foreach ($fault->getUsedMaterials() as $material) {
|
||||
// $itemTemplate .= sprintf(
|
||||
// $faultCostItemTpl,
|
||||
// $material['name'],
|
||||
// $material['unit'],
|
||||
// $material['amount'],
|
||||
// $material['nettPrice'],
|
||||
// $material['amount'] * $material['nettPrice']
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// $sumMaterialCost += $faultService->calculateMaterialCost($fault);
|
||||
// $workCost = $faultService->calculateWorkCost($fault);
|
||||
// $sumWorkCost += $workCost;
|
||||
// $workHours = $faultService->calculateWorkHours($fault);
|
||||
//
|
||||
// $lateFine = $faultService->calculateLateFine($fault);
|
||||
// $sumLateFine += $lateFine->sum();
|
||||
//
|
||||
// $itemTemplate .= sprintf($faultCostWorkTpl, $workHours, $workCost);
|
||||
// foreach ($lateFine->getItems() as $item) {
|
||||
// $itemTemplate .= sprintf(
|
||||
// $faultCostLateTpl,
|
||||
// $item->getUnit(),
|
||||
// $item->getCount(),
|
||||
// -$item->getAmount(),
|
||||
// -$item->sum()
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// $sumNettCost = $sumWorkCost + $sumMaterialCost - $sumLateFine;
|
||||
// return [
|
||||
// 'itemTemplate' => $itemTemplate,
|
||||
// 'sumMaterialCost' => $sumMaterialCost,
|
||||
// 'sumWorkCost' => $sumWorkCost,
|
||||
// 'lateFine' => $sumLateFine,
|
||||
// 'sumNettCost' => $sumNettCost,
|
||||
// 'vat' => floor($sumNettCost * 0.27),
|
||||
// 'sumTotalCost' => floor($sumNettCost * 1.27),
|
||||
// ];
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * @param int $year
|
||||
// * @param int $month
|
||||
// * @return array
|
||||
// */
|
||||
// private function getMonthlyReportData($year, $month)
|
||||
// {
|
||||
// $qb = $this->em->createQueryBuilder();
|
||||
//
|
||||
// $entities = $qb->select('i', 'f', 'fl', 'ec')
|
||||
// ->from(Institute::class, 'i')
|
||||
// ->innerJoin('i.faults', 'f')
|
||||
// ->innerJoin('f.facilityLocation', 'fl')
|
||||
// ->innerJoin('f.errorCategory', 'ec')
|
||||
// ->where('YEAR(f.workFinished) = :year')
|
||||
// ->andWhere('MONTH(f.workFinished) = :month')
|
||||
// ->orderBy('i.id')
|
||||
// ->setParameter('year', $year)
|
||||
// ->setParameter('month', $month)
|
||||
// ->getQuery()
|
||||
// ->getResult(Query::HYDRATE_OBJECT);
|
||||
//
|
||||
// return $entities;
|
||||
// }
|
||||
}
|
||||
20
src/App/Service/PdfServiceFactory.php
Normal file
20
src/App/Service/PdfServiceFactory.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class PdfServiceFactory
|
||||
{
|
||||
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
/** @var EntityManager $em */
|
||||
$em = $container->get('doctrine.entity_manager.orm_default');
|
||||
/** @var FaultManagerService $faultManager */
|
||||
$faultManager = $container->get(FaultManagerService::class);
|
||||
$config = $container->get('config');
|
||||
return new PdfService($em, $faultManager, $config);
|
||||
}
|
||||
}
|
||||
36
src/App/Service/RbaclFactory.php
Normal file
36
src/App/Service/RbaclFactory.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use Interop\Container\ContainerInterface;
|
||||
use Zend\Config\Config;
|
||||
use Zend\Permissions\Rbac\Rbac;
|
||||
|
||||
class RbaclFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container): Rbac
|
||||
{
|
||||
$emptyCfg = new Config([]);
|
||||
|
||||
$config = new Config($container->get('config')['acl_config']);
|
||||
$routeGuard = $config->get('route_guard', $emptyCfg);
|
||||
|
||||
$rbac = new Rbac();
|
||||
$rbac->setCreateMissingRoles(true);
|
||||
// roles
|
||||
$roles = $routeGuard->get('roles', $emptyCfg)->toArray();
|
||||
foreach ($roles as $roleName => $parents) {
|
||||
$rbac->addRole($roleName, $parents);
|
||||
}
|
||||
|
||||
// permissions
|
||||
$permissionCfg = $routeGuard->get('permissions', $emptyCfg)->toArray();
|
||||
foreach ($permissionCfg as $role => $permissions) {
|
||||
foreach ($permissions as $permission) {
|
||||
$rbac->getRole($role)->addPermission($permission);
|
||||
}
|
||||
}
|
||||
|
||||
return $rbac;
|
||||
}
|
||||
}
|
||||
32
src/App/Service/SolutionTimeIntervalService.php
Normal file
32
src/App/Service/SolutionTimeIntervalService.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Entity\SolutionTimeInterval;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
|
||||
class SolutionTimeIntervalService
|
||||
{
|
||||
/**
|
||||
* @var EntityManager
|
||||
*/
|
||||
private $em;
|
||||
|
||||
public function __construct(EntityManager $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return FacilityLocations in a tree form
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getList()
|
||||
{
|
||||
/** @var EntityRepository $treeRepository */
|
||||
$repository = $this->em->getRepository(SolutionTimeInterval::class);
|
||||
return $repository->findAll();
|
||||
}
|
||||
}
|
||||
16
src/App/Service/SolutionTimeIntervalServiceFactory.php
Normal file
16
src/App/Service/SolutionTimeIntervalServiceFactory.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class SolutionTimeIntervalServiceFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
/** @var EntityManager $em */
|
||||
$em = $container->get('doctrine.entity_manager.orm_default');
|
||||
return new SolutionTimeIntervalService($em);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user