Commit 50bcebb2 authored by Σταύρος Παπαδάκης's avatar Σταύρος Παπαδάκης Committed by GitHub

New applications form

parents 2af31e8f 3951a5c0
......@@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "ce63645072785d61c343bdef07061ae2",
"content-hash": "86cc938c4ba809f58f72c6f3c4a9d635",
"hash": "b3178a5d5f722fad84f4c0311d54457a",
"content-hash": "f000cf68a96e1a870a120eb816628d24",
"packages": [
{
"name": "container-interop/container-interop",
......@@ -1079,16 +1079,16 @@
},
{
"name": "slim/slim",
"version": "3.4.2",
"version": "3.5.0",
"source": {
"type": "git",
"url": "https://github.com/slimphp/Slim.git",
"reference": "a132385f736063d00632b52b3f8a389fe66fe4fa"
"reference": "184352bc1913d7ba552ab4131d62f4730ddb0893"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/slimphp/Slim/zipball/a132385f736063d00632b52b3f8a389fe66fe4fa",
"reference": "a132385f736063d00632b52b3f8a389fe66fe4fa",
"url": "https://api.github.com/repos/slimphp/Slim/zipball/184352bc1913d7ba552ab4131d62f4730ddb0893",
"reference": "184352bc1913d7ba552ab4131d62f4730ddb0893",
"shasum": ""
},
"require": {
......@@ -1145,7 +1145,7 @@
"micro",
"router"
],
"time": "2016-05-25 11:23:38"
"time": "2016-07-26 15:12:13"
},
{
"name": "slim/twig-view",
......
<?php
/**
* gredu_labs
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
return [
'application_form' => [
'itemcategory' => [
'currentversion' => 1,
'map' => [
],
],
],
];
<?php
/**
* gredu_labs
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
return [
'application_form' => [
'itemcategory' => [
'map' => [
'fromversion' => 0,
'toversion' => 1,
'items' => [
],
],
],
],
];
......@@ -11,6 +11,7 @@
'dsn' => '',
'user' => null,
'pass' => null,
'freeze' => true,
'options' => [
],
......
......@@ -48,6 +48,7 @@ CREATE TABLE `applicationformitem` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`itemcategory_id` int(11) unsigned NOT NULL,
`qty` int(11) unsigned NOT NULL,
`qtyacquired` int(11) unsigned NOT NULL DEFAULT 0,
`reasons` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`applicationform_id` int(11) unsigned NOT NULL,
`lab_id` int(11) unsigned NOT NULL,
......@@ -158,9 +159,11 @@ DROP TABLE IF EXISTS `itemcategory`;
CREATE TABLE `itemcategory` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`groupflag` int(11) unsigned DEFAULT 0,
`sort` int(11) unsigned DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY `name_UNIQUE` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=42 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=InnoDB AUTO_INCREMENT=200 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
......@@ -169,7 +172,54 @@ CREATE TABLE `itemcategory` (
LOCK TABLES `itemcategory` WRITE;
/*!40000 ALTER TABLE `itemcategory` DISABLE KEYS */;
INSERT INTO `itemcategory` VALUES (8,'ACCESS POINT'),(26,'ΦΟΡΗΤΟΣ Η/Υ (LAPTOP)'),(6,'MODEM / ROUTER '),(5,'PATCH PANEL'),(14,'ΕΚΤΥΠΩΤΗΣ (PRINTER)'),(3,'ΚΡΙΩΜΑ (RACK)'),(13,'ΣΑΡΩΤΗΣ (SCANNER)'),(24,'SERVER'),(2,'SWITCH/ HUB'),(23,'TABLET'),(11,'WEBCAM'),(22,'ΣΤΑΘΜΟΣ ΕΡΓΑΣΙΑΣ'),(41,'ΒΙΝΤΕΟΠΡΟΒΟΛΕΑΣ'),(40,'ΔΙΑΔΡΑΣΤΙΚΟ ΣΥΣΤΗΜΑ'),(38,'ΕΠΕΞΕΡΓΑΣΤΗΣ (CPU)'),(34,'ΚΙΝΗΤΟ ΕΡΓΑΣΤΗΡΙΟ'),(32,'ΜΝΗΜΗ RAM'),(30,'ΟΘΟΝΗ'),(29,'ΣΚΛΗΡΟΣ ΔΙΣΚΟΣ'),(42,'ΤΡΙΣΔΙΑΣΤΑΤΟΣ ΕΚΤΥΠΩΤΗΣ'),(43,'ΤΡΙΣΔΙΑΣΤΑΤΟΣ ΣΑΡΩΤΗΣ'),(44,'ΣΕΤ ΡΟΜΠΟΤΙΚΗΣ - ΑΙΣΘΗΤΗΡΩΝ'),(45,'ΔΟΜΗΜΕΝΗ ΚΑΛΩΔΙΩΣΗ');
INSERT INTO `itemcategory` (`id`,`name`,`groupflag`,`sort`) VALUES
(8,'ACCESS POINT',0,8),
(26,'ΦΟΡΗΤΟΣ Η/Υ (LAPTOP)',0,26),
(6,'MODEM / ROUTER ',0,6),
(5,'PATCH PANEL',0,5),
(14,'ΕΚΤΥΠΩΤΗΣ (PRINTER)',0,14),
(3,'ΚΡΙΩΜΑ (RACK)',0,3),
(13,'ΣΑΡΩΤΗΣ (SCANNER)',0,13),
(24,'SERVER',0,24),
(2,'SWITCH/ HUB',0,2),
(23,'TABLET',0,23),
(11,'WEBCAM',0,11),
(22,'ΣΤΑΘΜΟΣ ΕΡΓΑΣΙΑΣ',0,22),
(41,'ΒΙΝΤΕΟΠΡΟΒΟΛΕΑΣ',0,41),
(40,'ΔΙΑΔΡΑΣΤΙΚΟ ΣΥΣΤΗΜΑ',0,40),
(38,'ΕΠΕΞΕΡΓΑΣΤΗΣ (CPU)',0,38),
(34,'ΚΙΝΗΤΟ ΕΡΓΑΣΤΗΡΙΟ',0,34),
(32,'ΜΝΗΜΗ RAM',0,32),
(30,'ΟΘΟΝΗ',0,30),
(29,'ΣΚΛΗΡΟΣ ΔΙΣΚΟΣ',0,29),
(42,'ΤΡΙΣΔΙΑΣΤΑΤΟΣ ΕΚΤΥΠΩΤΗΣ',0,42),
(43,'ΤΡΙΣΔΙΑΣΤΑΤΟΣ ΣΑΡΩΤΗΣ',0,43),
(44,'ΣΕΤ ΡΟΜΠΟΤΙΚΗΣ - ΑΙΣΘΗΤΗΡΩΝ',0,44),
(45,'ΔΟΜΗΜΕΝΗ ΚΑΛΩΔΙΩΣΗ',0,45);
INSERT INTO `itemcategory` (`id`,`name`,`groupflag`,`sort`) VALUES
(101,'ΣΤΑΘΕΡΟΣ ΗΛΕΚΤΡΟΝΙΚΟΣ ΥΠΟΛΟΓΙΣΤΗΣ (DESKTOP)', 1,1),
(102,'ΦΟΡΗΤΟΣ ΗΛΕΚΤΡΟΝΙΚΟΣ ΥΠΟΛΟΓΙΣΤΗΣ (LAPTOP)', 1,2),
(103,'ΕΠΙΤΡΑΠΕΖΙΟΣ ΒΙΝΤΕΟΠΡΟΒΟΛΕΑΣ (SHORT THROW PROJECTOR)', 1,3),
(104,'ΕΠΙΤΟΙΧΟΣ ΒΙΝΤΕΟΠΡΟΒΟΛΕΑΣ (ULTRA SHORT THROW WIFI PROJECTOR)', 1,4),
(105,'ΕΓΧΡΩΜΟΣ ΕΚΤΥΠΩΤΗΣ Α4', 1,5),
(106,'ΑΣΠΡΟΜΑΥΡΟΣ ΕΚΤΥΠΩΤΗΣ LASER Α4', 1,6),
(107,'ΔΙΑΔΙΚΤΥΑΚΗ ΚΑΜΕΡΑ (WEB CAMERA)', 1,7),
(108,'ΕΞΩΤΕΡΙΚΟΣ ΣΚΛΗΡΟΣ ΔΙΣΚΟΣ', 1,8),
(109,'ΑΣΠΡΟΜΑΥΡΟ ΠΟΛΥΜΗΧΑΝΗΜΑ Α4', 1,9),
(110,'ΑΣΠΡΟΜΑΥΡΟ ΠΟΛΥΜΗΧΑΝΗΜΑ Α3', 1,10),
(111,'ΑΣΥΡΜΑΤΟ ΣΗΜΕΙΟ ΠΡΟΣΒΑΣΗΣ (ACCESS POINT)', 1,11),
(112,'ΕΞΥΠΗΡΕΤΗΤΗΣ (HIGH-END WORKSTATION FOR SERVER FUNCTION)', 1,12),
(113,'ΥΠΟΛΟΓΙΣΤΙΚΗ ΜΟΝΑΔΑ ΧΑΜΗΛΟΥ ΟΓΚΟΥ/ΚΑΤΑΝΑΛΩΣΗΣ (SINGLE BOARD COMPUTER)', 1,13),
(114,'ΣΤΑΘΕΡΟΣ ΗΛΕΚΤΡΟΝΙΚΟΣ ΥΠΟΛΟΓΙΣΤΗΣ CLIENT (FAT CLIENT)', 1,14),
(115,'ΑΚΟΥΣΤΙΚΑ (HEADSET)', 1,15),
(116,'ΜΕΤΑΓΩΓΕΑΣ (SWITCH)', 1,16),
(117,'ΤΡΙΣΔΙΑΣΤΑΤΟΣ ΕΚΤΥΠΩΤΗΣ (3D PRINTER)', 1,17),
(118,'ΤΡΙΣΔΙΑΣΤΑΤΟΣ ΣΑΡΩΤΗΣ (3D SCANNER)', 1,18),
(119,'ΣΕΤ ΡΟΜΠΟΤΙΚΗΣ ΝΗΠΙΑΓΩΓΕΙΟΥ', 1,19),
(120,'ΣΕΤ ΡΟΜΠΟΤΙΚΗΣ ΔΗΜΟΤΙΚΟΥ', 1,20),
(121,'ΣΕΤ ΡΟΜΠΟΤΙΚΗΣ ΓΥΜΝΑΣΙΟΥ', 1,21),
(122,'ΣΕΤ ΡΟΜΠΟΤΙΚΗΣ ΛΥΚΕΙΟΥ', 1,22),
(123,'ΔΙΑΔΡΑΣΤΙΚΟ ΣΥΣΤΗΜΑ (INTERACTIVE SET)', 1,23);
/*!40000 ALTER TABLE `itemcategory` ENABLE KEYS */;
UNLOCK TABLES;
......
......@@ -44,6 +44,8 @@ return function (Slim\App $app) {
};
$container[GrEduLabs\ApplicationForm\Action\ApplicationForm::class] = function ($c) {
$settings = $c->get('settings');
$currentVersion = $settings['application_form']['itemcategory']['currentversion'];
return new GrEduLabs\ApplicationForm\Action\ApplicationForm(
$c->get('view'),
$c->get(GrEduLabs\Schools\Service\AssetServiceInterface::class),
......@@ -51,7 +53,9 @@ return function (Slim\App $app) {
$c->get(GrEduLabs\ApplicationForm\Service\ApplicationFormServiceInterface::class),
$c->get(GrEduLabs\ApplicationForm\InputFilter\ApplicationForm::class),
$c->get('authentication_service'),
$c->get('router')->pathFor('application_form.submit_success')
$c->get('router')->pathFor('application_form.submit_success'),
$currentVersion,
$c
);
};
......@@ -79,7 +83,8 @@ return function (Slim\App $app) {
$container[GrEduLabs\ApplicationForm\Middleware\SchoolApplicationForm::class] = function ($c) {
return new GrEduLabs\ApplicationForm\Middleware\SchoolApplicationForm(
$c->get('view'),
$c->get(GrEduLabs\ApplicationForm\Service\ApplicationFormServiceInterface::class)
$c->get(GrEduLabs\ApplicationForm\Service\ApplicationFormServiceInterface::class),
$c
);
};
});
......
ALTER TABLE `applicationformitem`
DROP COLUMN `qtyacquired` ;
ALTER TABLE `itemcategory`
DROP COLUMN `groupflag` ;
ALTER TABLE `itemcategory`
DROP COLUMN `sort` ;
ALTER TABLE `applicationformitem`
ADD COLUMN `qtyacquired` int(11) unsigned NOT NULL DEFAULT 0
AFTER `qty` ;
ALTER TABLE `itemcategory`
ADD COLUMN `groupflag` int(11) unsigned NOT NULL DEFAULT 0 ;
ALTER TABLE `itemcategory`
ADD COLUMN `sort` int(11) unsigned NOT NULL DEFAULT 0 ;
LOCK TABLES `itemcategory` WRITE;
/*!40000 ALTER TABLE `itemcategory` DISABLE KEYS */;
INSERT INTO `itemcategory` (`id`,`name`,`groupflag`,`sort`) VALUES
(101,'ΣΤΑΘΕΡΟΣ ΗΛΕΚΤΡΟΝΙΚΟΣ ΥΠΟΛΟΓΙΣΤΗΣ (DESKTOP)', 1,1),
(102,'ΦΟΡΗΤΟΣ ΗΛΕΚΤΡΟΝΙΚΟΣ ΥΠΟΛΟΓΙΣΤΗΣ (LAPTOP)', 1,2),
(103,'ΕΠΙΤΡΑΠΕΖΙΟΣ ΒΙΝΤΕΟΠΡΟΒΟΛΕΑΣ (SHORT THROW PROJECTOR)', 1,3),
(104,'ΕΠΙΤΟΙΧΟΣ ΒΙΝΤΕΟΠΡΟΒΟΛΕΑΣ (ULTRA SHORT THROW WIFI PROJECTOR)', 1,4),
(105,'ΕΓΧΡΩΜΟΣ ΕΚΤΥΠΩΤΗΣ Α4', 1,5),
(106,'ΑΣΠΡΟΜΑΥΡΟΣ ΕΚΤΥΠΩΤΗΣ LASER Α4', 1,6),
(107,'ΔΙΑΔΙΚΤΥΑΚΗ ΚΑΜΕΡΑ (WEB CAMERA)', 1,7),
(108,'ΕΞΩΤΕΡΙΚΟΣ ΣΚΛΗΡΟΣ ΔΙΣΚΟΣ', 1,8),
(109,'ΑΣΠΡΟΜΑΥΡΟ ΠΟΛΥΜΗΧΑΝΗΜΑ Α4', 1,9),
(110,'ΑΣΠΡΟΜΑΥΡΟ ΠΟΛΥΜΗΧΑΝΗΜΑ Α3', 1,10),
(111,'ΑΣΥΡΜΑΤΟ ΣΗΜΕΙΟ ΠΡΟΣΒΑΣΗΣ (ACCESS POINT)', 1,11),
(112,'ΕΞΥΠΗΡΕΤΗΤΗΣ (HIGH-END WORKSTATION FOR SERVER FUNCTION)', 1,12),
(113,'ΥΠΟΛΟΓΙΣΤΙΚΗ ΜΟΝΑΔΑ ΧΑΜΗΛΟΥ ΟΓΚΟΥ/ΚΑΤΑΝΑΛΩΣΗΣ (SINGLE BOARD COMPUTER)', 1,13),
(114,'ΣΤΑΘΕΡΟΣ ΗΛΕΚΤΡΟΝΙΚΟΣ ΥΠΟΛΟΓΙΣΤΗΣ CLIENT (FAT CLIENT)', 1,14),
(115,'ΑΚΟΥΣΤΙΚΑ (HEADSET)', 1,15),
(116,'ΜΕΤΑΓΩΓΕΑΣ (SWITCH)', 1,16),
(117,'ΤΡΙΣΔΙΑΣΤΑΤΟΣ ΕΚΤΥΠΩΤΗΣ (3D PRINTER)', 1,17),
(118,'ΤΡΙΣΔΙΑΣΤΑΤΟΣ ΣΑΡΩΤΗΣ (3D SCANNER)', 1,18),
(119,'ΣΕΤ ΡΟΜΠΟΤΙΚΗΣ ΝΗΠΙΑΓΩΓΕΙΟΥ', 1,19),
(120,'ΣΕΤ ΡΟΜΠΟΤΙΚΗΣ ΔΗΜΟΤΙΚΟΥ', 1,20),
(121,'ΣΕΤ ΡΟΜΠΟΤΙΚΗΣ ΓΥΜΝΑΣΙΟΥ', 1,21),
(122,'ΣΕΤ ΡΟΜΠΟΤΙΚΗΣ ΛΥΚΕΙΟΥ', 1,22),
(123,'ΔΙΑΔΡΑΣΤΙΚΟ ΣΥΣΤΗΜΑ (INTERACTIVE SET)', 1,23);
/*!40000 ALTER TABLE `itemcategory` ENABLE KEYS */;
UNLOCK TABLES;
ALTER TABLE `itemcategory` AUTO_INCREMENT = 200;
......@@ -48,6 +48,7 @@ CREATE TABLE `applicationformitem` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`itemcategory_id` int(11) unsigned NOT NULL,
`qty` int(11) unsigned NOT NULL,
`qtyacquired` int(11) unsigned DEFAULT 0,
`reasons` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`applicationform_id` int(11) unsigned NOT NULL,
`lab_id` int(11) unsigned NOT NULL,
......
<?php
/**
* gredu_labs.
*
......@@ -19,8 +20,8 @@ use Slim\Views\Twig;
use Zend\Authentication\AuthenticationServiceInterface;
use Zend\InputFilter\InputFilterInterface;
class ApplicationForm
{
class ApplicationForm {
/**
* @var Twig
*/
......@@ -56,6 +57,18 @@ class ApplicationForm
*/
protected $authService;
/**
*
* @var int The version of the application form to handle
*/
protected $version;
/**
*
* @var type SLIM application container
*/
protected $container;
/**
*
* @var string
......@@ -63,69 +76,124 @@ class ApplicationForm
protected $successUrl;
public function __construct(
Twig $view,
AssetServiceInterface $assetsService,
LabServiceInterface $labService,
ApplicationFormServiceInterface $appFormService,
InputFilterInterface $appFormInputFilter,
AuthenticationServiceInterface $authService,
$successUrl
Twig $view, AssetServiceInterface $assetsService, LabServiceInterface $labService, ApplicationFormServiceInterface $appFormService, InputFilterInterface $appFormInputFilter, AuthenticationServiceInterface $authService, $successUrl, $version, $container
) {
$this->view = $view;
$this->assetsService = $assetsService;
$this->labService = $labService;
$this->appFormService = $appFormService;
$this->view = $view;
$this->assetsService = $assetsService;
$this->labService = $labService;
$this->appFormService = $appFormService;
$this->appFormInputFilter = $appFormInputFilter;
$this->authService = $authService;
$this->successUrl = $successUrl;
$this->authService = $authService;
$this->successUrl = $successUrl;
$this->version = $version;
$this->container = $container;
}
public function __invoke(Request $req, Response $res)
{
public function __invoke(Request $req, Response $res) {
$school = $req->getAttribute('school');
if ($req->isPost()) {
$this->appFormInputFilter->setData(array_merge($req->getParams(), [
'school_id' => $school->id,
'submitted_by'=> $this->authService->getIdentity()->mail,
$reqParams = $req->getParams();
array_splice($reqParams['items'], 0, 0);
$this->appFormInputFilter->setData(array_merge($reqParams, [
'school_id' => $school->id,
'submitted_by' => $this->authService->getIdentity()->mail,
]));
$isValid = $this->appFormInputFilter->isValid();
if ($isValid) {
$data = $this->appFormInputFilter->getValues();
$appForm = $this->appFormService->submit($data);
$data = $this->appFormInputFilter->getValues();
$appForm = $this->appFormService->submit($data);
$_SESSION['applicationForm']['appForm'] = $appForm;
$res = $res->withRedirect($this->successUrl);
$res = $res->withRedirect($this->successUrl);
return $res;
}
$this->view['form'] = [
'is_valid' => $isValid,
'values' => $this->appFormInputFilter->getValues(),
'is_valid' => $isValid,
'values' => $this->appFormInputFilter->getValues(),
'raw_values' => $this->appFormInputFilter->getRawValues(),
'messages' => $this->appFormInputFilter->getMessages(),
'messages' => $this->appFormInputFilter->getMessages(),
];
}
$loadForm = (bool) $req->getParam('load', false);
$loadForm = (bool) $req->getParam('load', false);
$this->view['choose'] = !$loadForm && !$req->isPost();
if (!$req->isPost() && $loadForm) {
// take care of new options in applications and migrate existing ones
if (null !== ($appForm = $this->appFormService->findSchoolApplicationForm($school->id))) {
/**
* Do mapping of old items to new only if items do exist (old form)
* and the map is available at the app settings.
* TODO: Only one version migrations are supported. If the old items are
* two or more versions older, they will not be handled.
*/
// get the existing (db) application form version
$items_version = $this->version;
if (isset($appForm['items']) && \count($appForm['items']) > 0) {
$items_version = array_values($appForm['items'])[0]['version'];
}
if ($this->version != $items_version &&
isset($appForm['items']) &&
isset($this->container['settings']['application_form']['itemcategory']['map']) &&
$this->container['settings']['application_form']['itemcategory']['map']['fromversion'] == $items_version &&
$this->container['settings']['application_form']['itemcategory']['map']['toversion'] == $this->version &&
isset($this->container['settings']['application_form']['itemcategory']['map']['items'])) {
// if map exists for this version, use it
$items_map = $this->container['settings']['application_form']['itemcategory']['map']['items'];
$appForm['items'] = array_map(function ($item) use ($items_map) {
$migrate_values = [];
if (isset($items_map[$item['itemcategory_id']]) &&
intval($items_map[$item['itemcategory_id']]) > 0) {
$migrate_values = [
'itemcategory_prev' => $item['itemcategory_id'],
'itemcategory_id_prev' => $item['itemcategory_id'],
'itemcategory_id' => intval($items_map[$item['itemcategory_id']]),
];
} else {
$migrate_values = [
'itemcategory_prev' => '',
'itemcategory_id_prev' => -1,
];
}
$migrate_values['prev_form_load'] = true;
return array_merge($item, $migrate_values);
}, $appForm['items']);
} elseif ($this->version != $items_version &&
isset($appForm['items']) &&
isset($this->container['settings']['application_form']['itemcategory']['map']) &&
($this->container['settings']['application_form']['itemcategory']['map']['fromversion'] != $items_version ||
$this->container['settings']['application_form']['itemcategory']['map']['toversion'] != $this->version)) {
// if map does not exist for this version, notify user
$items_map = $this->container['settings']['application_form']['itemcategory']['map']['items'];
$appForm['items'] = array_map(function ($item) use ($items_map) {
$migrate_values = [
'itemcategory_prev' => '',
'itemcategory_id_prev' => -2,
'prev_form_load' => true
];
return array_merge($item, $migrate_values);
}, $appForm['items']);
}
$this->view['form'] = [
'values' => $appForm,
];
}
}
$labs = $this->labService->getLabsBySchoolId($school->id);
$res = $this->view->render($res, 'application_form/form.twig', [
$res = $this->view->render($res, 'application_form/form.twig', [
'lab_choices' => array_map(function ($lab) {
return ['value' => $lab['id'], 'label' => $lab['name']];
}, $labs),
'type_choices' => array_map(function ($category) {
return ['value' => $category['id'], 'label' => $category['name']];
}, $this->assetsService->getAllItemCategories()),
]);
return $res;
}
}
return ['value' => $lab['id'], 'label' => $lab['name']];
}, $labs),
'type_choices' => array_map(function ($category) {
return ['value' => $category['id'], 'label' => $category['name']];
}, $this->assetsService->getAllItemCategories($this->version)),
]);
return $res;
}
}
\ No newline at end of file
......@@ -58,6 +58,18 @@ class ApplicationFormItem extends InputFilter
'min' => 0,
]));
$qtyacquired = new Input('qtyacquired');
$qtyacquired->setRequired(true)
->getFilterChain()
->attach(new Filter\ToInt());
$qtyacquired->getValidatorChain()
->attach(new Validator\NotEmpty())
->attach(new Validator\GreaterThan([
'min' => 0,
'inclusive' => true
]
));
$reasons = new Input('reasons');
$reasons->setRequired(true)
->getFilterChain()
......@@ -69,6 +81,7 @@ class ApplicationFormItem extends InputFilter
$this->add($labId)
->add($itemCategoryId)
->add($qty)
->add($qtyacquired)
->add($reasons);
}
}
......@@ -24,6 +24,7 @@ class SchoolApplicationForm
* @var Twig
*/
protected $view;
protected $container;
/**
*
......@@ -31,10 +32,11 @@ class SchoolApplicationForm
*/
protected $appFormService;
public function __construct(Twig $view, ApplicationFormServiceInterface $appFormService)
public function __construct(Twig $view, ApplicationFormServiceInterface $appFormService, $container)
{
$this->view = $view;
$this->appFormService = $appFormService;
$this->container = $container;
}
public function __invoke(Request $req, Response $res, callable $next)
......@@ -43,15 +45,51 @@ class SchoolApplicationForm
$appForm = $this->appFormService->findSchoolApplicationForm($school->id);
if ($appForm) {
$appForm['items'] = array_reduce($appForm['items'], function ($aggr, $item) {
$settings = $this->container->get('settings');
$currentVersion = $settings['application_form']['itemcategory']['currentversion'];
// get the existing (db) application form version
$items_version = $currentVersion;
if (isset($appForm['items']) && \count($appForm['items']) > 0) {
$items_version = array_values($appForm['items'])[0]['version'];
}
$appForm['items'] = array_reduce($appForm['items'], function ($aggr, $item) use ($currentVersion, $items_version) {
$category = $item['itemcategory_id'];
if (!isset($aggr[$category])) {
$aggr[$category] = [
'category' => $item['itemcategory'],
'count' => 0,
'category' => $item['itemcategory'],
'count' => 0,
'countAcquired' => 0,
'available' => 'LATEST'
];
/**
* Do mapping of old items to new only if items do exist (old form)
* and the map is available at the app settings.
* TODO: Only one version migrations are supported. If the old items are
* two or more versions older, they will not be handled.
*/
if ($currentVersion != $items_version &&
isset($this->container['settings']['application_form']['itemcategory']['map']) &&
$this->container['settings']['application_form']['itemcategory']['map']['fromversion'] == $items_version &&
$this->container['settings']['application_form']['itemcategory']['map']['toversion'] == $currentVersion &&
isset($this->container['settings']['application_form']['itemcategory']['map']['items'])) {
if (isset($this->container['settings']['application_form']['itemcategory']['map']['items'][$item['itemcategory_id']]) &&
intval($this->container['settings']['application_form']['itemcategory']['map']['items'][$item['itemcategory_id']]) > 0) {
$aggr[$category]['available'] = "MIGRATE";
} else {
$aggr[$category]['available'] = "UNAVAILABLE";
}
} elseif ($currentVersion != $items_version &&
isset($this->container['settings']['application_form']['itemcategory']['map']) &&
($this->container['settings']['application_form']['itemcategory']['map']['fromversion'] != $items_version ||
$this->container['settings']['application_form']['itemcategory']['map']['toversion'] != $currentVersion)) {
$aggr[$category]['available'] = "UNAVAILABLE";
}
}
$aggr[$category]['count'] += $item['qty'];
$aggr[$category]['countAcquired'] += $item['qtyacquired'];
return $aggr;
}, []);
......
......@@ -28,6 +28,7 @@ class ApplicationFormService implements ApplicationFormServiceInterface
$item->lab_id = $itemData['lab_id'];
$item->itemcategory_id = $itemData['itemcategory_id'];
$item->qty = $itemData['qty'];
$item->qtyacquired = $itemData['qtyacquired'];
$item->reasons = $itemData['reasons'];
$items[] = $item;
}
......@@ -57,6 +58,7 @@ class ApplicationFormService implements ApplicationFormServiceInterface
return array_merge($itemBean->export(), [
'lab' => $itemBean->lab->name,
'itemcategory' => $itemBean->itemcategory->name,
'version' => $itemBean->itemcategory->groupflag,
]);
}, $bean->ownApplicationformitemList);
......
......@@ -13,10 +13,10 @@
</div>
{% endmacro %}
{% macro itemCount(name, label, value, index) %}
{% macro itemCount(name, label, value, index, minvalue) %}
<div class="form-group">
<div class="col-xs-12 col-sm-12 col-md-9">
<input placeholder="{{ label|striptags }}" class="form-control input-sm" min="1"
<input placeholder="{{ label|striptags }}" class="form-control input-sm" min="{{ minvalue|default(1)}}"
type="number" name="items[{{ index | default('<%= index %>') | raw }}][{{ name }}]" value="{{ value|default('')|raw }}">
</div>
</div>
......@@ -64,6 +64,13 @@
</div>
{% endmacro %}
{% macro infoBox(boxtype, msg) %}
<div class="alert alert-{{ boxtype }} alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Κλείσιμο"><span aria-hidden="true">&times;</span></button>
<p class="text-{{ boxtype }}">{{ msg | raw }}</p>
</div>
{% endmacro %}
{% block content %}
{% import _self as macros %}
......@@ -108,13 +115,14 @@
<fieldset>
<legend>Νέος εξοπλισμός</legend>
<div id="items-list">
<table class="table table-hover table-striped">
<table class="table table-hover table-striped table-condensed">
<thead>
<tr>
<th>Πλήθος</th>
<th>Τύπος</th>
<th>Χώρος</th>
<th>Αιτιολογία χρήσης</th>
<th>Πλήθος αιτούμενων</th>
<th>Πλήθος υπαρχόντων που λειτουργούν</th>
<th class="col-xs-3">Τύπος</th>
<th class="col-xs-3">Χώρος</th>
<th class="col-xs-3">Αιτιολογία χρήσης</th>
<th></th>
</tr>
</thead>
......@@ -122,9 +130,22 @@
{% for itemIndex,item in form.values.items %}
<tr>
<td>{{ macros.itemCount('qty', 'Πλήθος', item.qty, loop.index0) }}</td>
<td>{{ macros.itemSelect('itemcategory_id', 'Τύπος', type_choices, item.itemcategory_id, loop.index0) }}</td>
<td>{{ macros.itemSelect('lab_id', 'Χώρος', lab_choices, item.lab_id, loop.index0 ) }}</td>
<td>{{ macros.itemReasons('reasons', 'Αιτιολογία χρήσης', item.reasons, loop.index0) }}</td>
<td>{{ macros.itemCount('qtyacquired', 'Πλήθος', item.qtyacquired, loop.index0, 0) }}</td>
<td class="col-xs-3">
{{ macros.itemSelect('itemcategory_id', 'Τύπος', type_choices, item.itemcategory_id, loop.index0) }}
{% if item.prev_form_load == true %}
{% if item.itemcategory_id_prev == -2 %}
{{ macros.infoBox('warning', "<small>Τα είδη έχουν τροποποιηθεί. Παρακαλούμε επιλέξτε εκ νέου από τη λίστα το είδος #{ item.itemcategory } εφόσον είναι διαθέσιμο.</small>") }}
{% elseif item.itemcategory_id_prev == -1 %}
{{ macros.infoBox('danger', "Δεν είναι διαθέσιμο το είδος #{ item.itemcategory } στη νέα αίτηση. Θα πρέπει να το καταργήσετε ή να επιλέξετε νέο είδος εξοπλισμού.") }}
{% else %}
{{ macros.infoBox('info', "<small>Το είδος #{ item.itemcategory } έχει αντικατασταθεί στη νέα αίτηση.</small>") }}
{% endif %}
</div>
{% endif %}
</td>
<td class="col-xs-3">{{ macros.itemSelect('lab_id', 'Χώρος', lab_choices, item.lab_id, loop.index0 ) }}</td>
<td class="col-xs-3">{{ macros.itemReasons('reasons', 'Αιτιολογία χρήσης', item.reasons, loop.index0) }}</td>
<td>
{% if loop.index0 > 0 %}
<button type="button" class="btn btn-xs text-danger remove-row">
......@@ -135,16 +156,17 @@
{% else %}
<tr>
<td>{{ macros.itemCount('qty', 'Πλήθος', '', 0) }}</td>
<td>{{ macros.itemSelect('itemcategory_id', 'Τύπος', type_choices, '', 0) }}</td>
<td>{{ macros.itemSelect('lab_id', 'Χώρος', lab_choices, '', 0 ) }}</td>
<td>{{ macros.itemReasons('reasons', 'Αιτιολογία χρήσης', '', 0) }}</td>
<td>{{ macros.itemCount('qtyacquired', 'Πλήθος', '', 0, 0) }}</td>
<td class="col-xs-3">{{ macros.itemSelect('itemcategory_id', 'Τύπος', type_choices, '', 0) }}</td>
<td class="col-xs-3">{{ macros.itemSelect('lab_id', 'Χώρος', lab_choices, '', 0 ) }}</td>
<td class="col-xs-3">{{ macros.itemReasons('reasons', 'Αιτιολογία χρήσης', '', 0) }}</td>
<td></td>
</tr>
{% endfor %}
</tbody>
<tfoot>
<tr>
<td colspan="5" class="text-right">
<td colspan="5" class="text-right col-xs-12">
<button type="button" class="btn btn-sm btn-primary add-row">
<i class="fa fa-plus"></i>
Προσθήκη εξοπλισμού
......@@ -183,6 +205,7 @@
{% endif %}
<script type="text/template" id="app-form-item-row-template">
<td>{{ macros.itemCount('qty', 'Πλήθος') }}</td>
<td>{{ macros.itemCount('qtyacquired', 'Πλήθος', '',