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

New applications form

parents 2af31e8f 3951a5c0
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"hash": "ce63645072785d61c343bdef07061ae2", "hash": "b3178a5d5f722fad84f4c0311d54457a",
"content-hash": "86cc938c4ba809f58f72c6f3c4a9d635", "content-hash": "f000cf68a96e1a870a120eb816628d24",
"packages": [ "packages": [
{ {
"name": "container-interop/container-interop", "name": "container-interop/container-interop",
...@@ -1079,16 +1079,16 @@ ...@@ -1079,16 +1079,16 @@
}, },
{ {
"name": "slim/slim", "name": "slim/slim",
"version": "3.4.2", "version": "3.5.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/slimphp/Slim.git", "url": "https://github.com/slimphp/Slim.git",
"reference": "a132385f736063d00632b52b3f8a389fe66fe4fa" "reference": "184352bc1913d7ba552ab4131d62f4730ddb0893"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/slimphp/Slim/zipball/a132385f736063d00632b52b3f8a389fe66fe4fa", "url": "https://api.github.com/repos/slimphp/Slim/zipball/184352bc1913d7ba552ab4131d62f4730ddb0893",
"reference": "a132385f736063d00632b52b3f8a389fe66fe4fa", "reference": "184352bc1913d7ba552ab4131d62f4730ddb0893",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
...@@ -1145,7 +1145,7 @@ ...@@ -1145,7 +1145,7 @@
"micro", "micro",
"router" "router"
], ],
"time": "2016-05-25 11:23:38" "time": "2016-07-26 15:12:13"
}, },
{ {
"name": "slim/twig-view", "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 @@ ...@@ -11,6 +11,7 @@
'dsn' => '', 'dsn' => '',
'user' => null, 'user' => null,
'pass' => null, 'pass' => null,
'freeze' => true,
'options' => [ 'options' => [
], ],
......
...@@ -48,6 +48,7 @@ CREATE TABLE `applicationformitem` ( ...@@ -48,6 +48,7 @@ CREATE TABLE `applicationformitem` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`itemcategory_id` int(11) unsigned NOT NULL, `itemcategory_id` int(11) unsigned NOT NULL,
`qty` 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, `reasons` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`applicationform_id` int(11) unsigned NOT NULL, `applicationform_id` int(11) unsigned NOT NULL,
`lab_id` int(11) unsigned NOT NULL, `lab_id` int(11) unsigned NOT NULL,
...@@ -158,9 +159,11 @@ DROP TABLE IF EXISTS `itemcategory`; ...@@ -158,9 +159,11 @@ DROP TABLE IF EXISTS `itemcategory`;
CREATE TABLE `itemcategory` ( CREATE TABLE `itemcategory` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, `name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`groupflag` int(11) unsigned DEFAULT 0,
`sort` int(11) unsigned DEFAULT 0,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `name_UNIQUE` (`name`) 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 */; /*!40101 SET character_set_client = @saved_cs_client */;
-- --
...@@ -169,7 +172,54 @@ CREATE TABLE `itemcategory` ( ...@@ -169,7 +172,54 @@ CREATE TABLE `itemcategory` (
LOCK TABLES `itemcategory` WRITE; LOCK TABLES `itemcategory` WRITE;
/*!40000 ALTER TABLE `itemcategory` DISABLE KEYS */; /*!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 */; /*!40000 ALTER TABLE `itemcategory` ENABLE KEYS */;
UNLOCK TABLES; UNLOCK TABLES;
......
...@@ -44,6 +44,8 @@ return function (Slim\App $app) { ...@@ -44,6 +44,8 @@ return function (Slim\App $app) {
}; };
$container[GrEduLabs\ApplicationForm\Action\ApplicationForm::class] = function ($c) { $container[GrEduLabs\ApplicationForm\Action\ApplicationForm::class] = function ($c) {
$settings = $c->get('settings');
$currentVersion = $settings['application_form']['itemcategory']['currentversion'];
return new GrEduLabs\ApplicationForm\Action\ApplicationForm( return new GrEduLabs\ApplicationForm\Action\ApplicationForm(
$c->get('view'), $c->get('view'),
$c->get(GrEduLabs\Schools\Service\AssetServiceInterface::class), $c->get(GrEduLabs\Schools\Service\AssetServiceInterface::class),
...@@ -51,7 +53,9 @@ return function (Slim\App $app) { ...@@ -51,7 +53,9 @@ return function (Slim\App $app) {
$c->get(GrEduLabs\ApplicationForm\Service\ApplicationFormServiceInterface::class), $c->get(GrEduLabs\ApplicationForm\Service\ApplicationFormServiceInterface::class),
$c->get(GrEduLabs\ApplicationForm\InputFilter\ApplicationForm::class), $c->get(GrEduLabs\ApplicationForm\InputFilter\ApplicationForm::class),
$c->get('authentication_service'), $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) { ...@@ -79,7 +83,8 @@ return function (Slim\App $app) {
$container[GrEduLabs\ApplicationForm\Middleware\SchoolApplicationForm::class] = function ($c) { $container[GrEduLabs\ApplicationForm\Middleware\SchoolApplicationForm::class] = function ($c) {
return new GrEduLabs\ApplicationForm\Middleware\SchoolApplicationForm( return new GrEduLabs\ApplicationForm\Middleware\SchoolApplicationForm(
$c->get('view'), $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` ( ...@@ -48,6 +48,7 @@ CREATE TABLE `applicationformitem` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`itemcategory_id` int(11) unsigned NOT NULL, `itemcategory_id` int(11) unsigned NOT NULL,
`qty` 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, `reasons` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`applicationform_id` int(11) unsigned NOT NULL, `applicationform_id` int(11) unsigned NOT NULL,
`lab_id` int(11) unsigned NOT NULL, `lab_id` int(11) unsigned NOT NULL,
......
<?php <?php
/** /**
* gredu_labs. * gredu_labs.
* *
...@@ -19,8 +20,8 @@ use Slim\Views\Twig; ...@@ -19,8 +20,8 @@ use Slim\Views\Twig;
use Zend\Authentication\AuthenticationServiceInterface; use Zend\Authentication\AuthenticationServiceInterface;
use Zend\InputFilter\InputFilterInterface; use Zend\InputFilter\InputFilterInterface;
class ApplicationForm class ApplicationForm {
{
/** /**
* @var Twig * @var Twig
*/ */
...@@ -56,6 +57,18 @@ class ApplicationForm ...@@ -56,6 +57,18 @@ class ApplicationForm
*/ */
protected $authService; protected $authService;
/**
*
* @var int The version of the application form to handle
*/
protected $version;
/**
*
* @var type SLIM application container
*/
protected $container;
/** /**
* *
* @var string * @var string
...@@ -63,69 +76,124 @@ class ApplicationForm ...@@ -63,69 +76,124 @@ class ApplicationForm
protected $successUrl; protected $successUrl;
public function __construct( public function __construct(
Twig $view, Twig $view, AssetServiceInterface $assetsService, LabServiceInterface $labService, ApplicationFormServiceInterface $appFormService, InputFilterInterface $appFormInputFilter, AuthenticationServiceInterface $authService, $successUrl, $version, $container
AssetServiceInterface $assetsService,
LabServiceInterface $labService,
ApplicationFormServiceInterface $appFormService,
InputFilterInterface $appFormInputFilter,
AuthenticationServiceInterface $authService,
$successUrl
) { ) {
$this->view = $view; $this->view = $view;
$this->assetsService = $assetsService; $this->assetsService = $assetsService;
$this->labService = $labService; $this->labService = $labService;
$this->appFormService = $appFormService; $this->appFormService = $appFormService;
$this->appFormInputFilter = $appFormInputFilter; $this->appFormInputFilter = $appFormInputFilter;
$this->authService = $authService; $this->authService = $authService;
$this->successUrl = $successUrl; $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'); $school = $req->getAttribute('school');
if ($req->isPost()) { if ($req->isPost()) {
$this->appFormInputFilter->setData(array_merge($req->getParams(), [ $reqParams = $req->getParams();
'school_id' => $school->id, array_splice($reqParams['items'], 0, 0);
'submitted_by'=> $this->authService->getIdentity()->mail, $this->appFormInputFilter->setData(array_merge($reqParams, [
'school_id' => $school->id,
'submitted_by' => $this->authService->getIdentity()->mail,
])); ]));
$isValid = $this->appFormInputFilter->isValid(); $isValid = $this->appFormInputFilter->isValid();
if ($isValid) { if ($isValid) {
$data = $this->appFormInputFilter->getValues(); $data = $this->appFormInputFilter->getValues();
$appForm = $this->appFormService->submit($data); $appForm = $this->appFormService->submit($data);
$_SESSION['applicationForm']['appForm'] = $appForm; $_SESSION['applicationForm']['appForm'] = $appForm;
$res = $res->withRedirect($this->successUrl); $res = $res->withRedirect($this->successUrl);
return $res; return $res;
} }
$this->view['form'] = [ $this->view['form'] = [
'is_valid' => $isValid, 'is_valid' => $isValid,
'values' => $this->appFormInputFilter->getValues(), 'values' => $this->appFormInputFilter->getValues(),
'raw_values' => $this->appFormInputFilter->getRawValues(), '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(); $this->view['choose'] = !$loadForm && !$req->isPost();
if (!$req->isPost() && $loadForm) { if (!$req->isPost() && $loadForm) {
// take care of new options in applications and migrate existing ones
if (null !== ($appForm = $this->appFormService->findSchoolApplicationForm($school->id))) { 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'] = [ $this->view['form'] = [
'values' => $appForm, 'values' => $appForm,
]; ];
} }
} }
$labs = $this->labService->getLabsBySchoolId($school->id); $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) { 'lab_choices' => array_map(function ($lab) {
return ['value' => $lab['id'], 'label' => $lab['name']]; return ['value' => $lab['id'], 'label' => $lab['name']];
}, $labs), }, $labs),
'type_choices' => array_map(function ($category) { 'type_choices' => array_map(function ($category) {
return ['value' => $category['id'], 'label' => $category['name']]; return ['value' => $category['id'], 'label' => $category['name']];
}, $this->assetsService->getAllItemCategories()), }, $this->assetsService->getAllItemCategories($this->version)),
]); ]);
return $res; return $res;
} }
}
}
\ No newline at end of file
...@@ -58,6 +58,18 @@ class ApplicationFormItem extends InputFilter ...@@ -58,6 +58,18 @@ class ApplicationFormItem extends InputFilter
'min' => 0, '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 = new Input('reasons');
$reasons->setRequired(true) $reasons->setRequired(true)
->getFilterChain() ->getFilterChain()
...@@ -69,6 +81,7 @@ class ApplicationFormItem extends InputFilter ...@@ -69,6 +81,7 @@ class ApplicationFormItem extends InputFilter
$this->add($labId) $this->add($labId)
->add($itemCategoryId) ->add($itemCategoryId)
->add($qty) ->add($qty)
->add($qtyacquired)
->add($reasons); ->add($reasons);
} }
} }
...@@ -24,6 +24,7 @@ class SchoolApplicationForm ...@@ -24,6 +24,7 @@ class SchoolApplicationForm
* @var Twig * @var Twig
*/ */
protected $view; protected $view;
protected $container;
/** /**
* *
...@@ -31,10 +32,11 @@ class SchoolApplicationForm ...@@ -31,10 +32,11 @@ class SchoolApplicationForm
*/ */
protected $appFormService; protected $appFormService;
public function __construct(Twig $view, ApplicationFormServiceInterface $appFormService) public function __construct(Twig $view, ApplicationFormServiceInterface $appFormService, $container)
{ {
$this->view = $view; $this->view = $view;
$this->appFormService = $appFormService; $this->appFormService = $appFormService;
$this->container = $container;
} }
public function __invoke(Request $req, Response $res, callable $next) public function __invoke(Request $req, Response $res, callable $next)
...@@ -43,15 +45,51 @@ class SchoolApplicationForm ...@@ -43,15 +45,51 @@ class SchoolApplicationForm
$appForm = $this->appFormService->findSchoolApplicationForm($school->id); $appForm = $this->appFormService->findSchoolApplicationForm($school->id);
if ($appForm) { 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']; $category = $item['itemcategory_id'];
if (!isset($aggr[$category])) { if (!isset($aggr[$category])) {
$aggr[$category] = [ $aggr[$category] = [
'category' => $item['itemcategory'],