Commit 01695be7 authored by gtsakalos's avatar gtsakalos

Merge pull request #6 from kanellov/develop

Develop
parents 1c956df0 bae7c178
...@@ -13,8 +13,7 @@ return [ ...@@ -13,8 +13,7 @@ return [
'routes' => [ 'routes' => [
['/school', ['school'], ['get']], ['/school', ['school'], ['get']],
['/school/labs', ['school'], ['get']], ['/school/labs', ['school'], ['get']],
['/school/staff', ['school'], ['get', 'post']], ['/school/staff', ['school'], ['get', 'post', 'delete']],
['/school/staff/{id:[1-9][0-9]*}', ['school'], ['delete']],
['/school/assets', ['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 @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */; /*!40101 SET character_set_client = utf8 */;
CREATE TABLE `user` ( CREATE TABLE `user` (
...@@ -11,7 +27,19 @@ CREATE TABLE `user` ( ...@@ -11,7 +27,19 @@ CREATE TABLE `user` (
`uid` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `uid` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`authentication_source` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, `authentication_source` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`role` 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`), PRIMARY KEY (`id`),
UNIQUE KEY `mail_UNIQUE` (`mail`) UNIQUE KEY `mail_UNIQUE` (`mail`),
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; 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 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 <?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. * gredu_labs.
* *
...@@ -8,7 +15,7 @@ ...@@ -8,7 +15,7 @@
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html * @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(); $container = $app->getContainer();
$events = $container['events']; $events = $container['events'];
...@@ -18,33 +25,35 @@ return function (Slim\App $app) { ...@@ -18,33 +25,35 @@ return function (Slim\App $app) {
}); });
$events('on', 'app.services', function ($stop, $container) { $events('on', 'app.services', function ($stop, $container) {
$container[SchSync\Middleware\CreateUser::class] = function ($c) { $container[CreateUser::class] = function ($c) {
return new SchSync\Middleware\CreateUser( return new CreateUser(
$c['authentication_service'], $c->get('authentication_service'),
$c['router']->pathFor('user.login'), $c->get('router')->pathFor('user.login'),
$c['router']->pathFor('user.logout.sso'), $c->get('router')->pathFor('user.logout.sso'),
$c['flash'], $c->get('flash'),
$c['logger'] $c->get('logger')
); );
}; };
$container[SchSync\Middleware\CreateSchool::class] = function ($c) { $container[CreateSchool::class] = function ($c) {
return new SchSync\Middleware\CreateSchool( return new CreateSchool(
$c['ldap'], $c->get('ldap'),
$c[SchMM\FetchUnit::class], $c->get(FetchUnit::class),
$c['authentication_service'], $c->get('authentication_service'),
$c['router']->pathFor('user.login'), $c->get(SchoolServiceInterface::class),
$c['router']->pathFor('user.logout.sso'), $c->get(SchoolInputFilter::class),
$c['flash'], $c->get('router')->pathFor('user.login'),
$c['logger'] $c->get('router')->pathFor('user.logout.sso'),
$c->get('flash'),
$c->get('logger')
); );
}; };
}); });
$events('on', 'app.bootstrap', function ($stop, $app, $container) { $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()) { if ('user.login.sso' === $route->getName()) {
$route->add(SchSync\Middleware\CreateUser::class) $route->add(CreateUser::class)
->add(SchSync\Middleware\CreateSchool::class); ->add(CreateSchool::class);
break; break;
} }
} }
......
...@@ -10,7 +10,10 @@ ...@@ -10,7 +10,10 @@
namespace SchSync\Middleware; namespace SchSync\Middleware;
use Exception;
use GrEduLabs\Authentication\Identity; 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\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
...@@ -38,6 +41,18 @@ class CreateSchool ...@@ -38,6 +41,18 @@ class CreateSchool
*/ */
private $authService; private $authService;
/**
*
* @var SchoolServiceInterface
*/
private $schoolService;
/**
*
* @var SchoolInputFilter
*/
private $schoolInputFilter;
/** /**
* @var string * @var string
*/ */
...@@ -62,6 +77,8 @@ class CreateSchool ...@@ -62,6 +77,8 @@ class CreateSchool
Ldap $ldap, Ldap $ldap,
callable $fetchUnitFromMM, callable $fetchUnitFromMM,
AuthenticationServiceInterface $authService, AuthenticationServiceInterface $authService,
SchoolServiceInterface $schoolService,
SchoolInputFilter $schoolInputFilter,
$unitNotFoundRedirectUrl, $unitNotFoundRedirectUrl,
$ssoLogoutUrl, $ssoLogoutUrl,
Messages $flash, Messages $flash,
...@@ -70,6 +87,8 @@ class CreateSchool ...@@ -70,6 +87,8 @@ class CreateSchool
$this->ldap = $ldap; $this->ldap = $ldap;
$this->fetchUnit = $fetchUnitFromMM; $this->fetchUnit = $fetchUnitFromMM;
$this->authService = $authService; $this->authService = $authService;
$this->schoolService = $schoolService;
$this->schoolInputFilter = $schoolInputFilter;
$this->unitNotFoundRedirectUrl = (string) $unitNotFoundRedirectUrl; $this->unitNotFoundRedirectUrl = (string) $unitNotFoundRedirectUrl;
$this->ssoLogoutUrl = (string) $ssoLogoutUrl; $this->ssoLogoutUrl = (string) $ssoLogoutUrl;
$this->flash = $flash; $this->flash = $flash;
...@@ -113,33 +132,36 @@ class CreateSchool ...@@ -113,33 +132,36 @@ class CreateSchool
$school = R::findOne('school', 'registry_no = ?', [$registryNo]); $school = R::findOne('school', 'registry_no = ?', [$registryNo]);
try { try {
if (!$school) { if (!$school) {
R::begin(); $data = [
$school = R::dispense('school'); 'id' => '',
$school->registry_no = $unit['registry_no']; 'registry_no' => $unit['registry_no'],
$school->name = $unit['name']; 'name' => $unit['name'],
$school->street_address = $unit['street_address']; 'street_address' => $unit['street_address'],
$school->postal_code = $unit['postal_code']; 'postal_code' => $unit['postal_code'],
$school->phone_number = $unit['phone_number']; 'phone_number' => $unit['phone_number'],
$school->fax_number = $unit['fax_number']; 'fax_number' => $unit['fax_number'],
$school->email = $unit['email']; 'email' => $unit['email'],
$school->municipality = $unit['municipality']; 'municipality' => $unit['municipality'],
$school->schooltype_id = $unit['unit_type_id']; 'schooltype_id' => $unit['unit_type_id'],
$school->prefecture_id = $unit['prefecture_id']; 'prefecture_id' => $unit['prefecture_id'],
$school->educationlevel_id = $unit['education_level_id']; 'educationlevel_id' => $unit['education_level_id'],
$school->eduadmin_id = $unit['edu_admin_id']; 'eduadmin_id' => $unit['edu_admin_id'],
$school->created = time(); 'creator' => $identity->mail,
$school->creator = $identity->mail; ];
$school_id = R::store($school); $filtered = call_user_func($this->schoolInputFilter, $data);
$this->logger->info(sprintf('School %s imported from MM to database', $registryNo), ['creator' => $identity->mail]); 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 = R::load('user', $identity->id);
$user->school_id = $school_id; $user->school_id = $school['id'];
R::store($user); R::store($user);
$this->logger->info(sprintf('Set school %s to user %s', $registryNo, $identity->mail)); $this->logger->info(sprintf('Set school %s to user %s', $registryNo, $identity->mail));
R::commit();
} }
} catch (\Exception $e) { } catch (Exception $e) {
R::rollback();
$this->logger->error(sprintf('Problem inserting school %s form MM in database', $registryNo)); $this->logger->error(sprintf('Problem inserting school %s form MM in database', $registryNo));
$this->logger->debug('Exception', [$e->getMessage(), $e->getTraceAsString()]); $this->logger->debug('Exception', [$e->getMessage(), $e->getTraceAsString()]);
......
This diff is collapsed.
...@@ -147,25 +147,26 @@ DROP TABLE IF EXISTS `school`; ...@@ -147,25 +147,26 @@ DROP TABLE IF EXISTS `school`;
CREATE TABLE `school` ( CREATE TABLE `school` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`registry_no` varchar(25) COLLATE utf8mb4_unicode_ci NOT NULL, `registry_no` varchar(25) COLLATE utf8mb4_unicode_ci NOT NULL,
`name` varchar(191) CHARACTER SET utf8mb4 NOT NULL, `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`street_address` varchar(191) CHARACTER SET utf8mb4 NOT NULL, `street_address` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`postal_code` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL, `postal_code` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`phone_number` varchar(25) COLLATE utf8mb4_unicode_ci NOT NULL, `phone_number` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`fax_number` varchar(25) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `fax_number` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`email` varchar(255) CHARACTER SET utf8mb4 NOT NULL, `email` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`municipality` varchar(255) CHARACTER SET utf8mb4 DEFAULT NULL, `municipality` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`schooltype_id` int(11) unsigned NOT NULL, `schooltype_id` int(11) unsigned NOT NULL,
`prefecture_id` int(11) unsigned NOT NULL, `prefecture_id` int(11) unsigned NOT NULL,
`educationlevel_id` int(11) unsigned NOT NULL, `educationlevel_id` int(11) unsigned NOT NULL,
`eduadmin_id` int(11) unsigned NOT NULL, `eduadmin_id` int(11) unsigned NOT NULL,
`created` 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`), PRIMARY KEY (`id`),
UNIQUE KEY `registry_no_UNIQUE` (`registry_no`),
KEY `index_foreignkey_school_schooltype` (`schooltype_id`), KEY `index_foreignkey_school_schooltype` (`schooltype_id`),
KEY `index_foreignkey_school_prefecture` (`prefecture_id`), KEY `index_foreignkey_school_prefecture` (`prefecture_id`),
KEY `index_foreignkey_school_educationlevel` (`educationlevel_id`), KEY `index_foreignkey_school_educationlevel` (`educationlevel_id`),
KEY `index_foreignkey_school_eduadmin` (`eduadmin_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 */; /*!40101 SET character_set_client = @saved_cs_client */;
-- --
...@@ -244,17 +245,22 @@ UNLOCK TABLES; ...@@ -244,17 +245,22 @@ UNLOCK TABLES;
-- Table structure for table `course` -- Table structure for table `course`
-- --
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `course` ( CREATE TABLE `course` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `name` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`) 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` -- Table structure for table `lab`
-- --
DROP TABLE IF EXISTS `lab`; DROP TABLE IF EXISTS `lab`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `lab` ( CREATE TABLE `lab` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`school_id` int(11) unsigned NOT NULL, `school_id` int(11) unsigned NOT NULL,
...@@ -272,8 +278,7 @@ CREATE TABLE `lab` ( ...@@ -272,8 +278,7 @@ CREATE TABLE `lab` (
KEY `index_foreignkey_lab_teacher` (`teacher_id`), KEY `index_foreignkey_lab_teacher` (`teacher_id`),
CONSTRAINT `c_fk_lab_teacher_id` FOREIGN KEY (`teacher_id`) REFERENCES `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`) 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 */; /*!40101 SET character_set_client = @saved_cs_client */;
...@@ -281,6 +286,8 @@ CREATE TABLE `lab` ( ...@@ -281,6 +286,8 @@ CREATE TABLE `lab` (
-- Table structure for table `course_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` ( CREATE TABLE `course_lab` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`course_id` int(11) unsigned DEFAULT NULL, `course_id` int(11) unsigned DEFAULT NULL,
...@@ -291,12 +298,9 @@ CREATE TABLE `course_lab` ( ...@@ -291,12 +298,9 @@ CREATE TABLE `course_lab` (
KEY `index_foreignkey_course_lab_lab` (`lab_id`), 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_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 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` -- Table structure for table `schoolasset`
...@@ -321,7 +325,6 @@ CREATE TABLE `schoolasset` ( ...@@ -321,7 +325,6 @@ CREATE TABLE `schoolasset` (
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
......
...@@ -162,9 +162,12 @@ ...@@ -162,9 +162,12 @@
return; return;
} }
$.ajax({ $.ajax({
url: this.url + '/' + this.teacher.get('id'), url: that.url,
type: 'delete', type: 'delete',
dataType: 'json' dataType: 'json',
data: {
'id': that.teacher.get('id')
}
}).done(function () { }).done(function () {
that.model.remove(that.teacher.get('id')); that.model.remove(that.teacher.get('id'));
that.hide(); 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 ...@@ -28,7 +28,7 @@ class Index
$school = $req->getAttribute('school'); $school = $req->getAttribute('school');
return $this->view->render($res, 'schools/index.twig', [ return $this->view->render($res, 'schools/index.twig', [
'school' => $school->export(), 'school' => $school,
]); ]);
} }
} }
...@@ -12,21 +12,20 @@ namespace GrEduLabs\Schools\Action\Lab; ...@@ -12,21 +12,20 @@ namespace GrEduLabs\Schools\Action\Lab;
use GrEduLabs\Schools\Service\LabServiceInterface; use GrEduLabs\Schools\Service\LabServiceInterface;
use GrEduLabs\Schools\Service\StaffServiceInterface; use GrEduLabs\Schools\Service\StaffServiceInterface;
use RedBeanPHP\R;
use Slim\Http\Request; use Slim\Http\Request;
use Slim\Http\Response; use Slim\Http\Response;
use Slim\Views\Twig; use Slim\Views\Twig;
use RedBeanPHP\R;
class ListAll class ListAll
{ {
protected $view; protected $view;
public function __construct( public function __construct(
Twig $view, Twig $view,
LabServiceInterface $labservice, LabServiceInterface $labservice,
StaffServiceInterface $staffservice StaffServiceInterface $staffservice
) ) {
{
$this->view = $view; $this->view = $view;
$this->labservice = $labservice; $this->labservice = $labservice;
$this->staffservice = $staffservice; $this->staffservice = $staffservice;
...@@ -53,27 +52,28 @@ class ListAll ...@@ -53,27 +52,28 @@ class ListAll
// R::store($lab); // R::store($lab);
$labs = $this->labservice->getLabsBySchoolId($school->id); $labs = $this->labservice->getLabsBySchoolId($school->id);
$staff = $this->staffservice->getTeachersBySchoolId($school->id); $staff = $this->staffservice->getTeachersBySchoolId($school->id);
$clean_staff = []; $clean_staff = [];
foreach ($staff as $obj) { foreach ($staff as $obj) {
if ($obj['is_responsible']){ if ($obj['is_responsible']) {
$clean_staff[] = [ $clean_staff[] = [
'value' => $obj['id'], 'value' => $obj['id'],
'label' => $obj['name']." ".$obj['surname'] 'label' => $obj['name'] . " " . $obj['surname'],
]; ];
} }
} }
$courses = $this->labservice->getCourses(); $courses = $this->labservice->getCourses();
$lessons = []; $lessons = [];
foreach ($courses as $lesson){ foreach ($courses as $lesson) {
$lessons[] = ['value' => $lesson->id, 'label' => $lesson->name]; $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', [ return $this->view->render($res, 'schools/labs.twig', [
'labs' => $labs , 'labs' => $labs,
'staff' => $clean_staff, 'staff' => $clean_staff,
'lab_types' => [ 'lab_types' => [
[ [
'value' => 1, 'value' => 1,
......
...@@ -18,7 +18,7 @@ use Slim\Http\Response; ...@@ -18,7 +18,7 @@ use Slim\Http\Response;
class PersistLab