* logger added
* calendar view in maintenance * $year filter support in xlsx and maintenance
This commit is contained in:
parent
b906e360bf
commit
4d52d4b575
@ -29,11 +29,13 @@
|
|||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^7.1",
|
"php": "^7.1",
|
||||||
|
"ext-json": "*",
|
||||||
"dasprid/container-interop-doctrine": "^1.1",
|
"dasprid/container-interop-doctrine": "^1.1",
|
||||||
"doctrine/data-fixtures": "~2.0",
|
"doctrine/data-fixtures": "~2.0",
|
||||||
"gedmo/doctrine-extensions": "^2.4",
|
"gedmo/doctrine-extensions": "^2.4",
|
||||||
"imagine/imagine": "^1.1.0",
|
"imagine/imagine": "^1.1.0",
|
||||||
"lcobucci/jwt": "^3.3",
|
"lcobucci/jwt": "^3.3",
|
||||||
|
"los/loslog": "^3.1",
|
||||||
"monolog/monolog": "^1.24",
|
"monolog/monolog": "^1.24",
|
||||||
"oro/doctrine-extensions": "^1.2",
|
"oro/doctrine-extensions": "^1.2",
|
||||||
"phpoffice/phpexcel": "1.8.1",
|
"phpoffice/phpexcel": "1.8.1",
|
||||||
@ -54,8 +56,7 @@
|
|||||||
"zendframework/zend-mail": "^2.10.0",
|
"zendframework/zend-mail": "^2.10.0",
|
||||||
"zendframework/zend-permissions-rbac": "^3.0.0",
|
"zendframework/zend-permissions-rbac": "^3.0.0",
|
||||||
"zendframework/zend-servicemanager": "^3.3",
|
"zendframework/zend-servicemanager": "^3.3",
|
||||||
"zendframework/zend-stdlib": "^3.1",
|
"zendframework/zend-stdlib": "^3.1"
|
||||||
"ext-json": "*"
|
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^7.0.1",
|
"phpunit/phpunit": "^7.0.1",
|
||||||
|
|||||||
172
composer.lock
generated
172
composer.lock
generated
@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "99fd952d2eafc5dafae9479945333cc4",
|
"content-hash": "be48e23d53e2ae2899e20570e3baa394",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "behat/transliterator",
|
"name": "behat/transliterator",
|
||||||
@ -1333,6 +1333,74 @@
|
|||||||
],
|
],
|
||||||
"time": "2018-11-11T12:23:46+00:00"
|
"time": "2018-11-11T12:23:46+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "los/loslog",
|
||||||
|
"version": "3.1.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/Lansoweb/LosLog.git",
|
||||||
|
"reference": "a6dc0138f2db721ffa134d495972c20b2da2e7b6"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/Lansoweb/LosLog/zipball/a6dc0138f2db721ffa134d495972c20b2da2e7b6",
|
||||||
|
"reference": "a6dc0138f2db721ffa134d495972c20b2da2e7b6",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": "^7.1",
|
||||||
|
"psr/container": "^1.0",
|
||||||
|
"psr/log": "^1.0",
|
||||||
|
"zendframework/zend-diactoros": "^1.7",
|
||||||
|
"zendframework/zend-log": "^2.9",
|
||||||
|
"zendframework/zend-stratigility": "^3.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"mikey179/vfsstream": "^1.6",
|
||||||
|
"phpstan/phpstan": "^0.9.2",
|
||||||
|
"phpunit/phpunit": "^7.0",
|
||||||
|
"rollbar/rollbar": "^1.4",
|
||||||
|
"satooshi/php-coveralls": "^2.0",
|
||||||
|
"squizlabs/php_codesniffer": "^2.7",
|
||||||
|
"zendframework/zend-coding-standard": "^1.0"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"rollbar/rollbar": "Needed if you want to use Rollbar logger"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-develop": "2.0-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"LosMiddleware\\LosLog\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"BSD-3-Clause"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Leandro Silva",
|
||||||
|
"email": "leandro@leandrosilva.info",
|
||||||
|
"homepage": "http://leandrosilva.info"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "LosLog provides some log utility",
|
||||||
|
"homepage": "http://github.com/Lansoweb/LosLog",
|
||||||
|
"keywords": [
|
||||||
|
"expressive",
|
||||||
|
"log",
|
||||||
|
"los",
|
||||||
|
"module",
|
||||||
|
"zf2",
|
||||||
|
"zf3"
|
||||||
|
],
|
||||||
|
"time": "2018-03-16T13:02:56+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "monolog/monolog",
|
"name": "monolog/monolog",
|
||||||
"version": "1.24.0",
|
"version": "1.24.0",
|
||||||
@ -2951,41 +3019,38 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "zendframework/zend-diactoros",
|
"name": "zendframework/zend-diactoros",
|
||||||
"version": "2.0.0",
|
"version": "1.8.6",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/zendframework/zend-diactoros.git",
|
"url": "https://github.com/zendframework/zend-diactoros.git",
|
||||||
"reference": "0bae78192e634774b5584f0210c1232da82cb1ff"
|
"reference": "20da13beba0dde8fb648be3cc19765732790f46e"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/zendframework/zend-diactoros/zipball/0bae78192e634774b5584f0210c1232da82cb1ff",
|
"url": "https://api.github.com/repos/zendframework/zend-diactoros/zipball/20da13beba0dde8fb648be3cc19765732790f46e",
|
||||||
"reference": "0bae78192e634774b5584f0210c1232da82cb1ff",
|
"reference": "20da13beba0dde8fb648be3cc19765732790f46e",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^7.1",
|
"php": "^5.6 || ^7.0",
|
||||||
"psr/http-factory": "^1.0",
|
|
||||||
"psr/http-message": "^1.0"
|
"psr/http-message": "^1.0"
|
||||||
},
|
},
|
||||||
"provide": {
|
"provide": {
|
||||||
"psr/http-factory-implementation": "1.0",
|
|
||||||
"psr/http-message-implementation": "1.0"
|
"psr/http-message-implementation": "1.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"ext-dom": "*",
|
"ext-dom": "*",
|
||||||
"ext-libxml": "*",
|
"ext-libxml": "*",
|
||||||
"http-interop/http-factory-tests": "^0.5.0",
|
|
||||||
"php-http/psr7-integration-tests": "dev-master",
|
"php-http/psr7-integration-tests": "dev-master",
|
||||||
"phpunit/phpunit": "^7.0.2",
|
"phpunit/phpunit": "^5.7.16 || ^6.0.8 || ^7.2.7",
|
||||||
"zendframework/zend-coding-standard": "~1.0.0"
|
"zendframework/zend-coding-standard": "~1.0"
|
||||||
},
|
},
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"extra": {
|
"extra": {
|
||||||
"branch-alias": {
|
"branch-alias": {
|
||||||
"dev-master": "2.0.x-dev",
|
"dev-master": "1.8.x-dev",
|
||||||
"dev-develop": "2.1.x-dev",
|
"dev-develop": "1.9.x-dev",
|
||||||
"dev-release-1.8": "1.8.x-dev"
|
"dev-release-2.0": "2.0.x-dev"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
@ -3005,15 +3070,16 @@
|
|||||||
},
|
},
|
||||||
"notification-url": "https://packagist.org/downloads/",
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
"license": [
|
"license": [
|
||||||
"BSD-3-Clause"
|
"BSD-2-Clause"
|
||||||
],
|
],
|
||||||
"description": "PSR HTTP Message implementations",
|
"description": "PSR HTTP Message implementations",
|
||||||
|
"homepage": "https://github.com/zendframework/zend-diactoros",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"http",
|
"http",
|
||||||
"psr",
|
"psr",
|
||||||
"psr-7"
|
"psr-7"
|
||||||
],
|
],
|
||||||
"time": "2018-09-27T19:49:04+00:00"
|
"time": "2018-09-05T19:29:37+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "zendframework/zend-escaper",
|
"name": "zendframework/zend-escaper",
|
||||||
@ -3661,6 +3727,77 @@
|
|||||||
],
|
],
|
||||||
"time": "2018-04-30T15:20:54+00:00"
|
"time": "2018-04-30T15:20:54+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "zendframework/zend-log",
|
||||||
|
"version": "2.10.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/zendframework/zend-log.git",
|
||||||
|
"reference": "9cec3b092acb39963659c2f32441cccc56b3f430"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/zendframework/zend-log/zipball/9cec3b092acb39963659c2f32441cccc56b3f430",
|
||||||
|
"reference": "9cec3b092acb39963659c2f32441cccc56b3f430",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": "^5.6 || ^7.0",
|
||||||
|
"psr/log": "^1.0",
|
||||||
|
"zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3",
|
||||||
|
"zendframework/zend-stdlib": "^2.7 || ^3.0"
|
||||||
|
},
|
||||||
|
"provide": {
|
||||||
|
"psr/log-implementation": "1.0.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"mikey179/vfsstream": "^1.6",
|
||||||
|
"phpunit/phpunit": "^5.7.15 || ^6.0.8",
|
||||||
|
"zendframework/zend-coding-standard": "~1.0.0",
|
||||||
|
"zendframework/zend-db": "^2.6",
|
||||||
|
"zendframework/zend-escaper": "^2.5",
|
||||||
|
"zendframework/zend-filter": "^2.5",
|
||||||
|
"zendframework/zend-mail": "^2.6.1",
|
||||||
|
"zendframework/zend-validator": "^2.10.1"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"ext-mongo": "mongo extension to use Mongo writer",
|
||||||
|
"ext-mongodb": "mongodb extension to use MongoDB writer",
|
||||||
|
"zendframework/zend-console": "Zend\\Console component to use the RequestID log processor",
|
||||||
|
"zendframework/zend-db": "Zend\\Db component to use the database log writer",
|
||||||
|
"zendframework/zend-escaper": "Zend\\Escaper component, for use in the XML log formatter",
|
||||||
|
"zendframework/zend-mail": "Zend\\Mail component to use the email log writer",
|
||||||
|
"zendframework/zend-validator": "Zend\\Validator component to block invalid log messages"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "2.10.x-dev",
|
||||||
|
"dev-develop": "2.11.x-dev"
|
||||||
|
},
|
||||||
|
"zf": {
|
||||||
|
"component": "Zend\\Log",
|
||||||
|
"config-provider": "Zend\\Log\\ConfigProvider"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Zend\\Log\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"BSD-3-Clause"
|
||||||
|
],
|
||||||
|
"description": "component for general purpose logging",
|
||||||
|
"homepage": "https://github.com/zendframework/zend-log",
|
||||||
|
"keywords": [
|
||||||
|
"log",
|
||||||
|
"logging",
|
||||||
|
"zf2"
|
||||||
|
],
|
||||||
|
"time": "2018-04-09T21:59:51+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "zendframework/zend-mail",
|
"name": "zendframework/zend-mail",
|
||||||
"version": "2.10.0",
|
"version": "2.10.0",
|
||||||
@ -6175,7 +6312,8 @@
|
|||||||
"prefer-stable": true,
|
"prefer-stable": true,
|
||||||
"prefer-lowest": false,
|
"prefer-lowest": false,
|
||||||
"platform": {
|
"platform": {
|
||||||
"php": "^7.1"
|
"php": "^7.1",
|
||||||
|
"ext-json": "*"
|
||||||
},
|
},
|
||||||
"platform-dev": []
|
"platform-dev": []
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,7 +49,8 @@ return [
|
|||||||
'api.fault-comment.post',
|
'api.fault-comment.post',
|
||||||
'api.fault-reject.post',
|
'api.fault-reject.post',
|
||||||
'api.maintenance',
|
'api.maintenance',
|
||||||
'api.maintenance.upcoming'
|
'api.maintenance.upcoming',
|
||||||
|
'api.maintenance.calendar',
|
||||||
],
|
],
|
||||||
'ufo' => [
|
'ufo' => [
|
||||||
'api.fault.put',
|
'api.fault.put',
|
||||||
@ -69,6 +70,7 @@ return [
|
|||||||
'api.maintenance',
|
'api.maintenance',
|
||||||
'api.maintenance.put',
|
'api.maintenance.put',
|
||||||
'api.maintenance.upcoming',
|
'api.maintenance.upcoming',
|
||||||
|
'api.maintenance.calendar',
|
||||||
],
|
],
|
||||||
'karbantarto' => [
|
'karbantarto' => [
|
||||||
],
|
],
|
||||||
|
|||||||
27
config/autoload/loslog.global.php
Normal file
27
config/autoload/loslog.global.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
use Zend\Stratigility\Middleware\ErrorHandler;
|
||||||
|
|
||||||
|
return [
|
||||||
|
'dependencies' => [
|
||||||
|
'factories' => [
|
||||||
|
LosMiddleware\LosLog\LosLog::class => LosMiddleware\LosLog\LosLogFactory::class,
|
||||||
|
LosMiddleware\LosLog\HttpLog::class => LosMiddleware\LosLog\HttpLogFactory::class,
|
||||||
|
Psr\Log\LoggerInterface::class => LosMiddleware\LosLog\LoggerFactory::class,
|
||||||
|
],
|
||||||
|
'delegators' => [
|
||||||
|
ErrorHandler::class => [
|
||||||
|
LosMiddleware\LosLog\ErrorHandlerListenerDelegatorFactory::class,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'loslog' => [
|
||||||
|
'log_dir' => 'data/log',
|
||||||
|
'error_logger_file' => 'error.log',
|
||||||
|
'exception_logger_file' => 'exception.log',
|
||||||
|
'static_logger_file' => 'static.log',
|
||||||
|
'http_logger_file' => 'http.log',
|
||||||
|
'log_request' => false,
|
||||||
|
'log_response' => false,
|
||||||
|
'full' => false,
|
||||||
|
],
|
||||||
|
];
|
||||||
@ -13,6 +13,7 @@ $cacheConfig = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
$aggregator = new ConfigAggregator([
|
$aggregator = new ConfigAggregator([
|
||||||
|
\Zend\Log\ConfigProvider::class,
|
||||||
\Zend\Cache\ConfigProvider::class,
|
\Zend\Cache\ConfigProvider::class,
|
||||||
\Zend\Expressive\ConfigProvider::class,
|
\Zend\Expressive\ConfigProvider::class,
|
||||||
\Zend\Expressive\Helper\ConfigProvider::class,
|
\Zend\Expressive\Helper\ConfigProvider::class,
|
||||||
|
|||||||
@ -40,33 +40,35 @@ return function (
|
|||||||
$app->get('/', App\Handler\PingHandler::class, 'home');
|
$app->get('/', App\Handler\PingHandler::class, 'home');
|
||||||
$app->get('/api/ping', App\Handler\PingHandler::class, 'api.ping');
|
$app->get('/api/ping', App\Handler\PingHandler::class, 'api.ping');
|
||||||
|
|
||||||
$app->get('/api/maintenance/upcoming', App\Handler\MaintenanceUpcomingHandler::class, 'api.maintenance.upcoming');
|
$app->get('/api/maintenance/calendar/{year:\d+}', App\Handler\MaintenanceCalendarHandler::class, 'api.maintenance.calendar');
|
||||||
$app->route('/api/maintenance[/{id:\w+}]', App\Handler\MaintenanceHandler::class, ['GET', 'OPTIONS'], 'api.maintenance');
|
$app->get('/api/maintenance/upcoming/{year:\d+}', App\Handler\MaintenanceUpcomingHandler::class, 'api.maintenance.upcoming');
|
||||||
$app->route('/api/maintenance/{id:\w+}', App\Handler\MaintenanceHandler::class, ['PUT'], 'api.maintenance.put');
|
$app->get('/api/maintenance/{year:\d+}', App\Handler\MaintenanceHandler::class, 'api.maintenance.list');
|
||||||
|
$app->get('/api/maintenance/{year:\d+}/{id:w\+}', App\Handler\MaintenanceHandler::class, 'api.maintenance.get');
|
||||||
|
$app->put('/api/maintenance/{id:\w+}', App\Handler\MaintenanceHandler::class, 'api.maintenance.put');
|
||||||
|
|
||||||
// authentication and user management
|
// authentication and user management
|
||||||
$app->route('/api/auth/login', App\Handler\Auth\AuthHandler::class, ['POST', 'OPTIONS'], 'api.auth.login');
|
$app->post('/api/auth/login', App\Handler\Auth\AuthHandler::class, 'api.auth.login');
|
||||||
$app->route('/api/auth/renew', App\Handler\Auth\AuthHandler::class, ['GET', 'OPTIONS'], 'api.auth.renew');
|
$app->get('/api/auth/renew', App\Handler\Auth\AuthHandler::class, 'api.auth.renew');
|
||||||
$app->route('/api/user[/{id:\d+}]', App\Handler\User\UserHandler::class, ['GET', 'PUT', 'OPTIONS'], 'api.user.profile');
|
$app->route('/api/user[/{id:\d+}]', App\Handler\User\UserHandler::class, ['GET', 'PUT'], 'api.user.profile');
|
||||||
$app->route('/api/user/password', App\Handler\User\PasswordHandler::class, ['POST', 'OPTIONS'], 'api.user.password');
|
$app->post('/api/user/password', App\Handler\User\PasswordHandler::class, 'api.user.password');
|
||||||
|
|
||||||
// fault management
|
// fault management
|
||||||
$app->route('/api/fault[/{id:\d+}]', App\Handler\Fault\FaultHandler::class, ['GET', 'OPTIONS'], 'api.fault.get'); // list/show
|
$app->get('/api/fault[/{id:\d+}]', App\Handler\Fault\FaultHandler::class, 'api.fault.get'); // list/show
|
||||||
$app->post('/api/fault', App\Handler\Fault\FaultHandler::class, 'api.fault.post'); // create
|
$app->post('/api/fault', App\Handler\Fault\FaultHandler::class, 'api.fault.post'); // create
|
||||||
$app->put('/api/fault/{id:\d+}', App\Handler\Fault\FaultHandler::class, 'api.fault.put'); // update
|
$app->put('/api/fault/{id:\d+}', App\Handler\Fault\FaultHandler::class, 'api.fault.put'); // update
|
||||||
$app->delete('/api/fault/{id:\d+}', App\Handler\Fault\FaultHandler::class, 'api.fault.delete');
|
$app->delete('/api/fault/{id:\d+}', App\Handler\Fault\FaultHandler::class, 'api.fault.delete');
|
||||||
|
|
||||||
$app->route('/api/fault-reject/{id:\d+}', App\Handler\Fault\FaultRejectHandler::class, ['POST', 'OPTIONS'], 'api.fault-reject.post');
|
$app->post('/api/fault-reject/{id:\d+}', App\Handler\Fault\FaultRejectHandler::class, 'api.fault-reject.post');
|
||||||
$app->route('/api/fault-comment/{id:\d+}', App\Handler\Fault\FaultCommentHandler::class, ['POST', 'OPTIONS'], 'api.fault-comment.post');
|
$app->post('/api/fault-comment/{id:\d+}', App\Handler\Fault\FaultCommentHandler::class, 'api.fault-comment.post');
|
||||||
$app->route('/api/fault-attachment/{id:\d+}/{type}', App\Handler\Fault\FaultAttachmentHandler::class, ['POST', 'OPTIONS'], 'api.fault-attachment.post');
|
$app->post('/api/fault-attachment/{id:\d+}/{type}', App\Handler\Fault\FaultAttachmentHandler::class, 'api.fault-attachment.post');
|
||||||
$app->route('/show-attachment/{id:\d+}', App\Handler\Fault\FaultAttachmentHandler::class, ['GET', 'OPTIONS'], 'show-attachment');
|
$app->get('/show-attachment/{id:\d+}', App\Handler\Fault\FaultAttachmentHandler::class, 'show-attachment');
|
||||||
|
|
||||||
$app->route('/hibajegy-pdf/{id:\d+}[/{filename}]', App\Handler\Pdf\GenerateWorksheetHandler::class, ['GET', 'OPTIONS'], 'hibajegy-pdf');
|
$app->get('/hibajegy-pdf/{id:\d+}[/{filename}]', App\Handler\Pdf\GenerateWorksheetHandler::class, 'hibajegy-pdf');
|
||||||
$app->route('/karbantartasjegy-pdf/{id:\w+}[/{filename}]', App\Handler\Pdf\GenerateMaintenanceSheetHandler::class, ['GET', 'OPTIONS'], 'karbantartasjegy-pdf');
|
$app->get('/karbantartasjegy-pdf/{id:\w+}[/{filename}]', App\Handler\Pdf\GenerateMaintenanceSheetHandler::class, 'karbantartasjegy-pdf');
|
||||||
|
|
||||||
// core data
|
// core data
|
||||||
$app->route('/api/error-category', App\Handler\ErrorCategoryHandler::class, ['GET', 'OPTIONS'], 'api.error-category.get'); // list/show
|
$app->get('/api/error-category', App\Handler\ErrorCategoryHandler::class, 'api.error-category.get'); // list/show
|
||||||
$app->route('/api/error-origin', App\Handler\ErrorOriginHandler::class, ['GET', 'OPTIONS'], 'api.error-origin.get'); // list/show
|
$app->get('/api/error-origin', App\Handler\ErrorOriginHandler::class, 'api.error-origin.get'); // list/show
|
||||||
$app->route('/api/facility-location', App\Handler\FacilityLocationHandler::class, ['GET', 'OPTIONS'], 'api.facility-location.get'); // list/show
|
$app->get('/api/facility-location', App\Handler\FacilityLocationHandler::class, 'api.facility-location.get'); // list/show
|
||||||
$app->route('/api/solution-time-interval', App\Handler\SolutionTimeIntervalHandler::class, ['GET', 'OPTIONS'], 'api.solution-time-interval.get'); // list/show
|
$app->get('/api/solution-time-interval', App\Handler\SolutionTimeIntervalHandler::class, 'api.solution-time-interval.get'); // list/show
|
||||||
};
|
};
|
||||||
|
|||||||
@ -42,6 +42,7 @@ class ConfigProvider
|
|||||||
'factories' => [
|
'factories' => [
|
||||||
Handler\MaintenanceHandler::class => Handler\MaintenanceFactory::class,
|
Handler\MaintenanceHandler::class => Handler\MaintenanceFactory::class,
|
||||||
Handler\MaintenanceUpcomingHandler::class => Handler\MaintenanceUpcomingFactory::class,
|
Handler\MaintenanceUpcomingHandler::class => Handler\MaintenanceUpcomingFactory::class,
|
||||||
|
Handler\MaintenanceCalendarHandler::class => Handler\MaintenanceCalendarFactory::class,
|
||||||
|
|
||||||
Handler\Auth\AuthHandler::class => Handler\Auth\AuthFactory::class,
|
Handler\Auth\AuthHandler::class => Handler\Auth\AuthFactory::class,
|
||||||
Handler\User\UserHandler::class => Handler\User\UserFactory::class,
|
Handler\User\UserHandler::class => Handler\User\UserFactory::class,
|
||||||
|
|||||||
19
src/App/Handler/MaintenanceCalendarFactory.php
Normal file
19
src/App/Handler/MaintenanceCalendarFactory.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Handler;
|
||||||
|
|
||||||
|
use App\Service\MaintenanceManagerService;
|
||||||
|
use Interop\Container\ContainerInterface;
|
||||||
|
|
||||||
|
class MaintenanceCalendarFactory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param ContainerInterface $container
|
||||||
|
* @return MaintenanceCalendarHandler
|
||||||
|
*/
|
||||||
|
public function __invoke(ContainerInterface $container): MaintenanceCalendarHandler
|
||||||
|
{
|
||||||
|
$maintenanceManagerService = $container->get(MaintenanceManagerService::class);
|
||||||
|
return new MaintenanceCalendarHandler($maintenanceManagerService);
|
||||||
|
}
|
||||||
|
}
|
||||||
34
src/App/Handler/MaintenanceCalendarHandler.php
Normal file
34
src/App/Handler/MaintenanceCalendarHandler.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Handler;
|
||||||
|
|
||||||
|
use ApiLibs\AbstractHandler\CrudHandler;
|
||||||
|
use App\Service\MaintenanceManagerService;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
use Zend\Diactoros\Response\JsonResponse;
|
||||||
|
|
||||||
|
class MaintenanceCalendarHandler extends CrudHandler
|
||||||
|
{
|
||||||
|
/** @var MaintenanceManagerService */
|
||||||
|
private $maintenanceManagerService;
|
||||||
|
|
||||||
|
public function __construct(MaintenanceManagerService $maintenanceManagerService)
|
||||||
|
{
|
||||||
|
$this->maintenanceManagerService = $maintenanceManagerService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renew auth token
|
||||||
|
*
|
||||||
|
* @param ServerRequestInterface $request
|
||||||
|
* @return ResponseInterface
|
||||||
|
* @throws \PHPExcel_Exception
|
||||||
|
* @throws \PHPExcel_Reader_Exception
|
||||||
|
*/
|
||||||
|
public function getList(ServerRequestInterface $request): ResponseInterface
|
||||||
|
{
|
||||||
|
$year = (int)$request->getAttribute('year', date("Y"));
|
||||||
|
return new JsonResponse($this->maintenanceManagerService->getCalendarMaintenanceList($year));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -26,7 +26,8 @@ class MaintenanceHandler extends CrudHandler
|
|||||||
*/
|
*/
|
||||||
public function getList(ServerRequestInterface $request): ResponseInterface
|
public function getList(ServerRequestInterface $request): ResponseInterface
|
||||||
{
|
{
|
||||||
return new JsonResponse($this->maintenanceManagerService->getMaintenanceList()->getValues());
|
$year = (int)$request->getAttribute('year', date("Y"));
|
||||||
|
return new JsonResponse($this->maintenanceManagerService->getMaintenanceList($year)->getValues());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,7 +40,8 @@ class MaintenanceHandler extends CrudHandler
|
|||||||
public function get(ServerRequestInterface $request): ResponseInterface
|
public function get(ServerRequestInterface $request): ResponseInterface
|
||||||
{
|
{
|
||||||
$hash = $request->getAttribute(self::IDENTIFIER_NAME);
|
$hash = $request->getAttribute(self::IDENTIFIER_NAME);
|
||||||
return new JsonResponse($this->maintenanceManagerService->get($hash));
|
$year = (int)$request->getAttribute('year', date("Y"));
|
||||||
|
return new JsonResponse($this->maintenanceManagerService->get($hash, $year));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,7 +55,7 @@ class MaintenanceHandler extends CrudHandler
|
|||||||
{
|
{
|
||||||
$hash = $request->getAttribute(self::IDENTIFIER_NAME);
|
$hash = $request->getAttribute(self::IDENTIFIER_NAME);
|
||||||
$data = $this->getRequestData($request);
|
$data = $this->getRequestData($request);
|
||||||
$jwt = $request->getAttribute('token');
|
$token = $request->getAttribute('token');
|
||||||
return new JsonResponse($this->maintenanceManagerService->update($hash, $data, $jwt->uid));
|
return new JsonResponse($this->maintenanceManagerService->update($hash, $data, $token['uid']));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,6 +26,7 @@ class MaintenanceUpcomingHandler extends CrudHandler
|
|||||||
*/
|
*/
|
||||||
public function getList(ServerRequestInterface $request): ResponseInterface
|
public function getList(ServerRequestInterface $request): ResponseInterface
|
||||||
{
|
{
|
||||||
return new JsonResponse($this->maintenanceManagerService->getUpcomingMaintenanceList()->getValues());
|
$year = (int)$request->getAttribute('year', date("Y"));
|
||||||
|
return new JsonResponse($this->maintenanceManagerService->getUpcomingMaintenanceList($year)->getValues());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,29 +25,36 @@ class MaintenanceManagerService
|
|||||||
/** @var UserService */
|
/** @var UserService */
|
||||||
private $userService;
|
private $userService;
|
||||||
|
|
||||||
/** @var int */
|
|
||||||
private $year;
|
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
EntityManager $em,
|
EntityManager $em,
|
||||||
DoctrineObject $hydrator,
|
DoctrineObject $hydrator,
|
||||||
XlsxParserService $xlsxParserService,
|
XlsxParserService $xlsxParserService,
|
||||||
UserService $userService
|
UserService $userService
|
||||||
) {
|
) {
|
||||||
// $this->year = date("Y");
|
|
||||||
$this->year = 2018;
|
|
||||||
$this->em = $em;
|
$this->em = $em;
|
||||||
$this->hydrator = $hydrator;
|
$this->hydrator = $hydrator;
|
||||||
$this->xlsxParserService = $xlsxParserService;
|
$this->xlsxParserService = $xlsxParserService;
|
||||||
$this->userService = $userService;
|
$this->userService = $userService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMaintenanceList(): ArrayCollection
|
/**
|
||||||
|
* @param int $year
|
||||||
|
* @return ArrayCollection
|
||||||
|
* @throws \PHPExcel_Exception
|
||||||
|
* @throws \PHPExcel_Reader_Exception
|
||||||
|
*/
|
||||||
|
public function getMaintenanceList(int $year): ArrayCollection
|
||||||
{
|
{
|
||||||
return $this->getUpdatedXlsxData();
|
return $this->getUpdatedXlsxData($year);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUpcomingMaintenanceList(): ArrayCollection
|
/**
|
||||||
|
* @param int $year
|
||||||
|
* @return ArrayCollection
|
||||||
|
* @throws \PHPExcel_Exception
|
||||||
|
* @throws \PHPExcel_Reader_Exception
|
||||||
|
*/
|
||||||
|
public function getUpcomingMaintenanceList(int $year): ArrayCollection
|
||||||
{
|
{
|
||||||
$firstDayOfThisWeek = new \DateTime("@" . strtotime(sprintf("-%s days", date("N") - 0)));
|
$firstDayOfThisWeek = new \DateTime("@" . strtotime(sprintf("-%s days", date("N") - 0)));
|
||||||
$firstDayOfThisWeek
|
$firstDayOfThisWeek
|
||||||
@ -55,7 +62,7 @@ class MaintenanceManagerService
|
|||||||
->setTime(0, 0);
|
->setTime(0, 0);
|
||||||
$twoWeeksFromNow = (clone $firstDayOfThisWeek)->add(\DateInterval::createFromDateString("+14 days"));
|
$twoWeeksFromNow = (clone $firstDayOfThisWeek)->add(\DateInterval::createFromDateString("+14 days"));
|
||||||
|
|
||||||
$deviceGroups = $this->getUpdatedXlsxData();
|
$deviceGroups = $this->getUpdatedXlsxData($year);
|
||||||
|
|
||||||
foreach ($deviceGroups as $deviceGroup) {
|
foreach ($deviceGroups as $deviceGroup) {
|
||||||
/** @var DeviceGroup $deviceGroup */
|
/** @var DeviceGroup $deviceGroup */
|
||||||
@ -82,15 +89,57 @@ class MaintenanceManagerService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return DeviceGroup[]|ArrayCollection
|
* @param $year
|
||||||
|
* @return array
|
||||||
|
* @throws \PHPExcel_Exception
|
||||||
|
* @throws \PHPExcel_Reader_Exception
|
||||||
*/
|
*/
|
||||||
private function getUpdatedXlsxData()
|
public function getCalendarMaintenanceList($year): array
|
||||||
|
{
|
||||||
|
$result = [];
|
||||||
|
|
||||||
|
$deviceGroups = $this->getUpdatedXlsxData($year);
|
||||||
|
foreach ($deviceGroups as $deviceGroup) {
|
||||||
|
/** @var DeviceGroup $deviceGroup */
|
||||||
|
foreach ($deviceGroup->getDevices() as $device) {
|
||||||
|
foreach ($device->getTasks() as $task) {
|
||||||
|
$result[$task->getMonth()][] = [
|
||||||
|
'id' => $task->getHash(),
|
||||||
|
'state' => $task->getState(),
|
||||||
|
'month' => $task->getMonth(),
|
||||||
|
'start' => $task->getShouldStartAt()->format("Y-m-d"),
|
||||||
|
'finish' => $task->getShouldBeDoneBy()->format("Y-m-d"),
|
||||||
|
'group' => $deviceGroup->getName(),
|
||||||
|
'device' => [
|
||||||
|
'name' => $device->getName(),
|
||||||
|
'count' => $device->getCount(),
|
||||||
|
'work' => $device->getWorkDescription(),
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// $devices = $deviceGroup->getDevices()->filter(function (Device $device) {
|
||||||
|
// return count($device->getTasks());
|
||||||
|
// });
|
||||||
|
// $deviceGroup->setDevices($devices);
|
||||||
|
}
|
||||||
|
return array_values($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $year
|
||||||
|
* @return DeviceGroup[]|ArrayCollection
|
||||||
|
* @throws \PHPExcel_Exception
|
||||||
|
* @throws \PHPExcel_Reader_Exception
|
||||||
|
*/
|
||||||
|
private function getUpdatedXlsxData($year)
|
||||||
{
|
{
|
||||||
/** @var DeviceGroup[] $loadedCacheData */
|
/** @var DeviceGroup[] $loadedCacheData */
|
||||||
$loadedCacheData = $this->xlsxParserService->getXlsxData();
|
$loadedCacheData = $this->xlsxParserService->getXlsxData($year);
|
||||||
|
|
||||||
/** @var Maintenance[] $dbMaintenances */
|
/** @var Maintenance[] $dbMaintenances */
|
||||||
$dbMaintenances = $this->getMaintenancesInYear($this->year);
|
$dbMaintenances = $this->getMaintenancesInYear($year);
|
||||||
foreach ($dbMaintenances as $maintenance) {
|
foreach ($dbMaintenances as $maintenance) {
|
||||||
foreach ($loadedCacheData as &$deviceGroup) {
|
foreach ($loadedCacheData as &$deviceGroup) {
|
||||||
foreach ($deviceGroup->getDevices() as &$device) {
|
foreach ($deviceGroup->getDevices() as &$device) {
|
||||||
@ -105,6 +154,10 @@ class MaintenanceManagerService
|
|||||||
return $loadedCacheData;
|
return $loadedCacheData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $year
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public function getMaintenancesInYear($year): array
|
public function getMaintenancesInYear($year): array
|
||||||
{
|
{
|
||||||
$qb = $this->em->createQueryBuilder();
|
$qb = $this->em->createQueryBuilder();
|
||||||
@ -120,16 +173,19 @@ class MaintenanceManagerService
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $hash
|
* @param string $hash
|
||||||
|
* @param int $year
|
||||||
* @return Maintenance
|
* @return Maintenance
|
||||||
* @throws \Doctrine\ORM\ORMException
|
* @throws \Doctrine\ORM\ORMException
|
||||||
* @throws \Doctrine\ORM\OptimisticLockException
|
* @throws \Doctrine\ORM\OptimisticLockException
|
||||||
* @throws \Doctrine\ORM\TransactionRequiredException
|
* @throws \Doctrine\ORM\TransactionRequiredException
|
||||||
|
* @throws \PHPExcel_Exception
|
||||||
|
* @throws \PHPExcel_Reader_Exception
|
||||||
*/
|
*/
|
||||||
public function get(string $hash): Maintenance
|
public function get(string $hash, int $year): Maintenance
|
||||||
{
|
{
|
||||||
/** @var Maintenance $maintenance */
|
/** @var Maintenance $maintenance */
|
||||||
if (null == ($maintenance = $this->em->find(Maintenance::class, $hash))) {
|
if (null == ($maintenance = $this->em->find(Maintenance::class, $hash))) {
|
||||||
$maintenance = $this->initMaintenanceInDatabase($hash);
|
$maintenance = $this->initMaintenanceInDatabase($hash, $year);
|
||||||
}
|
}
|
||||||
return $maintenance;
|
return $maintenance;
|
||||||
}
|
}
|
||||||
@ -142,10 +198,12 @@ class MaintenanceManagerService
|
|||||||
* @throws \Doctrine\ORM\ORMException
|
* @throws \Doctrine\ORM\ORMException
|
||||||
* @throws \Doctrine\ORM\OptimisticLockException
|
* @throws \Doctrine\ORM\OptimisticLockException
|
||||||
* @throws \Doctrine\ORM\TransactionRequiredException
|
* @throws \Doctrine\ORM\TransactionRequiredException
|
||||||
|
* @throws \PHPExcel_Exception
|
||||||
|
* @throws \PHPExcel_Reader_Exception
|
||||||
*/
|
*/
|
||||||
public function update(string $hash, $data, int $uid): Maintenance
|
public function update(string $hash, $data, int $uid): Maintenance
|
||||||
{
|
{
|
||||||
$maintenance = $this->get($hash);
|
$maintenance = $this->get($hash, (int)$data['year']);
|
||||||
/** @var Maintenance $maintenance */
|
/** @var Maintenance $maintenance */
|
||||||
$maintenance = $this->hydrator->hydrate($data, $maintenance);
|
$maintenance = $this->hydrator->hydrate($data, $maintenance);
|
||||||
if (null == $maintenance->getStartedBy()) {
|
if (null == $maintenance->getStartedBy()) {
|
||||||
@ -163,43 +221,17 @@ class MaintenanceManagerService
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $id
|
* @param string $id
|
||||||
* @param string $state
|
* @param $year
|
||||||
* @param int $uid
|
|
||||||
* @return Maintenance
|
* @return Maintenance
|
||||||
* @throws \Doctrine\ORM\ORMException
|
* @throws \Doctrine\ORM\ORMException
|
||||||
* @throws \Doctrine\ORM\OptimisticLockException
|
* @throws \Doctrine\ORM\OptimisticLockException
|
||||||
* @throws \Doctrine\ORM\TransactionRequiredException
|
* @throws \PHPExcel_Exception
|
||||||
* @deprecated
|
* @throws \PHPExcel_Reader_Exception
|
||||||
*/
|
*/
|
||||||
public function setStatus(string $id, string $state, int $uid): Maintenance
|
private function initMaintenanceInDatabase(string $id, $year): 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;
|
$taskFound = null;
|
||||||
$loadedCacheData = $this->getUpdatedXlsxData();
|
$loadedCacheData = $this->getUpdatedXlsxData($year);
|
||||||
foreach ($loadedCacheData as $deviceGroup) {
|
foreach ($loadedCacheData as $deviceGroup) {
|
||||||
foreach ($deviceGroup->getDevices() as $device) {
|
foreach ($deviceGroup->getDevices() as $device) {
|
||||||
foreach ($device->getTasks() as $task) {
|
foreach ($device->getTasks() as $task) {
|
||||||
@ -218,7 +250,7 @@ class MaintenanceManagerService
|
|||||||
->setResponsible($taskFound->getDevice()->getResponsible())
|
->setResponsible($taskFound->getDevice()->getResponsible())
|
||||||
->setCount($taskFound->getDevice()->getCount())
|
->setCount($taskFound->getDevice()->getCount())
|
||||||
->setWorkDescription($taskFound->getDevice()->getWorkDescription())
|
->setWorkDescription($taskFound->getDevice()->getWorkDescription())
|
||||||
->setYear($this->year)
|
->setYear($year)
|
||||||
->setMonth($taskFound->getMonth())
|
->setMonth($taskFound->getMonth())
|
||||||
->setWeek($taskFound->getWeek())
|
->setWeek($taskFound->getWeek())
|
||||||
->setWorkerCount($taskFound->getWorkerCount())
|
->setWorkerCount($taskFound->getWorkerCount())
|
||||||
@ -231,20 +263,20 @@ class MaintenanceManagerService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param $workSheetYear
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function generateWorksheetId($year): string
|
private function generateWorksheetId($workSheetYear): string
|
||||||
{
|
{
|
||||||
$yearsFaultCount = $this->em->createQueryBuilder()
|
$yearsFaultCount = $this->em->createQueryBuilder()
|
||||||
->select('count(f.hash)')
|
->select('count(f.hash)')
|
||||||
->from(Maintenance::class, 'f')
|
->from(Maintenance::class, 'f')
|
||||||
->where('YEAR(f.shouldStartAt) = :thisYear')
|
->where('YEAR(f.shouldStartAt) = :thisYear')
|
||||||
// ->andWhere('f.shouldStartAt IS NOT null')
|
|
||||||
->andWhere('f.worksheetNumber IS NOT null')
|
->andWhere('f.worksheetNumber IS NOT null')
|
||||||
->setParameter('thisYear', $year)
|
->setParameter('thisYear', $workSheetYear)
|
||||||
->getQuery()
|
->getQuery()
|
||||||
->setHydrationMode(Query::HYDRATE_SINGLE_SCALAR)
|
->setHydrationMode(Query::HYDRATE_SINGLE_SCALAR)
|
||||||
->execute();
|
->execute();
|
||||||
return sprintf("%s/%s", $this->year, $yearsFaultCount+1);
|
return sprintf("%s/%s", $workSheetYear, $yearsFaultCount+1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,24 +15,15 @@ class XlsxParserService
|
|||||||
const XLSX_FILE_NAME = 'data/user-upload/webnaplo_%s.xlsx';
|
const XLSX_FILE_NAME = 'data/user-upload/webnaplo_%s.xlsx';
|
||||||
const XLSX_CACHE_FILE = 'data/cache/xlsx-full-cache_%s.dat';
|
const XLSX_CACHE_FILE = 'data/cache/xlsx-full-cache_%s.dat';
|
||||||
|
|
||||||
/**
|
/** @var DeviceGroup[]|ArrayCollection */
|
||||||
* @var DeviceGroup[]|ArrayCollection
|
|
||||||
*/
|
|
||||||
private $deviceGroups;
|
private $deviceGroups;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
private $year;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XlsxParserService constructor.
|
* XlsxParserService constructor.
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->deviceGroups = new ArrayCollection();
|
$this->deviceGroups = new ArrayCollection();
|
||||||
$this->year = date("Y");
|
|
||||||
// $this->year = 2018;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -60,46 +51,55 @@ class XlsxParserService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param int $year
|
||||||
* @return ArrayCollection|Maintenance[]
|
* @return ArrayCollection|Maintenance[]
|
||||||
|
* @throws \PHPExcel_Exception
|
||||||
|
* @throws \PHPExcel_Reader_Exception
|
||||||
*/
|
*/
|
||||||
public function getXlsxData(): ArrayCollection
|
public function getXlsxData(int $year): ArrayCollection
|
||||||
{
|
{
|
||||||
if (!file_exists($this->getXlsxFileName())) {
|
if (!file_exists($this->getXlsxFileName($year))) {
|
||||||
return new ArrayCollection();
|
return new ArrayCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file_exists($this->getTimestampFileName()) ||
|
if (!file_exists($this->getTimestampFileName($year)) ||
|
||||||
!file_exists($this->getCacheFileName()) ||
|
!file_exists($this->getCacheFileName($year)) ||
|
||||||
file_get_contents($this->getTimestampFileName()) < filemtime($this->getXlsxFileName())
|
file_get_contents($this->getTimestampFileName($year)) < filemtime($this->getXlsxFileName($year))
|
||||||
) {
|
) {
|
||||||
$this->rebuildCache();
|
$this->rebuildCache($year);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var ArrayCollection|DeviceGroup[] $loadedCacheData */
|
/** @var ArrayCollection|DeviceGroup[] $loadedCacheData */
|
||||||
$loadedCacheData = unserialize(file_get_contents($this->getCacheFileName()));
|
$loadedCacheData = unserialize(file_get_contents($this->getCacheFileName($year)));
|
||||||
return $loadedCacheData;
|
return $loadedCacheData;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function rebuildCache()
|
/**
|
||||||
|
* @param int $year
|
||||||
|
* @throws \PHPExcel_Exception
|
||||||
|
* @throws \PHPExcel_Reader_Exception
|
||||||
|
*/
|
||||||
|
private function rebuildCache(int $year)
|
||||||
{
|
{
|
||||||
$mtime = filemtime($this->getXlsxFileName());
|
$mtime = filemtime($this->getXlsxFileName($year));
|
||||||
$parsedXlsxData = $this->parseXlsx();
|
$parsedXlsxData = $this->parseXlsx($year);
|
||||||
file_put_contents($this->getCacheFileName(), serialize($parsedXlsxData));
|
file_put_contents($this->getCacheFileName($year), serialize($parsedXlsxData));
|
||||||
file_put_contents($this->getTimestampFileName(), $mtime);
|
file_put_contents($this->getTimestampFileName($year), $mtime);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param int $year
|
||||||
* @return ArrayCollection
|
* @return ArrayCollection
|
||||||
* @throws \PHPExcel_Exception
|
* @throws \PHPExcel_Exception
|
||||||
* @throws \PHPExcel_Reader_Exception
|
* @throws \PHPExcel_Reader_Exception
|
||||||
*/
|
*/
|
||||||
public function parseXlsx(): ArrayCollection
|
public function parseXlsx(int $year): ArrayCollection
|
||||||
{
|
{
|
||||||
$objPHPExcel = \PHPExcel_IOFactory::load($this->getXlsxFileName());
|
$objPHPExcel = \PHPExcel_IOFactory::load($this->getXlsxFileName($year));
|
||||||
$sheet = $objPHPExcel->getSheetByName(self::XLSX_SHEET_NAME);
|
$sheet = $objPHPExcel->getSheetByName(self::XLSX_SHEET_NAME);
|
||||||
|
|
||||||
$totalRows = $sheet->getHighestRow();
|
$totalRows = $sheet->getHighestRow();
|
||||||
$monthColumns = $this->year == 2018
|
$monthColumns = $year == 2018
|
||||||
? range(43, 58)
|
? range(43, 58)
|
||||||
: range(11, 58);
|
: range(11, 58);
|
||||||
$rowCursor = 7;
|
$rowCursor = 7;
|
||||||
@ -146,11 +146,11 @@ class XlsxParserService
|
|||||||
$weekDataCell = $sheet->getCellByColumnAndRow($column, $rowCursor);
|
$weekDataCell = $sheet->getCellByColumnAndRow($column, $rowCursor);
|
||||||
if ($weekDataCell->getValue() != "") {
|
if ($weekDataCell->getValue() != "") {
|
||||||
$month = floor(($column - 11) / 4 + 1);
|
$month = floor(($column - 11) / 4 + 1);
|
||||||
$firstDayOfFirstWeek = $this->getFirstWeekOfMonth($month);
|
$firstDayOfFirstWeek = $this->getFirstWeekOfMonth($year, $month);
|
||||||
$week = ($column - 11) % 4 + 1;
|
$week = ($column - 11) % 4 + 1;
|
||||||
|
|
||||||
$task = new DeviceMaintenanceTask($device);
|
$task = new DeviceMaintenanceTask($device);
|
||||||
$task->setYear($this->year)
|
$task->setYear($year)
|
||||||
->setMonth($month)
|
->setMonth($month)
|
||||||
->setWeek($week)
|
->setWeek($week)
|
||||||
->setShouldStartAt($firstDayOfFirstWeek->add(
|
->setShouldStartAt($firstDayOfFirstWeek->add(
|
||||||
@ -183,12 +183,13 @@ class XlsxParserService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param int $year
|
||||||
* @param int $month
|
* @param int $month
|
||||||
* @return \DateTime
|
* @return \DateTime
|
||||||
*/
|
*/
|
||||||
private function getFirstWeekOfMonth(int $month): \DateTime
|
private function getFirstWeekOfMonth(int $year, int $month): \DateTime
|
||||||
{
|
{
|
||||||
$firstDayOfMonth = mktime(0, 0, 0, $month, 1, $this->year);
|
$firstDayOfMonth = mktime(0, 0, 0, $month, 1, $year);
|
||||||
$weekDayOfFirst = date("N", $firstDayOfMonth);
|
$weekDayOfFirst = date("N", $firstDayOfMonth);
|
||||||
|
|
||||||
if ($weekDayOfFirst == 2) {
|
if ($weekDayOfFirst == 2) {
|
||||||
@ -203,24 +204,24 @@ class XlsxParserService
|
|||||||
|
|
||||||
return new \DateTime(sprintf(
|
return new \DateTime(sprintf(
|
||||||
"%s-%s-%s",
|
"%s-%s-%s",
|
||||||
$this->year,
|
$year,
|
||||||
$month,
|
$month,
|
||||||
$firstWeekMonday
|
$firstWeekMonday
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getCacheFileName(): string
|
private function getCacheFileName(int $year): string
|
||||||
{
|
{
|
||||||
return sprintf(self::XLSX_CACHE_FILE, $this->year);
|
return sprintf(self::XLSX_CACHE_FILE, $year);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getTimestampFileName(): string
|
private function getTimestampFileName(int $year): string
|
||||||
{
|
{
|
||||||
return sprintf(self::XLSX_TIMESTAMP, $this->year);
|
return sprintf(self::XLSX_TIMESTAMP, $year);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getXlsxFileName(): string
|
private function getXlsxFileName(int $year): string
|
||||||
{
|
{
|
||||||
return sprintf(self::XLSX_FILE_NAME, $this->year);
|
return sprintf(self::XLSX_FILE_NAME, $year);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user