Commit c0263ac7 authored by kanellov's avatar kanellov

implementing staff ui

parent 29fb0a3d
......@@ -28,6 +28,7 @@ return function (Slim\App $app) {
$container['settings']['db']['user'],
$container['settings']['db']['pass']
);
RedBeanPHP\R::freeze();
$container['view'] = function ($c) {
$settings = $c['settings'];
......
......@@ -60,7 +60,7 @@ return function (Slim\App $app) {
$container['staffservice'] = function ($c) {
return new GrEduLabs\Schools\Service\StaffService(
$c->get('schoolservice')
new GrEduLabs\Schools\Filter\Teacher()
);
};
......
......@@ -29,16 +29,7 @@ class Staff
$staff = $this->staffservice->getTeachersBySchoolId(1);
return $this->view->render($res, 'schools/staff.twig', [
'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' => 'Υπεύθυνος εργαστηρίου'],
],
'staff' => $staff,
'branches' => array_map(function ($branch) {
return ['value' => $branch['id'], 'label' => $branch['name']];
}, $this->staffservice->getBranches()),
......
<?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\Filter;
use InvalidArgumentException;
class Teacher
{
// private static $required = [
// 'school_id',
// 'branch_id',
// 'name',
// 'surname',
// 'email',
// 'telephone',
// ];
// private static $optional = [
// 'is_principle',
// 'is_responsible',
// ];
// private static $messageTemplates = [
// 'school_id' => 'Δεν ορίστηκε το σχολείο',
// 'branch_id' => 'Δεν ορίστηκε η ειδικότητα',
// 'name' => 'Δεν ορίστηκε το όνομα',
// 'surname' => 'Δεν ορίστηκε το επώνυμο',
// 'email'=> 'Δεν ορίστηκε το email',
// 'telephone' => 'Δεν ορίστηκε το τηλέφωνο',
// ];
private static $filter = [
'school_id' => [
'filter' => FILTER_VALIDATE_INT,
'flags' => FILTER_REQUIRE_SCALAR,
],
'branch_id' => [
'filter' => FILTER_VALIDATE_INT,
'flags' => FILTER_REQUIRE_SCALAR,
],
'name' => [
'filter' => FILTER_SANITIZE_STRING,
'flags' => FILTER_REQUIRE_SCALAR,
],
'surname' => [
'filter' => FILTER_SANITIZE_STRING,
'flags' => FILTER_REQUIRE_SCALAR,
],
'email' => FILTER_VALIDATE_EMAIL,
'telephone' => FILTER_SANITIZE_NUMBER_INT,
'is_principle' => [
'filter' => FILTER_VALIDATE_BOOLEAN,
],
'is_responsible' => [
'filter' => FILTER_VALIDATE_BOOLEAN,
],
];
public function __invoke(array $data, $create = true)
{
var_dump(filter_var_array($data, self::$filter, $create));
die();
// $messages = [];
// $fields = array_merge(self::$required, self::$optional);
// $data = array_intersect_key($data, array_flip($fields));
// $filtered = array_map('trim', $data);
// foreach (self::$required as $required) {
// if (!isset($data[$required])|| empty($data[$required])) {
// $messages[$required][] = self::$messageTemplates[$required];
// }
// }
// if (filter_input_array(type))
// var_dump($messages);
// die();
}
}
\ No newline at end of file
......@@ -13,14 +13,18 @@ use RedBeanPHP\R;
class StaffService implements StaffServiceInterface
{
protected $schoolService;
public function __construct(SchoolServiceInterface $schoolService)
private $filter;
public function __construct(callable $filter)
{
$this->schoolService = $schoolService;
$this->filter = $filter;
}
public function createTeacher(array $data)
{
$data = call_user_func($this->filter, $data, true);
var_dump($data);
die();
unset($data['id']);
$teacher = R::dispense('teacher');
$required = ['school_id', 'name','email', 'surname', 'telephone',
......@@ -40,34 +44,52 @@ class StaffService implements StaffServiceInterface
public function updateTeacher(array $data, $id)
{
$teacher = R::load('teacher', $id);
foreach ($data as $key => $value) {
$teacher[$key] = $value;
}
$id = R::store($teacher);
try {
$teacher = R::load('teacher', $id);
foreach ($data as $key => $value) {
$teacher[$key] = $value;
}
$id = R::store($teacher);
return $id;
return $id;
} catch (\Exception $e) {
}
}
public function getTeacherById($id)
{
$teacher = R::load('teacher', $id);
return $teacher;
return $this->export($teacher);
}
public function getTeachersBySchoolId($id)
{
$school = $this->schoolService->getSchool($id);
$teachers = $school->ownTeacher;
$teachers = R::findAll('teacher', 'school_id = ?', [$id]);
return $teachers;
return array_map([$this, 'export'], $teachers);
}
public function getBranches()
{
return array_map(function ($branch) {
return $branch->export();
}, R::find('branch', 'ORDER BY name ASC'));
}, R::findAll('branch', 'ORDER BY name ASC'));
}
private function export($teacherBean)
{
$position = [];
if ($teacherBean->is_principle) {
$position[] = 'Διευθυντής';
}
if ($teacherBean->is_responsible) {
$position[] = 'Υπεύθυνος εργαστηρίου';
}
return array_merge($teacherBean->export(), [
'branch' => $teacherBean->branch->name,
'position' => implode(', ', $position),
]);
}
}
......@@ -14,6 +14,23 @@
</div>
{% endmacro %}
{% macro checkbox(name, label, checked, attributes) %}
<div class="form-group">
<div class="col-xs-12 col-sm-12 col-md-9 col-md-offset-3">
<div class="checkbox">
<label>
<input type="checkbox" name="{{ name}}" id="el-{{ name }}"
{% if checked %} checked{% endif %}
{% for attr_name, attr_value in attributes|default({}) %}
{{ attr_name }}="{{ attr_value }}"
{% endfor %}>
{{ label|raw }}
</label>
</div>
</div>
</div>
{% endmacro %}
{% macro file(name, label, value, attributes) %}
<div class="form-group">
<label class="control-label hidden-xs hidden-sm col-md-3" for="el-{{ name }}">{{ label|raw }}</label>
......
......@@ -39,12 +39,12 @@
<a href="mailto:{{ employee.email }}">{{ employee.email }}</a>
</td>
<td class="branch">{{ employee.branch }}</td>
<td class="positionLabel">{{ employee.positionLabel }}</td>
<td class="position">{{ employee.position }}</td>
</tr>
{% else %}
<tr>
<td colspan="6" class="text-center text-muted no-records">
Δεν έχει καταχωρηθεί προσωπικό.
Δεν έχουν καταχωρηθεί εκπαιδευτικοί.
</td>
</tr>
{% endfor %}
......@@ -72,7 +72,8 @@
{{ macros.input('telephone', 'Τηλέφωνο','', 'tel', {'required': ''}) }}
{{ macros.input('email', 'Email','', 'email', {'required': ''}) }}
{{ macros.select('branch_id', 'Ειδικότητα', branches, '', {'required': ''}) }}
{{ macros.select('position', 'Θέση', positions, '', {'multiple': '', 'required': ''}) }}
{{ macros.checkbox('is_principle', 'Διευθυντής') }}
{{ macros.checkbox('is_responsible', 'Υπεύθυνος εργαστηρίου') }}
<input type="hidden" name="id" value="">
</div>
<div class="modal-footer">
......
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