staff create/update/delete ready

parent c0263ac7
.phpintel
vendor
\ No newline at end of file
vendor
/nbproject/private/
\ No newline at end of file
......@@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "2b6ef5eafbeda796b77abd927e9e74b2",
"content-hash": "b76fa7640686792f43397a7ff0ded352",
"hash": "059041460fb8d23eee6eeb857572b920",
"content-hash": "bd78bc722c9d002c5e0c6c4a04df5ac3",
"packages": [
{
"name": "container-interop/container-interop",
......@@ -1183,6 +1183,62 @@
],
"time": "2016-01-12 23:27:48"
},
{
"name": "zendframework/zend-filter",
"version": "2.6.1",
"source": {
"type": "git",
"url": "https://github.com/zendframework/zend-filter.git",
"reference": "202014ee64e2aae23140a1719f6d362a602713ed"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/zendframework/zend-filter/zipball/202014ee64e2aae23140a1719f6d362a602713ed",
"reference": "202014ee64e2aae23140a1719f6d362a602713ed",
"shasum": ""
},
"require": {
"php": "^5.5 || ^7.0",
"zendframework/zend-stdlib": "^2.7 || ^3.0"
},
"require-dev": {
"fabpot/php-cs-fixer": "1.7.*",
"pear/archive_tar": "^1.4",
"phpunit/phpunit": "~4.0",
"zendframework/zend-crypt": "^2.6",
"zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3",
"zendframework/zend-uri": "^2.5"
},
"suggest": {
"zendframework/zend-crypt": "Zend\\Crypt component, for encryption filters",
"zendframework/zend-i18n": "Zend\\I18n component for filters depending on i18n functionality",
"zendframework/zend-servicemanager": "Zend\\ServiceManager component, for using the filter chain functionality",
"zendframework/zend-uri": "Zend\\Uri component, for the UriNormalize filter"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.6-dev",
"dev-develop": "2.7-dev"
}
},
"autoload": {
"psr-4": {
"Zend\\Filter\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"description": "provides a set of commonly needed data filters",
"homepage": "https://github.com/zendframework/zend-filter",
"keywords": [
"filter",
"zf2"
],
"time": "2016-02-08 18:02:37"
},
{
"name": "zendframework/zend-hydrator",
"version": "1.0.0",
......@@ -1239,27 +1295,80 @@
],
"time": "2015-09-17 14:06:43"
},
{
"name": "zendframework/zend-inputfilter",
"version": "2.5.5",
"source": {
"type": "git",
"url": "https://github.com/zendframework/zend-inputfilter.git",
"reference": "3208cddbb92df029230cde676a5c8e5a22b531c6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/zendframework/zend-inputfilter/zipball/3208cddbb92df029230cde676a5c8e5a22b531c6",
"reference": "3208cddbb92df029230cde676a5c8e5a22b531c6",
"shasum": ""
},
"require": {
"php": ">=5.5",
"zendframework/zend-filter": "~2.5",
"zendframework/zend-stdlib": "~2.5",
"zendframework/zend-validator": "^2.5.3"
},
"require-dev": {
"fabpot/php-cs-fixer": "1.7.*",
"phpunit/phpunit": "^4.5",
"zendframework/zend-i18n": "~2.5",
"zendframework/zend-servicemanager": "~2.5"
},
"suggest": {
"zendframework/zend-servicemanager": "To support plugin manager support"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.5-dev",
"dev-develop": "2.6-dev"
}
},
"autoload": {
"psr-4": {
"Zend\\InputFilter\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"homepage": "https://github.com/zendframework/zend-inputfilter",
"keywords": [
"inputfilter",
"zf2"
],
"time": "2015-09-03 22:31:38"
},
{
"name": "zendframework/zend-ldap",
"version": "2.5.1",
"version": "2.6.0",
"source": {
"type": "git",
"url": "https://github.com/zendframework/zend-ldap.git",
"reference": "c647a86224030543401634dbafd514074b49b2b6"
"reference": "920863c447f167f7f1e90f982bdc2532e7a8bf24"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/zendframework/zend-ldap/zipball/c647a86224030543401634dbafd514074b49b2b6",
"reference": "c647a86224030543401634dbafd514074b49b2b6",
"url": "https://api.github.com/repos/zendframework/zend-ldap/zipball/920863c447f167f7f1e90f982bdc2532e7a8bf24",
"reference": "920863c447f167f7f1e90f982bdc2532e7a8bf24",
"shasum": ""
},
"require": {
"ext-ldap": "*",
"php": ">=5.3.23",
"php": ">=5.5",
"zendframework/zend-stdlib": "~2.5"
},
"require-dev": {
"fabpot/php-cs-fixer": "1.7.*",
"php-mock/php-mock-phpunit": "~0.3",
"phpunit/phpunit": "~4.0",
"zendframework/zend-config": "~2.5",
"zendframework/zend-eventmanager": "~2.5"
......@@ -1289,7 +1398,7 @@
"ldap",
"zf2"
],
"time": "2015-06-03 15:32:02"
"time": "2016-02-11 15:17:45"
},
{
"name": "zendframework/zend-math",
......@@ -1447,6 +1556,72 @@
"zf2"
],
"time": "2015-10-15 15:57:32"
},
{
"name": "zendframework/zend-validator",
"version": "2.5.3",
"source": {
"type": "git",
"url": "https://github.com/zendframework/zend-validator.git",
"reference": "53e567a58c8952a03da0b8edf0f075303a5ac5d1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/zendframework/zend-validator/zipball/53e567a58c8952a03da0b8edf0f075303a5ac5d1",
"reference": "53e567a58c8952a03da0b8edf0f075303a5ac5d1",
"shasum": ""
},
"require": {
"php": ">=5.5",
"zendframework/zend-stdlib": "~2.5"
},
"require-dev": {
"fabpot/php-cs-fixer": "1.7.*",
"phpunit/phpunit": "~4.0",
"zendframework/zend-cache": "~2.5",
"zendframework/zend-config": "~2.5",
"zendframework/zend-db": "~2.5",
"zendframework/zend-filter": "~2.5",
"zendframework/zend-http": "~2.5",
"zendframework/zend-i18n": "~2.5",
"zendframework/zend-math": "~2.5",
"zendframework/zend-servicemanager": "~2.5",
"zendframework/zend-session": "~2.5",
"zendframework/zend-uri": "~2.5"
},
"suggest": {
"zendframework/zend-db": "Zend\\Db component",
"zendframework/zend-filter": "Zend\\Filter component, required by the Digits validator",
"zendframework/zend-i18n": "Zend\\I18n component to allow translation of validation error messages as well as to use the various Date validators",
"zendframework/zend-i18n-resources": "Translations of validator messages",
"zendframework/zend-math": "Zend\\Math component",
"zendframework/zend-servicemanager": "Zend\\ServiceManager component to allow using the ValidatorPluginManager and validator chains",
"zendframework/zend-session": "Zend\\Session component",
"zendframework/zend-uri": "Zend\\Uri component, required by the Uri and Sitemap\\Loc validators"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.5-dev",
"dev-develop": "2.6-dev"
}
},
"autoload": {
"psr-4": {
"Zend\\Validator\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"description": "provides a set of commonly needed validators",
"homepage": "https://github.com/zendframework/zend-validator",
"keywords": [
"validator",
"zf2"
],
"time": "2015-09-03 19:06:11"
}
],
"packages-dev": [
......@@ -1609,22 +1784,24 @@
},
{
"name": "phpspec/prophecy",
"version": "v1.5.0",
"version": "v1.6.0",
"source": {
"type": "git",
"url": "https://github.com/phpspec/prophecy.git",
"reference": "4745ded9307786b730d7a60df5cb5a6c43cf95f7"
"reference": "3c91bdf81797d725b14cb62906f9a4ce44235972"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpspec/prophecy/zipball/4745ded9307786b730d7a60df5cb5a6c43cf95f7",
"reference": "4745ded9307786b730d7a60df5cb5a6c43cf95f7",
"url": "https://api.github.com/repos/phpspec/prophecy/zipball/3c91bdf81797d725b14cb62906f9a4ce44235972",
"reference": "3c91bdf81797d725b14cb62906f9a4ce44235972",
"shasum": ""
},
"require": {
"doctrine/instantiator": "^1.0.2",
"php": "^5.3|^7.0",
"phpdocumentor/reflection-docblock": "~2.0",
"sebastian/comparator": "~1.1"
"sebastian/comparator": "~1.1",
"sebastian/recursion-context": "~1.0"
},
"require-dev": {
"phpspec/phpspec": "~2.0"
......@@ -1632,7 +1809,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4.x-dev"
"dev-master": "1.5.x-dev"
}
},
"autoload": {
......@@ -1665,7 +1842,7 @@
"spy",
"stub"
],
"time": "2015-08-13 10:07:40"
"time": "2016-02-15 07:46:21"
},
{
"name": "phpunit/php-code-coverage",
......@@ -1961,16 +2138,16 @@
},
{
"name": "phpunit/phpunit",
"version": "4.8.22",
"version": "4.8.23",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "dfb11aa5236376b4fc63853cf746af39fe780e72"
"reference": "6e351261f9cd33daf205a131a1ba61c6d33bd483"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/dfb11aa5236376b4fc63853cf746af39fe780e72",
"reference": "dfb11aa5236376b4fc63853cf746af39fe780e72",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/6e351261f9cd33daf205a131a1ba61c6d33bd483",
"reference": "6e351261f9cd33daf205a131a1ba61c6d33bd483",
"shasum": ""
},
"require": {
......@@ -2029,7 +2206,7 @@
"testing",
"xunit"
],
"time": "2016-02-02 09:01:21"
"time": "2016-02-11 14:56:33"
},
{
"name": "phpunit/phpunit-mock-objects",
......
......@@ -14,6 +14,7 @@ return [
['/school', ['school'], ['get']],
['/school/labs', ['school'], ['get']],
['/school/staff', ['school'], ['get', 'post']],
['/school/staff/{id:[1-9][0-9]*}', ['school'], ['delete']],
['/school/assets', ['school'], ['get']],
],
],
......
......@@ -28,7 +28,7 @@ return function (Slim\App $app) {
$container['settings']['db']['user'],
$container['settings']['db']['pass']
);
RedBeanPHP\R::freeze();
// RedBeanPHP\R::freeze();
$container['view'] = function ($c) {
$settings = $c['settings'];
......
......@@ -25,16 +25,22 @@ return function (Slim\App $app) {
);
};
$container[GrEduLabs\Schools\Action\Staff::class] = function ($c) {
return new GrEduLabs\Schools\Action\Staff(
$container[GrEduLabs\Schools\Action\Staff\ListAll::class] = function ($c) {
return new GrEduLabs\Schools\Action\Staff\ListAll(
$c->get('view'),
$c->get('staffservice')
$c->get(GrEduLabs\Schools\Service\StaffService::class)
);
};
$container[GrEduLabs\Schools\Action\StaffCreate::class] = function ($c) {
return new GrEduLabs\Schools\Action\StaffCreate(
$c->get('staffservice')
$container[GrEduLabs\Schools\Action\Staff\PersistTeacher::class] = function ($c) {
return new GrEduLabs\Schools\Action\Staff\PersistTeacher(
$c->get(GrEduLabs\Schools\Service\StaffService::class)
);
};
$container[GrEduLabs\Schools\Action\Staff\DeleteTeacher::class] = function ($c) {
return new GrEduLabs\Schools\Action\Staff\DeleteTeacher(
$c->get(GrEduLabs\Schools\Service\StaffService::class)
);
};
......@@ -58,9 +64,17 @@ return function (Slim\App $app) {
return new GrEduLabs\Schools\Service\SchoolService();
};
$container['staffservice'] = function ($c) {
return new GrEduLabs\Schools\Service\StaffService(
new GrEduLabs\Schools\Filter\Teacher()
$container[GrEduLabs\Schools\InputFilter\Teacher::class] = function ($c) {
return new GrEduLabs\Schools\InputFilter\Teacher();
};
$container[GrEduLabs\Schools\Service\StaffService::class] = function ($c) {
return new GrEduLabs\Schools\Service\StaffService();
};
$container[GrEduLabs\Schools\Middleware\InputFilterTeacher::class] = function ($c) {
return new GrEduLabs\Schools\Middleware\InputFilterTeacher(
$c->get(GrEduLabs\Schools\InputFilter\Teacher::class)
);
};
......@@ -89,8 +103,13 @@ return function (Slim\App $app) {
$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('/staff', GrEduLabs\Schools\Action\Staff\ListAll::class)->setName('school.staff');
$this->post('/staff', GrEduLabs\Schools\Action\Staff\PersistTeacher::class)
->add(GrEduLabs\Schools\Middleware\InputFilterTeacher::class)
->setName('school.staffcreate');
$this->delete('/staff/{id:[1-9][0-9]*}', GrEduLabs\Schools\Action\Staff\DeleteTeacher::class)
->setName('school.staffdelete');
$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');
......
......@@ -178,6 +178,26 @@ INSERT INTO `schooltype` VALUES (1,'ΝΗΠΙΑΓΩΓΕΙΟ',1),(2,'ΔΗΜΟΤΙ
/*!40000 ALTER TABLE `schooltype` ENABLE KEYS */;
UNLOCK TABLES;
DROP TABLE IF EXISTS `teacher`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `teacher` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`school_id` int(11) unsigned NOT NULL,
`name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`surname` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`telephone` int(11) unsigned NOT NULL,
`email` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`branch_id` int(11) unsigned NOT NULL,
`is_principle` tinyint(1) unsigned DEFAULT '0',
`is_responsible` tinyint(1) unsigned DEFAULT '0',
PRIMARY KEY (`id`),
KEY `index_foreignkey_teacher_school` (`school_id`),
KEY `index_foreignkey_teacher_branch` (`branch_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!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 */;
......
......@@ -2,100 +2,112 @@
'use strict';
var Staff,
Employee,
EmployeeView,
Teacher,
StaffRow,
StaffView,
ModalView,
employeeTemplate;
TeacherView,
teacherTemplate;
Employee = Backbone.Model.extend({ idAttribute: 'id' });
Teacher = Backbone.Model.extend({ idAttribute: 'id' });
Staff = Backbone.Collection.extend({
model: Employee,
model: Teacher,
comparator: 'surname'
});
EmployeeView = Backbone.View.extend({
StaffRow = Backbone.View.extend({
tagName: 'tr',
template: (function () {
if (typeof employeeTemplate === 'undefined') {
employeeTemplate = _.template($('#employee-row').html());
if (typeof teacherTemplate === 'undefined') {
teacherTemplate = _.template($('#teacher-row').html());
}
return employeeTemplate;
return teacherTemplate;
}()),
initialize: function () {
this.model.on('change', this.render, this);
this.model.on('remove', this.remove, this);
},
render: function () {
this.$el.html(this.template({ employee: this.model.attributes }));
this.$el.html(this.template({ teacher: this.model.attributes }));
this.$el.attr('data-id', this.model.get('id'));
return this;
},
remove: function () {
this.$el.remove();
}
});
StaffView = Backbone.View.extend({
el: '#school',
modal: null,
teacherView: null,
events: {
'click .btn-add-employee': 'addEmployee',
'click .btn-add-teacher': 'addEmployee',
'click tbody tr': 'editEmployee'
},
initialize: function () {
var that = this;
this.modal = new ModalView();
this.teacherView = new TeacherView({model: this.model});
_.each(this.$el.find('tbody tr'), function (tr) {
var data = $(tr).data('employee'),
employee = new Employee(data);
that.model.add(employee);
new EmployeeView({ model: employee, el: tr });
$(tr).attr('data-employee', null);
var data = $(tr).data('teacher'),
teacher = new Teacher(data);
that.model.add(teacher);
new StaffRow({ model: teacher, el: tr });
$(tr).attr('data-teacher', null);
});
this.model.on('add', this.renderEmployee, this);
},
addEmployee: function (evt) {
var that = this;
evt.preventDefault();
this.modal.render(function (data) {
that.model.add(data);
that.$el.find('.no-records').remove();
});
this.teacherView.render();
return this;
},
editEmployee: function (evt) {
var employee = this.model.get($(evt.target).closest('tr').data('id'));
var teacherId;
if ($(evt.target).is('a')) return;
if (!employee) return;
this.modal.render(function (data) {
employee.set(data);
}, employee.attributes);
teacherId = $(evt.target).closest('tr').data('id');
this.teacherView.render(teacherId);
return this;
},
renderEmployee: function (employee) {
this.$el.find('tbody').append(new EmployeeView({
model: employee
renderEmployee: function (teacher) {
this.$el.find('tbody').append(new StaffRow({
model: teacher
}).render().el);
return this;
}
});
ModalView = Backbone.View.extend({
el: '#employee-form-modal',
TeacherView = Backbone.View.extend({
el: '#teacher-form-modal',
form: null,
teacher: null,
url: null,
events: {
'submit form': 'submit',
'submit form': 'persistTeacher',
'click button.remove': 'removeTeacher',
},
initialize: function () {
this.form = this.$el.find('form');
this.url = this.form.data('url');
},
render: function (done, employee) {
this.form.data('done', done);
render: function (teacherId) {
var teacherAttributes;
this.form[0].reset();
this.form.find('input[type="hidden"]').val('');
employee = employee || {};
if (!teacherId) {
this.$el.find('.modal-footer button.remove').addClass('hidden');
} else {
this.$el.find('.modal-footer button.remove').removeClass('hidden');
}
this.teacher = teacherId && this.model.get(teacherId) || null;
teacherAttributes = this.teacher && this.teacher.attributes || {};
_.each(this.form[0].elements, function (element) {
var element = $(element),
name = element.attr('name');
element.val(employee[name] || '');
if ('checkbox' === element.attr('type')) {
element.prop('checked', parseInt(teacherAttributes[name], 10));
} else {
element.val(teacherAttributes[name] || '');
}
});
this.show();
},
......@@ -105,21 +117,40 @@
hide: function () {
this.$el.modal('hide');
},
submit: function (evt) {
persistTeacher: function (evt) {
var data = _.reduce(this.form.serializeArray(), function (hash, pair) {
hash[pair.name] = pair.value;
return hash;
}, {});
var that = this;
evt.preventDefault();
$.post("", data).
$.post(this.url, data).
done(function(response){
that.form.data('done'