Commit 8b650692 authored by Vassilis Kanellopoulos's avatar Vassilis Kanellopoulos

Merge remote-tracking branch 'gtsakalos/develop' into develop

Conflicts:
	module/schools/bootstrap.php
parents 39d0b2c1 1c956df0
......@@ -52,14 +52,16 @@ return function (Slim\App $app) {
);
};
$container[Action\Labs::class] = function ($c) {
return new Action\Labs(
$c->get('view')
$container[GrEduLabs\Schools\Action\Lab\ListAll::class] = function ($c) {
return new GrEduLabs\Schools\Action\Lab\ListAll(
$c->get('view'),
$c->get('labservice'),
$c->get('staffservice')
);
};
$container[Action\LabCreate::class] = function ($c) {
return new Action\LabCreate(
$container[GrEduLabs\Schools\Action\Lab\PersistLab::class] = function ($c) {
return new GrEduLabs\Schools\Action\Lab\PersistLab(
$c->get('labservice')
);
};
......@@ -173,8 +175,8 @@ return function (Slim\App $app) {
->add(Middleware\InputFilterTeacher::class);
$this->delete('/staff', Action\Staff\DeleteTeacher::class);
$this->get('/labs', Action\Labs::class)->setName('school.labs');
$this->post('/labs', Action\LabCreate::class)->setName('school.labcreate');
$this->get('/labs', GrEduLabs\Schools\Action\Lab\ListAll::class)->setName('school.labs');
$this->post('/labs', GrEduLabs\Schools\Action\Lab\PersistLab::class)->setName('school.labcreate');
$this->get('/assets', Action\Assets\ListAssets::class)->setName('school.assets');
$this->post('/assets', Action\Assets\PersistAsset::class)
......
......@@ -241,21 +241,64 @@ INSERT INTO `itemcategory` VALUES (8,'ACCESS POINT'),(26,'LAPTOP'),(7,'MEDIA CON
/*!40000 ALTER TABLE `itemcategory` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `course`
--
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;
--
-- 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,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
`school_id` int(11) unsigned NOT NULL,
`name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`type` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`area` int(11) unsigned NOT NULL,
`attachment` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`in_school_use` tinyint(1) unsigned DEFAULT '0',
`out_school_use` tinyint(1) unsigned DEFAULT '0',
`has_network` tinyint(1) unsigned DEFAULT '0',
`has_server` tinyint(1) unsigned DEFAULT '0',
`teacher_id` int(11) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `school_id` (`school_id`),
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;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `course_lab`
--
CREATE TABLE `course_lab` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`course_id` int(11) unsigned DEFAULT NULL,
`lab_id` int(11) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UQ_5dc8c5a0ea81087a9c594a364e698c3295024b75` (`course_id`,`lab_id`),
KEY `index_foreignkey_course_lab_course` (`course_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_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;
--
-- Table structure for table `course`
--
--
-- Table structure for table `schoolasset`
--
......
......@@ -8,55 +8,72 @@
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
namespace GrEduLabs\Schools\Action;
namespace GrEduLabs\Schools\Action\Lab;
use GrEduLabs\Schools\Service\LabServiceInterface;
use GrEduLabs\Schools\Service\StaffServiceInterface;
use Slim\Http\Request;
use Slim\Http\Response;
use Slim\Views\Twig;
use RedBeanPHP\R;
class Labs
class ListAll
{
protected $view;
public function __construct(Twig $view)
public function __construct(
Twig $view,
LabServiceInterface $labservice,
StaffServiceInterface $staffservice
)
{
$this->view = $view;
$this->view = $view;
$this->labservice = $labservice;
$this->staffservice = $staffservice;
}
public function __invoke(Request $req, Response $res, array $args = [])
{
return $this->view->render($res, 'schools/labs.twig', [
'labs' => [
[
'id' => 1,
'name' => 'ΕΡΓΑΣΤΗΡΙΟ ΠΛΗΡΟΦ/ΚΗΣ 1',
'type' => 1,
'typeName' => 'ΕΡΓΑΣΤΗΡΙΟ',
'responsible' => 1,
'responsibleName' => 'Γιώργος Τάδε',
'area' => 24,
],
[
'id' => 2,
'name' => 'ΕΡΓΑΣΤΗΡΙΟ ΠΛΗΡΟΦ/ΚΗΣ 2',
'type' => 2,
'typeName' => 'ΑΙΘΟΥΣΑ',
'responsible' => 2,
'responsibleName' => 'Νίκος Τάδε',
'area' => 50,
],
],
'staff' => [
[
'value' => 1,
'label' => 'Γιώργος Τάδε',
$school = $req->getAttribute('school', false);
if (!$school) {
return $res->withStatus(403, 'No school');
}
],
[
'value' => 2,
'label' => 'Νίκος Τάδε',
],
],
// $lab = R::dispense('lab');
// $lab->school_id = 1;
// $teacher = R::load('teacher', 2);
// $lab->sharedCourse = array($course1, $course2);
// $lab->area = 55;
// $lab->in_school_use = true;
// $lab->out_school_use = false;
// $lab->attachment = 'foo/bar/qux/arxeio.gph';
// $lab->has_network = true;
// $lab->has_server = true;
// R::store($lab);
$labs = $this->labservice->getLabsBySchoolId($school->id);
$staff = $this->staffservice->getTeachersBySchoolId($school->id);
$clean_staff = [];
foreach ($staff as $obj) {
if ($obj['is_responsible']){
$clean_staff[] = [
'value' => $obj['id'],
'label' => $obj['name']." ".$obj['surname']
];
}
}
$courses = $this->labservice->getCourses();
$lessons = [];
foreach ($courses as $lesson){
$lessons[] = ['value' => $lesson->id, 'label' => $lesson->name];
}
error_log(print_r($courses,TRUE));
error_log(print_r('courses',TRUE));
return $this->view->render($res, 'schools/labs.twig', [
'labs' => $labs ,
'staff' => $clean_staff,
'lab_types' => [
[
'value' => 1,
......@@ -71,16 +88,7 @@ class Labs
'label' => 'ΓΡΑΦΕΙΟ',
],
],
'lessons' => [
[
'value' => 1,
'label' => 'ΦΥΣΙΚΗ',
],
[
'value' => 2,
'label' => 'ΠΛΗΡΟΦΟΡΙΚΗ',
],
],
'lessons' => $lessons,
]);
}
}
......@@ -8,34 +8,51 @@
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
namespace GrEduLabs\Schools\Action;
namespace GrEduLabs\Schools\Action\Lab;
use Exception;
use GrEduLabs\Schools\Service\LabServiceInterface;
use Slim\Http\Request;
use Slim\Http\Response;
class LabCreate
class PersistLab
{
public function __construct($labservice)
private $labservice;
public function __construct(LabServiceInterface $labservice)
{
$this->labservice = $labservice;
}
public function __invoke(Request $req, Response $res, array $args = [])
{
$params = $req->getParams();
if (array_key_exists('id', $params)) {
$id = $params['id'];
unset($params['id']);
$id = $this->labservice->updateLab($params, $id);
$lab = $this->labservice->getLabById($id);
} else {
$id = $this->labservice->createLab($params);
$lab = $this->labservice->getLabById($id);
$school = $req->getAttribute('school', false);
if (!$school) {
return $res->withStatus(403, 'No school');
}
$params = $req->getParams();
$id = $params['id'];
$params['school_id'] = $school->id;
unset($params['id']);
$res = $res->withJson($lab->export());
try {
if ($id > 0) {
$id = $this->labservice->updateLab($params, $id);
$lab = $this->labservice->getLabById($id);
} else {
$id = $this->labservice->createLab($params);
if ($id > 0) {
$lab = $this->labservice->getLabById($id);
}
}
if (isset($lab)) {
return $res->withJson($lab->export())->withStatus(201);
}
} catch (Exception $ex){
$res = $res->withStatus(500, $ex->getMessage());
}
return $res;
return $res->withStatus(400);
}
}
......@@ -63,11 +63,31 @@ class LabService implements LabServiceInterface
return $lab;
}
public function getLabsBySchoolId($id)
{
$school = $this->schoolService->getSchool($id);
$labs = $school->ownLab;
$labs = R::findAll('lab', 'school_id = ?', [$id]);
return array_map([$this, 'export'], $labs);
}
public function getCourses(){
$courses = R::findAll('course');
return $courses;
}
return $labs;
public function getCoursesByLabId($id){
$lab = R::load('lab', $id);
$courses = $lab->sharedCourse;
return $courses;
}
private function getCoursesById(array $ids){
$courses = [];
foreach($ids as $id){
$course = R::load('course', $id);
$courses[] = $course;
}
return $courses;
}
}
......@@ -15,4 +15,7 @@ interface LabServiceInterface
public function updateLab(array $data, $id);
public function getLabById($id);
public function getLabsBySchoolId($id);
public function getCourses();
public function getCoursesByLabId($id);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment