Commit 01695be7 authored by gtsakalos's avatar gtsakalos

Merge pull request #6 from kanellov/develop

Develop
parents 1c956df0 bae7c178
......@@ -13,8 +13,7 @@ return [
'routes' => [
['/school', ['school'], ['get']],
['/school/labs', ['school'], ['get']],
['/school/staff', ['school'], ['get', 'post']],
['/school/staff/{id:[1-9][0-9]*}', ['school'], ['delete']],
['/school/staff', ['school'], ['get', 'post', 'delete']],
['/school/assets', ['school'], ['get', 'post', 'delete']],
],
],
......
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `user`
--
DROP TABLE IF EXISTS `user`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `user` (
......@@ -11,7 +27,19 @@ CREATE TABLE `user` (
`uid` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`authentication_source` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`role` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`school_id` int(11) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `mail_UNIQUE` (`mail`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
UNIQUE KEY `mail_UNIQUE` (`mail`),
KEY `index_foreignkey_user_school` (`school_id`),
CONSTRAINT `c_fk_user_school_id` FOREIGN KEY (`school_id`) REFERENCES `school` (`id`) ON DELETE SET NULL ON UPDATE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
<?php
use GrEduLabs\Schools\InputFilter\School as SchoolInputFilter;
use GrEduLabs\Schools\Service\SchoolServiceInterface;
use SchMM\FetchUnit;
use SchSync\Middleware\CreateSchool;
use SchSync\Middleware\CreateUser;
use Slim\App;
/**
* gredu_labs.
*
......@@ -8,7 +15,7 @@
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
return function (Slim\App $app) {
return function (App $app) {
$container = $app->getContainer();
$events = $container['events'];
......@@ -18,33 +25,35 @@ return function (Slim\App $app) {
});
$events('on', 'app.services', function ($stop, $container) {
$container[SchSync\Middleware\CreateUser::class] = function ($c) {
return new SchSync\Middleware\CreateUser(
$c['authentication_service'],
$c['router']->pathFor('user.login'),
$c['router']->pathFor('user.logout.sso'),
$c['flash'],
$c['logger']
$container[CreateUser::class] = function ($c) {
return new CreateUser(
$c->get('authentication_service'),
$c->get('router')->pathFor('user.login'),
$c->get('router')->pathFor('user.logout.sso'),
$c->get('flash'),
$c->get('logger')
);
};
$container[SchSync\Middleware\CreateSchool::class] = function ($c) {
return new SchSync\Middleware\CreateSchool(
$c['ldap'],
$c[SchMM\FetchUnit::class],
$c['authentication_service'],
$c['router']->pathFor('user.login'),
$c['router']->pathFor('user.logout.sso'),
$c['flash'],
$c['logger']
$container[CreateSchool::class] = function ($c) {
return new CreateSchool(
$c->get('ldap'),
$c->get(FetchUnit::class),
$c->get('authentication_service'),
$c->get(SchoolServiceInterface::class),
$c->get(SchoolInputFilter::class),
$c->get('router')->pathFor('user.login'),
$c->get('router')->pathFor('user.logout.sso'),
$c->get('flash'),
$c->get('logger')
);
};
});
$events('on', 'app.bootstrap', function ($stop, $app, $container) {
foreach ($container['router']->getRoutes() as $route) {
foreach ($container->get('router')->getRoutes() as $route) {
if ('user.login.sso' === $route->getName()) {
$route->add(SchSync\Middleware\CreateUser::class)
->add(SchSync\Middleware\CreateSchool::class);
$route->add(CreateUser::class)
->add(CreateSchool::class);
break;
}
}
......
......@@ -10,7 +10,10 @@
namespace SchSync\Middleware;
use Exception;
use GrEduLabs\Authentication\Identity;
use GrEduLabs\Schools\InputFilter\School as SchoolInputFilter;
use GrEduLabs\Schools\Service\SchoolServiceInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Log\LoggerInterface;
......@@ -38,6 +41,18 @@ class CreateSchool
*/
private $authService;
/**
*
* @var SchoolServiceInterface
*/
private $schoolService;
/**
*
* @var SchoolInputFilter
*/
private $schoolInputFilter;
/**
* @var string
*/
......@@ -62,6 +77,8 @@ class CreateSchool
Ldap $ldap,
callable $fetchUnitFromMM,
AuthenticationServiceInterface $authService,
SchoolServiceInterface $schoolService,
SchoolInputFilter $schoolInputFilter,
$unitNotFoundRedirectUrl,
$ssoLogoutUrl,
Messages $flash,
......@@ -70,6 +87,8 @@ class CreateSchool
$this->ldap = $ldap;
$this->fetchUnit = $fetchUnitFromMM;
$this->authService = $authService;
$this->schoolService = $schoolService;
$this->schoolInputFilter = $schoolInputFilter;
$this->unitNotFoundRedirectUrl = (string) $unitNotFoundRedirectUrl;
$this->ssoLogoutUrl = (string) $ssoLogoutUrl;
$this->flash = $flash;
......@@ -113,33 +132,36 @@ class CreateSchool
$school = R::findOne('school', 'registry_no = ?', [$registryNo]);
try {
if (!$school) {
R::begin();
$school = R::dispense('school');
$school->registry_no = $unit['registry_no'];
$school->name = $unit['name'];
$school->street_address = $unit['street_address'];
$school->postal_code = $unit['postal_code'];
$school->phone_number = $unit['phone_number'];
$school->fax_number = $unit['fax_number'];
$school->email = $unit['email'];
$school->municipality = $unit['municipality'];
$school->schooltype_id = $unit['unit_type_id'];
$school->prefecture_id = $unit['prefecture_id'];
$school->educationlevel_id = $unit['education_level_id'];
$school->eduadmin_id = $unit['edu_admin_id'];
$school->created = time();
$school->creator = $identity->mail;
$school_id = R::store($school);
$this->logger->info(sprintf('School %s imported from MM to database', $registryNo), ['creator' => $identity->mail]);
$data = [
'id' => '',
'registry_no' => $unit['registry_no'],
'name' => $unit['name'],
'street_address' => $unit['street_address'],
'postal_code' => $unit['postal_code'],
'phone_number' => $unit['phone_number'],
'fax_number' => $unit['fax_number'],
'email' => $unit['email'],
'municipality' => $unit['municipality'],
'schooltype_id' => $unit['unit_type_id'],
'prefecture_id' => $unit['prefecture_id'],
'educationlevel_id' => $unit['education_level_id'],
'eduadmin_id' => $unit['edu_admin_id'],
'creator' => $identity->mail,
];
$filtered = call_user_func($this->schoolInputFilter, $data);
if (!$filtered['is_valid']) {
$this->logger->error('Invalid data', $filtered);
throw new Exception('Invalid data');
}
$school = $this->schoolService->createSchool($filtered['values']);
$this->logger->info(sprintf('School %s imported from MM to database', $registryNo), $filtered['values']);
$user = R::load('user', $identity->id);
$user->school_id = $school_id;
$user->school_id = $school['id'];
R::store($user);
$this->logger->info(sprintf('Set school %s to user %s', $registryNo, $identity->mail));
R::commit();
}
} catch (\Exception $e) {
R::rollback();
} catch (Exception $e) {
$this->logger->error(sprintf('Problem inserting school %s form MM in database', $registryNo));
$this->logger->debug('Exception', [$e->getMessage(), $e->getTraceAsString()]);
......
This diff is collapsed.
......@@ -147,25 +147,26 @@ DROP TABLE IF EXISTS `school`;
CREATE TABLE `school` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`registry_no` varchar(25) COLLATE utf8mb4_unicode_ci NOT NULL,
`name` varchar(191) CHARACTER SET utf8mb4 NOT NULL,
`street_address` varchar(191) CHARACTER SET utf8mb4 NOT NULL,
`postal_code` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL,
`phone_number` varchar(25) COLLATE utf8mb4_unicode_ci NOT NULL,
`fax_number` varchar(25) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`email` varchar(255) CHARACTER SET utf8mb4 NOT NULL,
`municipality` varchar(255) CHARACTER SET utf8mb4 DEFAULT NULL,
`name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`street_address` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`postal_code` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`phone_number` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`fax_number` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`email` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`municipality` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`schooltype_id` int(11) unsigned NOT NULL,
`prefecture_id` int(11) unsigned NOT NULL,
`educationlevel_id` int(11) unsigned NOT NULL,
`eduadmin_id` int(11) unsigned NOT NULL,
`created` int(11) unsigned NOT NULL,
`creator` varchar(255) CHARACTER SET utf8mb4 NOT NULL,
`creator` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `registry_no_UNIQUE` (`registry_no`),
KEY `index_foreignkey_school_schooltype` (`schooltype_id`),
KEY `index_foreignkey_school_prefecture` (`prefecture_id`),
KEY `index_foreignkey_school_educationlevel` (`educationlevel_id`),
KEY `index_foreignkey_school_eduadmin` (`eduadmin_id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
......@@ -244,17 +245,22 @@ UNLOCK TABLES;
-- Table structure for table `course`
--
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `course` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `lab`
--
DROP TABLE IF EXISTS `lab`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `lab` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`school_id` int(11) unsigned NOT NULL,
......@@ -272,8 +278,7 @@ CREATE TABLE `lab` (
KEY `index_foreignkey_lab_teacher` (`teacher_id`),
CONSTRAINT `c_fk_lab_teacher_id` FOREIGN KEY (`teacher_id`) REFERENCES `teacher` (`id`),
CONSTRAINT `lab_ibfk_1` FOREIGN KEY (`school_id`) REFERENCES `school` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
......@@ -281,6 +286,8 @@ CREATE TABLE `lab` (
-- Table structure for table `course_lab`
--
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `course_lab` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`course_id` int(11) unsigned DEFAULT NULL,
......@@ -291,12 +298,9 @@ CREATE TABLE `course_lab` (
KEY `index_foreignkey_course_lab_lab` (`lab_id`),
CONSTRAINT `c_fk_course_lab_lab_id` FOREIGN KEY (`lab_id`) REFERENCES `lab` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `c_fk_course_lab_course_id` FOREIGN KEY (`course_id`) REFERENCES `course` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `course`
--
--
-- Table structure for table `schoolasset`
......@@ -321,7 +325,6 @@ CREATE TABLE `schoolasset` (
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
......
......@@ -162,9 +162,12 @@
return;
}
$.ajax({
url: this.url + '/' + this.teacher.get('id'),
url: that.url,
type: 'delete',
dataType: 'json'
dataType: 'json',
data: {
'id': that.teacher.get('id')
}
}).done(function () {
that.model.remove(that.teacher.get('id'));
that.hide();
......
<?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
*/
namespace GrEduLabs\Schools\Action;
use Slim\Http\Request;
use Slim\Http\Response;
use Slim\Views\Twig;
class Assets
{
protected $view;
public function __construct(Twig $view)
{
$this->view = $view;
}
public function __invoke(Request $req, Response $res, array $args = [])
{
return $this->view->render($res, 'schools/assets.twig', [
'assets' => [
[
'id' => 1,
'type' => 1,
'typeName' => 'ΒΙΝΤΕΟΠΡΟΒΟΛΕΑΣ',
'lab' => 1,
'labName' => 'ΕΡΓΑΣΤΗΡΙΟ ΠΛΗΡΟΦ/ΚΗΣ 1',
'quantity' => 2,
'acquisitionYear' => '2001',
'comments' => 'test',
],
[
'id' => 2,
'type' => 3,
'typeName' => 'LAPTOP',
'lab' => 2,
'labName' => 'ΕΡΓΑΣΤΗΡΙΟ ΠΛΗΡΟΦ/ΚΗΣ 2',
'quantity' => 1,
'acquisitionYear' => '2003',
'comments' => 'test',
],
[
'id' => 3,
'type' => 2,
'typeName' => 'ΠΛΗΚΤΡΟΛΟΓΙΟ',
'lab' => 2,
'labName' => 'ΕΡΓΑΣΤΗΡΙΟ ΠΛΗΡΟΦ/ΚΗΣ 2',
'quantity' => 10,
'acquisitionYear' => '2008',
'comments' => 'test',
],
],
]);
}
}
......@@ -28,7 +28,7 @@ class Index
$school = $req->getAttribute('school');
return $this->view->render($res, 'schools/index.twig', [
'school' => $school->export(),
'school' => $school,
]);
}
}
......@@ -12,10 +12,10 @@ namespace GrEduLabs\Schools\Action\Lab;
use GrEduLabs\Schools\Service\LabServiceInterface;
use GrEduLabs\Schools\Service\StaffServiceInterface;
use RedBeanPHP\R;
use Slim\Http\Request;
use Slim\Http\Response;
use Slim\Views\Twig;
use RedBeanPHP\R;
class ListAll
{
......@@ -25,8 +25,7 @@ class ListAll
Twig $view,
LabServiceInterface $labservice,
StaffServiceInterface $staffservice
)
{
) {
$this->view = $view;
$this->labservice = $labservice;
$this->staffservice = $staffservice;
......@@ -57,22 +56,23 @@ class ListAll
$staff = $this->staffservice->getTeachersBySchoolId($school->id);
$clean_staff = [];
foreach ($staff as $obj) {
if ($obj['is_responsible']){
if ($obj['is_responsible']) {
$clean_staff[] = [
'value' => $obj['id'],
'label' => $obj['name']." ".$obj['surname']
'label' => $obj['name'] . " " . $obj['surname'],
];
}
}
$courses = $this->labservice->getCourses();
$lessons = [];
foreach ($courses as $lesson){
foreach ($courses as $lesson) {
$lessons[] = ['value' => $lesson->id, 'label' => $lesson->name];
}
error_log(print_r($courses,TRUE));
error_log(print_r('courses',TRUE));
error_log(print_r($courses, TRUE));
error_log(print_r('courses', TRUE));
return $this->view->render($res, 'schools/labs.twig', [
'labs' => $labs ,
'labs' => $labs,
'staff' => $clean_staff,
'lab_types' => [
[
......
......@@ -48,11 +48,10 @@ class PersistLab
if (isset($lab)) {
return $res->withJson($lab->export())->withStatus(201);
}
} catch (Exception $ex){
} catch (Exception $ex) {
$res = $res->withStatus(500, $ex->getMessage());
}
return $res->withStatus(400);
}
}
......@@ -28,13 +28,13 @@ class DeleteTeacher
$this->staffService = $staffService;
}
public function __invoke(Request $req, Response $res, array $args = [])
public function __invoke(Request $req, Response $res)
{
$school = $req->getAttribute('school', false);
if (!$school->id) {
return $res->withStatus(403, 'No school');
}
$id = isset($args['id']) ? $args['id'] : false;
$id = $req->getParam('id', false);
if (!$id) {
$res = $res->withStatus(404);
......
<?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
*/
namespace GrEduLabs\Schools\InputFilter;
use Exception;
use GrEduLabs\Schools\Service\SchoolServiceInterface;
use Zend\Filter;
use Zend\InputFilter\Input;
use Zend\InputFilter\InputFilter;
use Zend\Validator;
class School
{
use InputFilterTrait;
public function __construct(
SchoolServiceInterface $schoolService
) {
$id = new Input('id');
$id->setRequired(false)
->getValidatorChain()
->attach(new Validator\Digits());
$registryNo = new Input('registry_no');
$registryNo->setRequired(true)
->getValidatorChain()
->attach(new Validator\NotEmpty())
->attach(new Validator\Callback([
'callback' => function ($value, $context = []) use ($schoolService) {
$id = isset($context['id']) ? $context['id'] : false;
if (false === $id) {
throw new Exception('No id in context');
}
try {
$school = $schoolService->findSchoolByRegistryNo($value);
if (!$school || (isset($school['id']) && !$school['id'])) {
return true;
}
return $school['id'] == $id;
} catch (Exception $ex) {
return false;
}
},
'messageTemplate' => 'Το σχολείο με κωδικό %value% υπάρχει ήδη',
]));
$name = new Input('name');
$name->setRequired(true)
->getFilterChain()
->attach(new Filter\StripTags())
->attach(new Filter\StringTrim());
$name->getValidatorChain()
->attach(new Validator\NotEmpty());
$streetAddress = new Input('street_address');
$streetAddress->setRequired(false)
->getFilterChain()
->attach(new Filter\StripTags())
->attach(new Filter\StringTrim());
$postalCode = new Input('postal_code');
$postalCode->setRequired(false)
->getFilterChain()
->attach(new Filter\Digits());
$phoneNumber = new Input('phone_number');
$phoneNumber->setRequired(false)
->getFilterChain()
->attach(new Filter\Digits());
$faxNumber = new Input('fax_number');
$faxNumber->setRequired(false)
->getFilterChain()
->attach(new Filter\Digits());
$email = new Input('email');
$email->setRequired(false)
->getValidatorChain()
->attach(new Validator\EmailAddress());
$municipality = new Input('municipality');
$municipality->setRequired(true)
->getFilterChain()
->attach(new Filter\StripTags())
->attach(new Filter\StringTrim());
$schoolTypeId = new Input('schooltype_id');
$schoolTypeId->setRequired(true)
->getFilterChain()
->attach(new Filter\ToInt());
$prefectureId = new Input('prefecture_id');
$prefectureId->setRequired(true)
->getFilterChain()
->attach(new Filter\ToInt());
$educationlevelId = new Input('educationlevel_id');
$educationlevelId->setRequired(true)
->getFilterChain()
->attach(new Filter\ToInt());
$eduadminId = new Input('eduadmin_id');
$eduadminId->setRequired(true)
->getFilterChain()
->attach(new Filter\ToInt());
$creator = new Input('creator');
$creator->setRequired(true)