staff create/update/delete ready

parent c0263ac7
.phpintel .phpintel
vendor vendor
\ No newline at end of file /nbproject/private/
\ No newline at end of file
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"hash": "2b6ef5eafbeda796b77abd927e9e74b2", "hash": "059041460fb8d23eee6eeb857572b920",
"content-hash": "b76fa7640686792f43397a7ff0ded352", "content-hash": "bd78bc722c9d002c5e0c6c4a04df5ac3",
"packages": [ "packages": [
{ {
"name": "container-interop/container-interop", "name": "container-interop/container-interop",
...@@ -1183,6 +1183,62 @@ ...@@ -1183,6 +1183,62 @@
], ],
"time": "2016-01-12 23:27:48" "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", "name": "zendframework/zend-hydrator",
"version": "1.0.0", "version": "1.0.0",
...@@ -1239,27 +1295,80 @@ ...@@ -1239,27 +1295,80 @@
], ],
"time": "2015-09-17 14:06:43" "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", "name": "zendframework/zend-ldap",
"version": "2.5.1", "version": "2.6.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/zendframework/zend-ldap.git", "url": "https://github.com/zendframework/zend-ldap.git",
"reference": "c647a86224030543401634dbafd514074b49b2b6" "reference": "920863c447f167f7f1e90f982bdc2532e7a8bf24"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/zendframework/zend-ldap/zipball/c647a86224030543401634dbafd514074b49b2b6", "url": "https://api.github.com/repos/zendframework/zend-ldap/zipball/920863c447f167f7f1e90f982bdc2532e7a8bf24",
"reference": "c647a86224030543401634dbafd514074b49b2b6", "reference": "920863c447f167f7f1e90f982bdc2532e7a8bf24",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"ext-ldap": "*", "ext-ldap": "*",
"php": ">=5.3.23", "php": ">=5.5",
"zendframework/zend-stdlib": "~2.5" "zendframework/zend-stdlib": "~2.5"
}, },
"require-dev": { "require-dev": {
"fabpot/php-cs-fixer": "1.7.*", "fabpot/php-cs-fixer": "1.7.*",
"php-mock/php-mock-phpunit": "~0.3",
"phpunit/phpunit": "~4.0", "phpunit/phpunit": "~4.0",
"zendframework/zend-config": "~2.5", "zendframework/zend-config": "~2.5",
"zendframework/zend-eventmanager": "~2.5" "zendframework/zend-eventmanager": "~2.5"
...@@ -1289,7 +1398,7 @@ ...@@ -1289,7 +1398,7 @@
"ldap", "ldap",
"zf2" "zf2"
], ],
"time": "2015-06-03 15:32:02" "time": "2016-02-11 15:17:45"
}, },
{ {
"name": "zendframework/zend-math", "name": "zendframework/zend-math",
...@@ -1447,6 +1556,72 @@ ...@@ -1447,6 +1556,72 @@
"zf2" "zf2"
], ],
"time": "2015-10-15 15:57:32" "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": [ "packages-dev": [
...@@ -1609,22 +1784,24 @@ ...@@ -1609,22 +1784,24 @@
}, },
{ {
"name": "phpspec/prophecy", "name": "phpspec/prophecy",
"version": "v1.5.0", "version": "v1.6.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpspec/prophecy.git", "url": "https://github.com/phpspec/prophecy.git",
"reference": "4745ded9307786b730d7a60df5cb5a6c43cf95f7" "reference": "3c91bdf81797d725b14cb62906f9a4ce44235972"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpspec/prophecy/zipball/4745ded9307786b730d7a60df5cb5a6c43cf95f7", "url": "https://api.github.com/repos/phpspec/prophecy/zipball/3c91bdf81797d725b14cb62906f9a4ce44235972",
"reference": "4745ded9307786b730d7a60df5cb5a6c43cf95f7", "reference": "3c91bdf81797d725b14cb62906f9a4ce44235972",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"doctrine/instantiator": "^1.0.2", "doctrine/instantiator": "^1.0.2",
"php": "^5.3|^7.0",
"phpdocumentor/reflection-docblock": "~2.0", "phpdocumentor/reflection-docblock": "~2.0",
"sebastian/comparator": "~1.1" "sebastian/comparator": "~1.1",
"sebastian/recursion-context": "~1.0"
}, },
"require-dev": { "require-dev": {
"phpspec/phpspec": "~2.0" "phpspec/phpspec": "~2.0"
...@@ -1632,7 +1809,7 @@ ...@@ -1632,7 +1809,7 @@
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "1.4.x-dev" "dev-master": "1.5.x-dev"
} }
}, },
"autoload": { "autoload": {
...@@ -1665,7 +1842,7 @@ ...@@ -1665,7 +1842,7 @@
"spy", "spy",
"stub" "stub"
], ],
"time": "2015-08-13 10:07:40" "time": "2016-02-15 07:46:21"
}, },
{ {
"name": "phpunit/php-code-coverage", "name": "phpunit/php-code-coverage",
...@@ -1961,16 +2138,16 @@ ...@@ -1961,16 +2138,16 @@
}, },
{ {
"name": "phpunit/phpunit", "name": "phpunit/phpunit",
"version": "4.8.22", "version": "4.8.23",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git", "url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "dfb11aa5236376b4fc63853cf746af39fe780e72" "reference": "6e351261f9cd33daf205a131a1ba61c6d33bd483"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/dfb11aa5236376b4fc63853cf746af39fe780e72", "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/6e351261f9cd33daf205a131a1ba61c6d33bd483",
"reference": "dfb11aa5236376b4fc63853cf746af39fe780e72", "reference": "6e351261f9cd33daf205a131a1ba61c6d33bd483",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
...@@ -2029,7 +2206,7 @@ ...@@ -2029,7 +2206,7 @@
"testing", "testing",
"xunit" "xunit"
], ],
"time": "2016-02-02 09:01:21" "time": "2016-02-11 14:56:33"
}, },
{ {
"name": "phpunit/phpunit-mock-objects", "name": "phpunit/phpunit-mock-objects",
......
...@@ -14,6 +14,7 @@ return [ ...@@ -14,6 +14,7 @@ return [
['/school', ['school'], ['get']], ['/school', ['school'], ['get']],
['/school/labs', ['school'], ['get']], ['/school/labs', ['school'], ['get']],
['/school/staff', ['school'], ['get', 'post']], ['/school/staff', ['school'], ['get', 'post']],
['/school/staff/{id:[1-9][0-9]*}', ['school'], ['delete']],
['/school/assets', ['school'], ['get']], ['/school/assets', ['school'], ['get']],
], ],
], ],
......
...@@ -28,7 +28,7 @@ return function (Slim\App $app) { ...@@ -28,7 +28,7 @@ return function (Slim\App $app) {
$container['settings']['db']['user'], $container['settings']['db']['user'],
$container['settings']['db']['pass'] $container['settings']['db']['pass']
); );
RedBeanPHP\R::freeze(); // RedBeanPHP\R::freeze();
$container['view'] = function ($c) { $container['view'] = function ($c) {
$settings = $c['settings']; $settings = $c['settings'];
......
...@@ -25,16 +25,22 @@ return function (Slim\App $app) { ...@@ -25,16 +25,22 @@ return function (Slim\App $app) {
); );
}; };
$container[GrEduLabs\Schools\Action\Staff::class] = function ($c) { $container[GrEduLabs\Schools\Action\Staff\ListAll::class] = function ($c) {
return new GrEduLabs\Schools\Action\Staff( return new GrEduLabs\Schools\Action\Staff\ListAll(
$c->get('view'), $c->get('view'),
$c->get('staffservice') $c->get(GrEduLabs\Schools\Service\StaffService::class)
); );
}; };
$container[GrEduLabs\Schools\Action\StaffCreate::class] = function ($c) { $container[GrEduLabs\Schools\Action\Staff\PersistTeacher::class] = function ($c) {
return new GrEduLabs\Schools\Action\StaffCreate( return new GrEduLabs\Schools\Action\Staff\PersistTeacher(
$c->get('staffservice') $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) { ...@@ -58,9 +64,17 @@ return function (Slim\App $app) {
return new GrEduLabs\Schools\Service\SchoolService(); return new GrEduLabs\Schools\Service\SchoolService();
}; };
$container['staffservice'] = function ($c) { $container[GrEduLabs\Schools\InputFilter\Teacher::class] = function ($c) {
return new GrEduLabs\Schools\Service\StaffService( return new GrEduLabs\Schools\InputFilter\Teacher();
new GrEduLabs\Schools\Filter\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) { ...@@ -89,8 +103,13 @@ return function (Slim\App $app) {
$app->group('/school', function () { $app->group('/school', function () {
$this->get('', GrEduLabs\Schools\Action\Index::class)->setName('school'); $this->get('', GrEduLabs\Schools\Action\Index::class)->setName('school');
$this->get('/staff', GrEduLabs\Schools\Action\Staff::class)->setName('school.staff'); $this->get('/staff', GrEduLabs\Schools\Action\Staff\ListAll::class)->setName('school.staff');
$this->post('/staff', GrEduLabs\Schools\Action\StaffCreate::class)->setName('school.staffcreate'); $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->get('/labs', GrEduLabs\Schools\Action\Labs::class)->setName('school.labs');
$this->post('/labs', GrEduLabs\Schools\Action\LabCreate::class)->setName('school.labcreate'); $this->post('/labs', GrEduLabs\Schools\Action\LabCreate::class)->setName('school.labcreate');
$this->get('/assets', GrEduLabs\Schools\Action\Assets::class)->setName('school.assets'); $this->get('/assets', GrEduLabs\Schools\Action\Assets::class)->setName('school.assets');
......
...@@ -178,6 +178,26 @@ INSERT INTO `schooltype` VALUES (1,'ΝΗΠΙΑΓΩΓΕΙΟ',1),(2,'ΔΗΜΟΤΙ ...@@ -178,6 +178,26 @@ INSERT INTO `schooltype` VALUES (1,'ΝΗΠΙΑΓΩΓΕΙΟ',1),(2,'ΔΗΜΟΤΙ
/*!40000 ALTER TABLE `schooltype` ENABLE KEYS */; /*!40000 ALTER TABLE `schooltype` ENABLE KEYS */;
UNLOCK TABLES; 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 */; /*!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 */;
......
...@@ -2,100 +2,112 @@ ...@@ -2,100 +2,112 @@
'use strict'; 'use strict';
var Staff, var Staff,
Employee, Teacher,
EmployeeView, StaffRow,
StaffView, StaffView,
ModalView, TeacherView,
employeeTemplate; teacherTemplate;
Employee = Backbone.Model.extend({ idAttribute: 'id' }); Teacher = Backbone.Model.extend({ idAttribute: 'id' });
Staff = Backbone.Collection.extend({ Staff = Backbone.Collection.extend({
model: Employee, model: Teacher,
comparator: 'surname' comparator: 'surname'
}); });
EmployeeView = Backbone.View.extend({ StaffRow = Backbone.View.extend({
tagName: 'tr', tagName: 'tr',
template: (function () { template: (function () {
if (typeof employeeTemplate === 'undefined') { if (typeof teacherTemplate === 'undefined') {
employeeTemplate = _.template($('#employee-row').html()); teacherTemplate = _.template($('#teacher-row').html());
} }
return employeeTemplate; return teacherTemplate;
}()), }()),
initialize: function () { initialize: function () {
this.model.on('change', this.render, this); this.model.on('change', this.render, this);
this.model.on('remove', this.remove, this);
}, },
render: function () { 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')); this.$el.attr('data-id', this.model.get('id'));
return this; return this;
},
remove: function () {
this.$el.remove();
} }
}); });
StaffView = Backbone.View.extend({ StaffView = Backbone.View.extend({
el: '#school', el: '#school',
modal: null, teacherView: null,
events: { events: {
'click .btn-add-employee': 'addEmployee', 'click .btn-add-teacher': 'addEmployee',
'click tbody tr': 'editEmployee' 'click tbody tr': 'editEmployee'
}, },
initialize: function () { initialize: function () {
var that = this; var that = this;
this.modal = new ModalView(); this.teacherView = new TeacherView({model: this.model});
_.each(this.$el.find('tbody tr'), function (tr) { _.each(this.$el.find('tbody tr'), function (tr) {
var data = $(tr).data('employee'), var data = $(tr).data('teacher'),
employee = new Employee(data); teacher = new Teacher(data);
that.model.add(employee); that.model.add(teacher);
new EmployeeView({ model: employee, el: tr }); new StaffRow({ model: teacher, el: tr });
$(tr).attr('data-employee', null);