Commit 29fb0a3d authored by kanellov's avatar kanellov

fix some issues with staff

parent ad15c8f7
......@@ -13,7 +13,7 @@ return [
'routes' => [
['/school', ['school'], ['get']],
['/school/labs', ['school'], ['get']],
['/school/staff', ['school'], ['get']],
['/school/staff', ['school'], ['get', 'post']],
['/school/assets', ['school'], ['get']],
],
],
......
......@@ -54,28 +54,32 @@ return function (Slim\App $app) {
return new GrEduLabs\Schools\Action\Assets($c->get('view'));
};
$container['schoolservice'] = function($c){
return new GrEduLabs\Schools\Service\SchoolService();
$container['schoolservice'] = function ($c) {
return new GrEduLabs\Schools\Service\SchoolService();
};
$container['staffservice'] = function($c){
return new GrEduLabs\Schools\Service\StaffService(
$c->get('schoolservice')
);
$container['staffservice'] = function ($c) {
return new GrEduLabs\Schools\Service\StaffService(
$c->get('schoolservice')
);
};
$container['labservice'] = function($c){
return new GrEduLabs\Schools\Service\LabService(
$c->get('schoolservice'),
$c->get('staffservice')
);
$container['labservice'] = function ($c) {
return new GrEduLabs\Schools\Service\LabService(
$c->get('schoolservice'),
$c->get('staffservice')
);
};
$container['assetservice'] = function($c){
return new GrEduLabs\Schools\Service\AssetService(
$c->get('schoolservice'),
$c->get('labservice')
);
$container['assetservice'] = function ($c) {
return new GrEduLabs\Schools\Service\AssetService(
$c->get('schoolservice'),
$c->get('labservice')
);
};
$container[GrEduLabs\Schools\Middleware\FetchSchoolFromIdentity::class] = function ($c) {
return new GrEduLabs\Schools\Middleware\FetchSchoolFromIdentity($c['authentication_service']);
};
});
......@@ -90,5 +94,6 @@ return function (Slim\App $app) {
$this->get('/labs', GrEduLabs\Schools\Action\Labs::class)->setName('school.labs');
$this->post('/labs', GrEduLabs\Schools\Action\LabCreate::class)->setName('school.labcreate');
$this->get('/assets', GrEduLabs\Schools\Action\Assets::class)->setName('school.assets');
});
})->add(GrEduLabs\Schools\Middleware\FetchSchoolFromIdentity::class);
});
};
<?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 function (Slim\App $app) {
$container = $app->getContainer();
$events = $container['events'];
<<<<<<< HEAD
$events('on', 'app.autoload', function ($stop, $autoloader) {
$autoloader->addPsr4('GrEduLabs\\Schools\\', __DIR__ . '/src/');
});
$events('on', 'app.services', function ($stop, $container) {
$container[GrEduLabs\Schools\Action\Index::class] = function ($c) {
return new GrEduLabs\Schools\Action\Index($c->get('view'));
};
$container[GrEduLabs\Schools\Action\Staff::class] = function ($c) {
return new GrEduLabs\Schools\Action\Staff($c->get('view'));
};
=======
$container['autoloader']->addPsr4('GrEduLabs\\Schools\\', __DIR__ . '/src/');
$container[GrEduLabs\Schools\Action\Index::class] = function ($c) {
return new GrEduLabs\Schools\Action\Index(
$c->get('view'),
$c->get('schoolservice')
);
};
$container[GrEduLabs\Schools\Action\Staff::class] = function ($c) {
return new GrEduLabs\Schools\Action\Staff(
$c->get('view'),
$c->get('staffservice')
);
};
$container[GrEduLabs\Schools\Action\StaffCreate::class] = function ($c) {
return new GrEduLabs\Schools\Action\StaffCreate(
$c->get('staffservice')
);
};
$container[GrEduLabs\Schools\Action\Labs::class] = function ($c) {
return new GrEduLabs\Schools\Action\Labs(
$c->get('view')
);
};
$container[GrEduLabs\Schools\Action\LabCreate::class] = function ($c) {
return new GrEduLabs\Schools\Action\LabCreate(
$c->get('labservice')
);
};
>>>>>>> gtsakalos/modular
$container[GrEduLabs\Schools\Action\Labs::class] = function ($c) {
return new GrEduLabs\Schools\Action\Labs($c->get('view'));
};
<<<<<<< HEAD
$container[GrEduLabs\Schools\Action\Assets::class] = function ($c) {
return new GrEduLabs\Schools\Action\Assets($c->get('view'));
};
});
=======
$container['schoolservice'] = function($c){
return new GrEduLabs\Schools\Service\SchoolService();
};
$container['staffservice'] = function($c){
return new GrEduLabs\Schools\Service\StaffService(
$c->get('schoolservice')
);
};
$container['labservice'] = function($c){
return new GrEduLabs\Schools\Service\LabService(
$c->get('schoolservice'),
$c->get('staffservice')
);
};
$container['assetservice'] = function($c){
return new GrEduLabs\Schools\Service\AssetService(
$c->get('schoolservice'),
$c->get('labservice')
);
};
$events = $container['events'];
>>>>>>> gtsakalos/modular
$events('on', 'app.bootstrap', function ($stop, $app, $container) {
$container['view']->getEnvironment()->getLoader()->prependPath(__DIR__ . '/templates');
<<<<<<< HEAD
$app->group('/school', function () {
$this->get('', GrEduLabs\Schools\Action\Index::class)->setName('school');
$this->get('/staff', GrEduLabs\Schools\Action\Staff::class)->setName('school.staff');
$this->get('/labs', GrEduLabs\Schools\Action\Labs::class)->setName('school.labs');
$this->get('/assets', GrEduLabs\Schools\Action\Assets::class)->setName('school.assets');
});
=======
$app->group('/school', function () {
$this->get('', GrEduLabs\Schools\Action\Index::class)->setName('school');
$this->get('/staff', GrEduLabs\Schools\Action\Staff::class)->setName('school.staff');
$this->post('/staff', GrEduLabs\Schools\Action\StaffCreate::class)->setName('school.staffcreate');
$this->get('/labs', GrEduLabs\Schools\Action\Labs::class)->setName('school.labs');
$this->post('/labs', GrEduLabs\Schools\Action\LabCreate::class)->setName('school.labcreate');
$this->get('/assets', GrEduLabs\Schools\Action\Assets::class)->setName('school.assets');
>>>>>>> gtsakalos/modular
});
};
......@@ -57,6 +57,7 @@
evt.preventDefault();
this.modal.render(function (data) {
that.model.add(data);
that.$el.find('.no-records').remove();
});
return this;
},
......@@ -109,15 +110,18 @@
hash[pair.name] = pair.value;
return hash;
}, {});
var that = this;
evt.preventDefault();
if (!data.id) {
data.id = (100 * Math.random()).toFixed(0);
}
this.form.data('done')(data);
this.form.data('done', undefined);
this.hide();
$.post("", data).
done(function(response){
that.form.data('done')(response);
that.form.data('done', undefined);
that.hide();
}).fail(function (xhr, err) {
alert(xhr.statusText);
});
}
});
new StaffView({ model: new Staff() });
}());
\ No newline at end of file
}());
......@@ -25,9 +25,7 @@ class Index
public function __invoke(Request $req, Response $res, array $args = [])
{
$identity = $req->getAttribute('identity');
$user = \RedBeanPHP\R::load('user', $identity->id);
$school = $user->school;
$school = $req->getAttribute('school');
return $this->view->render($res, 'schools/index.twig', [
'school' => $school->export(),
......
......@@ -24,18 +24,18 @@ class LabCreate
public function __invoke(Request $req, Response $res, array $args = [])
{
$params = $req->getParams();
if (array_key_exists('id', $params)){
if (array_key_exists('id', $params)) {
$id = $params['id'];
unset($params['id']);
$id = $this->labservice->updateLab($params, $id);
$id = $this->labservice->updateLab($params, $id);
$lab = $this->labservice->getLabById($id);
}
else{
$id = $this->labservice->createLab($params);
} else {
$id = $this->labservice->createLab($params);
$lab = $this->labservice->getLabById($id);
}
$res = $res->withJson($lab->export());
return $res;
}
}
......@@ -20,24 +20,28 @@ class Staff
public function __construct(Twig $view, $staffservice)
{
$this->view = $view;
$this->view = $view;
$this->staffservice = $staffservice;
}
public function __invoke(Request $req, Response $res, array $args = [])
{
$staff = $this->staffservice->getTeachersBySchoolId(1);
return $this->view->render($res, 'schools/staff.twig', [
'staff' => $staff,
'staff' => array_map(function ($employee) {
return array_merge($employee->export(), [
'branch' => $employee->branch->name,
]);
}, $staff),
'positions' => [
['value' => 1, 'label' => 'Εκπαδευτικός'],
['value' => 2, 'label' => 'Διευθυντής σχολείου'],
['value' => 3, 'label' => 'Υπεύθυνος εργαστηρίου'],
],
'branches' => [
['value' => 'branch1', 'label' => 'branch'],
['value' => 'branch2', 'label' => 'branch2'],
],
'branches' => array_map(function ($branch) {
return ['value' => $branch['id'], 'label' => $branch['name']];
}, $this->staffservice->getBranches()),
]);
}
}
......@@ -23,24 +23,29 @@ class StaffCreate
public function __invoke(Request $req, Response $res, array $args = [])
{
$school = $req->getAttribute('school', false);
if (!$school) {
return $res->withStatus(403, 'No school');
}
$params = $req->getParams();
$id = $params['id'];
$id = $params['id'];
unset($params['id']);
if ($id > 0){
$id = $this->staffservice->updateTeacher($params, $id);
$params['school_id'] = $school->id;
if ($id > 0) {
$id = $this->staffservice->updateTeacher($params, $id);
$teacher = $this->staffservice->getTeacherById($id);
}
else{
} else {
$id = $this->staffservice->createTeacher($params);
if ($id > 0){
if ($id > 0) {
$teacher = $this->staffservice->getTeacherById($id);
}
}
if (isset($teacher)){
return $res->withJson($teacher->export())->withStatus(201);
}
else{
if (isset($teacher)) {
return $res->withJson(array_merge($teacher->export(), [
'branch' => $teacher->branch->name,
]))->withStatus(201);
} else {
return $res->withStatus(400);
}
}
......
<?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\Middleware;
use RedBeanPHP\R;
class FetchSchoolFromIdentity
{
protected $authService;
public function __construct($authService)
{
$this->authService = $authService;
}
public function __invoke($req, $res, $next)
{
$identity = $this->authService->getIdentity();
if (!$identity) {
return $res->withStatus(403, 'No identity');
}
$user = R::load('user', $identity->id);
if (!($school = $user->school)) {
return $res->withStatus(403, 'No school');
}
return $next($req->withAttribute('school', $school), $res);
}
}
......@@ -17,24 +17,22 @@ class LabService implements LabServiceInterface
protected $staffService;
public function __construct(
SchoolServiceInterface $schoolService,
SchoolServiceInterface $schoolService,
StaffServiceInterface $staffService
) {
$this->schoolService = $schoolService;
$this->staffService = $staffService;
$this->staffService = $staffService;
}
public function createLab(array $data)
{
$lab = R::dispense('lab');
$required = ['school_id', 'name', 'type', 'area', 'in_school_use', 'out_school_use',
'courses', 'attachment', 'has_network', 'has_server' ];
foreach ($required as $value){
if (array_key_exists($value, $data)){
$lab = R::dispense('lab');
$required = ['school_id', 'name', 'type', 'area', 'in_school_use', 'out_school_use',
'courses', 'attachment', 'has_network', 'has_server', ];
foreach ($required as $value) {
if (array_key_exists($value, $data)) {
$lab[$value] = $data[$value];
}
else
{
} else {
return -1;
}
}
......@@ -44,27 +42,32 @@ class LabService implements LabServiceInterface
}
$id = R::store($lab);
return $id;
}
public function updateLab(array $data, $id){
public function updateLab(array $data, $id)
{
$lab= R::load('lab', $id);
foreach ($data as $key => $value){
foreach ($data as $key => $value) {
$lab[$key] = $value;
}
$id = R::store($lab);
return $id;
}
public function getLabById($id)
{
$lab = R::load('lab', $id);
return $lab;
}
public function getLabsBySchoolId($id)
{
$school = $this->schoolService->getSchool($id);
$labs = $school->ownLab;
$labs = $school->ownLab;
return $labs;
}
}
......@@ -17,7 +17,7 @@ class SchoolService implements SchoolServiceInterface
{
$school = R::dispense('school');
$required = ['registry_no', 'name', 'municipality','schooltype_id', 'prefecture_id',
'educationlevel_id', 'eduadmin_id', 'created', 'creator'];
'educationlevel_id', 'eduadmin_id', 'created', 'creator', ];
$optional = ['street_address', 'postal_code', 'phone_number', 'fax_number', 'email'];
foreach ($required as $value) {
if (array_key_exists($value, $data)) {
......@@ -34,11 +34,13 @@ class SchoolService implements SchoolServiceInterface
}
}
$id = R::store($school);
return $id;
}
public function getSchool($id)
{
$school = R::load('school', $id);
return $school;
}
}
......@@ -24,8 +24,8 @@ class StaffService implements StaffServiceInterface
unset($data['id']);
$teacher = R::dispense('teacher');
$required = ['school_id', 'name','email', 'surname', 'telephone',
'position', 'branch'];
$data['school_id'] = 1;
'position', 'branch_id', ];
foreach ($required as $value) {
if (array_key_exists($value, $data)) {
$teacher[$value] = $data[$value];
......@@ -34,21 +34,25 @@ class StaffService implements StaffServiceInterface
}
}
$id = R::store($teacher);
return $id;
}
public function updateTeacher(array $data, $id){
public function updateTeacher(array $data, $id)
{
$teacher = R::load('teacher', $id);
foreach ($data as $key => $value){
foreach ($data as $key => $value) {
$teacher[$key] = $value;
}
$id = R::store($teacher);
return $id;
}
public function getTeacherById($id)
{
$teacher = R::load('teacher', $id);
return $teacher;
}
......@@ -56,6 +60,14 @@ class StaffService implements StaffServiceInterface
{
$school = $this->schoolService->getSchool($id);
$teachers = $school->ownTeacher;
return $teachers;
}
public function getBranches()
{
return array_map(function ($branch) {
return $branch->export();
}, R::find('branch', 'ORDER BY name ASC'));
}
}
......@@ -15,4 +15,5 @@ interface StaffServiceInterface
public function getTeacherById($id);
public function getTeachersBySchoolId($id);
public function updateTeacher(array $data, $id);
public function getBranches();
}
......@@ -43,7 +43,7 @@
</tr>
{% else %}
<tr>
<td colspan="3" class="text-center text-muted">
<td colspan="6" class="text-center text-muted no-records">
Δεν έχει καταχωρηθεί προσωπικό.
</td>
</tr>
......@@ -71,7 +71,7 @@
{{ macros.input('surname', 'Επώνυμο', '', 'text', {'required': ''}) }}
{{ macros.input('telephone', 'Τηλέφωνο','', 'tel', {'required': ''}) }}
{{ macros.input('email', 'Email','', 'email', {'required': ''}) }}
{{ macros.select('branch', 'Ειδικότητα', branches, '', {'required': ''}) }}
{{ macros.select('branch_id', 'Ειδικότητα', branches, '', {'required': ''}) }}
{{ macros.select('position', 'Θέση', positions, '', {'multiple': '', 'required': ''}) }}
<input type="hidden" name="id" value="">
</div>
......
......@@ -57,6 +57,7 @@
evt.preventDefault();
this.modal.render(function (data) {
that.model.add(data);
that.$el.find('.no-records').remove();
});
return this;
},
......@@ -116,6 +117,8 @@
that.form.data('done')(response);
that.form.data('done', undefined);
that.hide();
}).fail(function (xhr, err) {
alert(xhr.statusText);
});
}
});
......
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