API support, serving JSON formatted data

Paged api endpoints accept "page" and "pagesize" params.
New config file config/settings/open_data.global.php
ACL is dynamically manipulated by the module.
The "index" endpoint provides links to available endpoints.
Documentation is provided in swagger.
Add doc links to open data page itminedu/gredu_labs#14
parent 9a4e9ac8
...@@ -6,21 +6,20 @@ ...@@ -6,21 +6,20 @@
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/) * @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 * @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/ */
return [ return [
'acl' => [ 'acl' => [
'default_role' => 'guest', 'default_role' => 'guest',
'roles' => [ 'roles' => [
'guest' => [], 'guest' => [],
'user' => [], 'user' => [],
'school' => ['user'], 'school' => ['user'],
'admin' => ['user'], 'admin' => ['user'],
], ],
'resoures' => [], 'resoures' => [],
'guards' => [ 'guards' => [
'resources' => [], 'resources' => [],
'callables' => [], 'callables' => [],
'routes' => [ 'routes' => [
['/', ['guest', 'user'], ['get']], ['/', ['guest', 'user'], ['get']],
['/about', ['guest', 'user'], ['get']], ['/about', ['guest', 'user'], ['get']],
['/school', ['school'], ['get']], ['/school', ['school'], ['get']],
......
<?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 [
'open_data' => [
'pagesize' => 20, // default page size
'maxpagesize' => 200, // maximum page size
],
];
...@@ -43,6 +43,7 @@ return function (App $app) { ...@@ -43,6 +43,7 @@ return function (App $app) {
'ID', 'ID',
'Κωδικός σχολείου', 'Κωδικός σχολείου',
'Ονομασία σχολείου', 'Ονομασία σχολείου',
'Περιφερειακή διεύθυνση εκπαίδευσης',
'Ονομασία χώρου', 'Ονομασία χώρου',
'Τύπος χώρου', 'Τύπος χώρου',
'Ειδικότητα υπευθύνου', 'Ειδικότητα υπευθύνου',
...@@ -65,6 +66,7 @@ return function (App $app) { ...@@ -65,6 +66,7 @@ return function (App $app) {
'Τύπος χώρου', 'Τύπος χώρου',
'Κωδικός σχολείου', 'Κωδικός σχολείου',
'Ονομασία σχολείου', 'Ονομασία σχολείου',
'Περιφερειακή διεύθυνση εκπαίδευσης',
'Σχόλια - Παρατηρήσεις', 'Σχόλια - Παρατηρήσεις',
], ],
], ],
...@@ -74,6 +76,7 @@ return function (App $app) { ...@@ -74,6 +76,7 @@ return function (App $app) {
'Τύπος', 'Τύπος',
'Κωδικός σχολείου', 'Κωδικός σχολείου',
'Ονομασία σχολείου', 'Ονομασία σχολείου',
'Περιφερειακή διεύθυνση εκπαίδευσης',
'ID χώρου', 'ID χώρου',
'Τύπος χώρου', 'Τύπος χώρου',
'Ονομασία', 'Ονομασία',
...@@ -87,6 +90,7 @@ return function (App $app) { ...@@ -87,6 +90,7 @@ return function (App $app) {
'ID', 'ID',
'Κωδικός σχολείου', 'Κωδικός σχολείου',
'Ονομασία σχολείου', 'Ονομασία σχολείου',
'Περιφερειακή διεύθυνση εκπαίδευσης',
'Ημερομηνία υποβολής', 'Ημερομηνία υποβολής',
'Σχόλια - Παρατηρήσεις', 'Σχόλια - Παρατηρήσεις',
], ],
...@@ -98,6 +102,7 @@ return function (App $app) { ...@@ -98,6 +102,7 @@ return function (App $app) {
'ID', 'ID',
'Κωδικός σχολείου', 'Κωδικός σχολείου',
'Ονομασία σχολείου', 'Ονομασία σχολείου',
'Περιφερειακή διεύθυνση εκπαίδευσης',
'Ημερομηνία υποβολής', 'Ημερομηνία υποβολής',
'Σχόλια - Παρατηρήσεις', 'Σχόλια - Παρατηρήσεις',
], ],
...@@ -110,6 +115,7 @@ return function (App $app) { ...@@ -110,6 +115,7 @@ return function (App $app) {
'ID', 'ID',
'Κωδικός σχολείου', 'Κωδικός σχολείου',
'Ονομασία σχολείου', 'Ονομασία σχολείου',
'Περιφερειακή διεύθυνση εκπαίδευσης',
'Ημερομηνία υποβολής', 'Ημερομηνία υποβολής',
'ID χώρου', 'ID χώρου',
'Τύπος χώρου', 'Τύπος χώρου',
...@@ -125,9 +131,14 @@ return function (App $app) { ...@@ -125,9 +131,14 @@ return function (App $app) {
'ID', 'ID',
'Κωδικός σχολείου', 'Κωδικός σχολείου',
'Ονομασία σχολείου', 'Ονομασία σχολείου',
'Περιφερειακή διεύθυνση εκπαίδευσης',
'Ημερομηνία υποβολής',
'ID χώρου',
'Τύπος χώρου',
'Νέος χώρος',
'Είδος', 'Είδος',
'Πλήθος Υπαρχόντων που λειτουργούν',
'Πλήθος Αιτουμένων', 'Πλήθος Αιτουμένων',
'Πλήθος Υπαρχόντων που λειτουργούν',
'Αιτιολογία χρήσης', 'Αιτιολογία χρήσης',
], ],
], ],
...@@ -198,6 +209,7 @@ return function (App $app) { ...@@ -198,6 +209,7 @@ return function (App $app) {
$sql = 'SELECT lab.id AS id, ' $sql = 'SELECT lab.id AS id, '
. ' school.registry_no AS school_registry_no, ' . ' school.registry_no AS school_registry_no, '
. ' school.name AS school_name, ' . ' school.name AS school_name, '
. ' regioneduadmin.name AS region_edu_admin, '
. ' TRIM(lab.name) AS name, ' . ' TRIM(lab.name) AS name, '
. ' TRIM(labtype.name) AS type, ' . ' TRIM(labtype.name) AS type, '
. ' branch.name AS responsible_branch, ' . ' branch.name AS responsible_branch, '
...@@ -211,6 +223,8 @@ return function (App $app) { ...@@ -211,6 +223,8 @@ return function (App $app) {
. ' FROM lab ' . ' FROM lab '
. ' LEFT JOIN labtype ON lab.labtype_id = labtype.id ' . ' LEFT JOIN labtype ON lab.labtype_id = labtype.id '
. ' LEFT JOIN school ON lab.school_id = school.id ' . ' LEFT JOIN school ON lab.school_id = school.id '
. ' LEFT JOIN eduadmin ON school.eduadmin_id = eduadmin.id '
. ' LEFT JOIN regioneduadmin ON eduadmin.regioneduadmin_id = regioneduadmin.id '
. ' LEFT JOIN lab_lesson ON lab_lesson.lab_id = lab.id ' . ' LEFT JOIN lab_lesson ON lab_lesson.lab_id = lab.id '
. ' LEFT JOIN lesson ON lab_lesson.lesson_id = lesson.id ' . ' LEFT JOIN lesson ON lab_lesson.lesson_id = lesson.id '
. ' LEFT JOIN teacher ON lab.responsible_id = teacher.id ' . ' LEFT JOIN teacher ON lab.responsible_id = teacher.id '
...@@ -234,10 +248,13 @@ return function (App $app) { ...@@ -234,10 +248,13 @@ return function (App $app) {
. ' TRIM(labtype.name) AS lab_type, ' . ' TRIM(labtype.name) AS lab_type, '
. ' school.registry_no AS school_registry_no, ' . ' school.registry_no AS school_registry_no, '
. ' school.name AS school_name, ' . ' school.name AS school_name, '
. ' regioneduadmin.name AS region_edu_admin, '
. ' schoolasset.comments AS comments ' . ' schoolasset.comments AS comments '
. ' FROM schoolasset ' . ' FROM schoolasset '
. ' LEFT JOIN itemcategory ON schoolasset.itemcategory_id = itemcategory.id ' . ' LEFT JOIN itemcategory ON schoolasset.itemcategory_id = itemcategory.id '
. ' LEFT JOIN school ON schoolasset.school_id = school.id ' . ' LEFT JOIN school ON schoolasset.school_id = school.id '
. ' LEFT JOIN eduadmin ON school.eduadmin_id = eduadmin.id '
. ' LEFT JOIN regioneduadmin ON eduadmin.regioneduadmin_id = regioneduadmin.id '
. ' LEFT JOIN lab ON schoolasset.lab_id = lab.id ' . ' LEFT JOIN lab ON schoolasset.lab_id = lab.id '
. ' LEFT JOIN labtype ON lab.labtype_id = labtype.id ' . ' LEFT JOIN labtype ON lab.labtype_id = labtype.id '
. ' GROUP BY schoolasset.id ' . ' GROUP BY schoolasset.id '
...@@ -249,15 +266,13 @@ return function (App $app) { ...@@ -249,15 +266,13 @@ return function (App $app) {
}; };
}; };
$c['csv_export_software'] = function ($c) {
$c['csv_export_software'] = function ($c) {
return function () { return function () {
$sql = 'SELECT softwarecategory.name AS name, ' $sql = 'SELECT softwarecategory.name AS name, '
. ' school.registry_no AS school_registry_no, ' . ' school.registry_no AS school_registry_no, '
. ' school.name AS school_name, ' . ' school.name AS school_name, '
. ' regioneduadmin.name AS region_edu_admin, '
. ' lab.id AS lab_id, ' . ' lab.id AS lab_id, '
. ' TRIM(labtype.name) AS lab_type, ' . ' TRIM(labtype.name) AS lab_type, '
. ' TRIM(software.title) AS title, ' . ' TRIM(software.title) AS title, '
...@@ -266,6 +281,8 @@ return function (App $app) { ...@@ -266,6 +281,8 @@ return function (App $app) {
. ' FROM software ' . ' FROM software '
. ' LEFT JOIN softwarecategory ON software.softwarecategory_id = softwarecategory.id ' . ' LEFT JOIN softwarecategory ON software.softwarecategory_id = softwarecategory.id '
. ' LEFT JOIN school ON software.school_id = school.id ' . ' LEFT JOIN school ON software.school_id = school.id '
. ' LEFT JOIN eduadmin ON school.eduadmin_id = eduadmin.id '
. ' LEFT JOIN regioneduadmin ON eduadmin.regioneduadmin_id = regioneduadmin.id '
. ' LEFT JOIN lab ON software.lab_id = lab.id ' . ' LEFT JOIN lab ON software.lab_id = lab.id '
. ' LEFT JOIN labtype ON lab.labtype_id = labtype.id ' . ' LEFT JOIN labtype ON lab.labtype_id = labtype.id '
. ' ORDER BY school_name '; . ' ORDER BY school_name ';
...@@ -284,17 +301,8 @@ return function (App $app) { ...@@ -284,17 +301,8 @@ return function (App $app) {
}; };
}; };
$c['csv_export_appforms'] = function ($c) { $c['csv_export_appforms'] = function ($c) {
//return function () {
return function () use ($c) { return function () use ($c) {
$settings = $c->get('settings'); $settings = $c->get('settings');
$version = $settings['application_form']['itemcategory']['currentversion']; $version = $settings['application_form']['itemcategory']['currentversion'];
...@@ -322,11 +330,14 @@ return function (App $app) { ...@@ -322,11 +330,14 @@ return function (App $app) {
$sql = 'SELECT applicationform.id AS id, ' $sql = 'SELECT applicationform.id AS id, '
. ' school.registry_no AS school_registry_no, ' . ' school.registry_no AS school_registry_no, '
. ' school.name AS school_name, ' . ' school.name AS school_name, '
. ' regioneduadmin.name AS region_edu_admin, '
. ' FROM_UNIXTIME(applicationform.submitted) AS submitted, ' . ' FROM_UNIXTIME(applicationform.submitted) AS submitted, '
. ' TRIM(applicationform.comments) AS comments' . ' TRIM(applicationform.comments) AS comments'
. ' FROM applicationformitem ' . ' FROM applicationformitem '
. ' LEFT JOIN applicationform ON applicationformitem.applicationform_id = applicationform.id ' . ' LEFT JOIN applicationform ON applicationformitem.applicationform_id = applicationform.id '
. ' LEFT JOIN school ON applicationform.school_id = school.id ' . ' LEFT JOIN school ON applicationform.school_id = school.id '
. ' LEFT JOIN eduadmin ON school.eduadmin_id = eduadmin.id '
. ' LEFT JOIN regioneduadmin ON eduadmin.regioneduadmin_id = regioneduadmin.id '
. ' LEFT JOIN itemcategory ON applicationformitem.itemcategory_id = itemcategory.id ' . ' LEFT JOIN itemcategory ON applicationformitem.itemcategory_id = itemcategory.id '
. ' LEFT JOIN lab ON applicationformitem.lab_id = lab.id ' . ' LEFT JOIN lab ON applicationformitem.lab_id = lab.id '
. ' LEFT JOIN labtype ON lab.labtype_id = labtype.id ' . ' LEFT JOIN labtype ON lab.labtype_id = labtype.id '
...@@ -337,51 +348,35 @@ return function (App $app) { ...@@ -337,51 +348,35 @@ return function (App $app) {
return $appForms; return $appForms;
// $sql = 'SELECT applicationform.id AS id, '
// . ' school.registry_no AS school_registry_no, '
// . ' school.name AS school_name, '
// . ' FROM_UNIXTIME(applicationform.submitted) AS submitted, '
// . ' TRIM(applicationform.comments) AS comments '
// . ' FROM applicationform '
// . ' LEFT JOIN school ON applicationform.school_id = school.id '
// . ' GROUP BY school.id '
// . ' HAVING MAX(applicationform.submitted)';
// $appForms = R::getAll($sql);
// return $appForms;
}; };
}; };
$c['csv_export_appnewforms'] = function ($c) { $c['csv_export_appnewforms'] = function ($c) {
return function () use ($c) { return function () use ($c) {
$appFormIdsSql = 'SELECT id FROM applicationform WHERE (submitted) IN( SELECT MAX(submitted) FROM applicationform GROUP BY school_id)'; $appFormIdsSql = 'SELECT id FROM applicationform WHERE (submitted) IN( SELECT MAX(submitted) FROM applicationform GROUP BY school_id)';
$appFormIds = R::getCol($appFormIdsSql); $appFormIds = R::getCol($appFormIdsSql);
if (empty($appFormIds)) { if (empty($appFormIds)) {
return []; return [];
} }
$in = implode(',', array_fill(0, count($appFormIds), '?')); $in = implode(',', array_fill(0, count($appFormIds), '?'));
$settings = $c->get('settings'); $settings = $c->get('settings');
$version = $settings['application_form']['itemcategory']['currentversion']; $version = $settings['application_form']['itemcategory']['currentversion'];
$sql = 'SELECT applicationform.id AS id, ' $sql = 'SELECT applicationform.id AS id, '
. ' school.registry_no AS school_registry_no, ' . ' school.registry_no AS school_registry_no, '
. ' school.name AS school_name, ' . ' school.name AS school_name, '
. ' regioneduadmin.name AS region_edu_admin, '
. ' FROM_UNIXTIME(applicationform.submitted) AS submitted, ' . ' FROM_UNIXTIME(applicationform.submitted) AS submitted, '
. ' TRIM(applicationform.comments) AS comments' . ' TRIM(applicationform.comments) AS comments'
. ' FROM applicationformitem ' . ' FROM applicationformitem '
. ' LEFT JOIN applicationform ON applicationformitem.applicationform_id = applicationform.id ' . ' LEFT JOIN applicationform ON applicationformitem.applicationform_id = applicationform.id '
. ' LEFT JOIN school ON applicationform.school_id = school.id ' . ' LEFT JOIN school ON applicationform.school_id = school.id '
. ' LEFT JOIN eduadmin ON school.eduadmin_id = eduadmin.id '
. ' LEFT JOIN regioneduadmin ON eduadmin.regioneduadmin_id = regioneduadmin.id '
. ' LEFT JOIN itemcategory ON applicationformitem.itemcategory_id = itemcategory.id ' . ' LEFT JOIN itemcategory ON applicationformitem.itemcategory_id = itemcategory.id '
. ' LEFT JOIN lab ON applicationformitem.lab_id = lab.id ' . ' LEFT JOIN lab ON applicationformitem.lab_id = lab.id '
. ' LEFT JOIN labtype ON lab.labtype_id = labtype.id ' . ' LEFT JOIN labtype ON lab.labtype_id = labtype.id '
...@@ -395,8 +390,6 @@ return function (App $app) { ...@@ -395,8 +390,6 @@ return function (App $app) {
}; };
}; };
$c['csv_export_appforms_items'] = function ($c) { $c['csv_export_appforms_items'] = function ($c) {
return function () use ($c){ return function () use ($c){
...@@ -413,14 +406,6 @@ return function (App $app) { ...@@ -413,14 +406,6 @@ return function (App $app) {
. ' WHERE itemcategory.groupflag NOT IN(' . $version . ')' . ' WHERE itemcategory.groupflag NOT IN(' . $version . ')'
. ' GROUP BY school.id)'; . ' GROUP BY school.id)';
// $appFormIdsSql = 'SELECT applicationform.id '
// . ' FROM applicationform '
// . ' GROUP BY school_id '
// . ' HAVING MAX(applicationform.submitted)';
$appFormIds = R::getCol($appFormIdsSql); $appFormIds = R::getCol($appFormIdsSql);
if (empty($appFormIds)) { if (empty($appFormIds)) {
...@@ -431,6 +416,7 @@ return function (App $app) { ...@@ -431,6 +416,7 @@ return function (App $app) {
$sql = 'SELECT applicationform.id AS id, ' $sql = 'SELECT applicationform.id AS id, '
. ' school.registry_no AS school_registry_no, ' . ' school.registry_no AS school_registry_no, '
. ' school.name AS school_name, ' . ' school.name AS school_name, '
. ' regioneduadmin.name AS region_edu_admin, '
. ' FROM_UNIXTIME(applicationform.submitted) AS submitted, ' . ' FROM_UNIXTIME(applicationform.submitted) AS submitted, '
. ' lab.id AS lab_id, ' . ' lab.id AS lab_id, '
. ' TRIM(labtype.name) AS lab_type, ' . ' TRIM(labtype.name) AS lab_type, '
...@@ -441,6 +427,8 @@ return function (App $app) { ...@@ -441,6 +427,8 @@ return function (App $app) {
. ' FROM applicationformitem ' . ' FROM applicationformitem '
. ' LEFT JOIN applicationform ON applicationformitem.applicationform_id = applicationform.id ' . ' LEFT JOIN applicationform ON applicationformitem.applicationform_id = applicationform.id '
. ' LEFT JOIN school ON applicationform.school_id = school.id ' . ' LEFT JOIN school ON applicationform.school_id = school.id '
. ' LEFT JOIN eduadmin ON school.eduadmin_id = eduadmin.id '
. ' LEFT JOIN regioneduadmin ON eduadmin.regioneduadmin_id = regioneduadmin.id '
. ' LEFT JOIN itemcategory ON applicationformitem.itemcategory_id = itemcategory.id ' . ' LEFT JOIN itemcategory ON applicationformitem.itemcategory_id = itemcategory.id '
. ' LEFT JOIN lab ON applicationformitem.lab_id = lab.id ' . ' LEFT JOIN lab ON applicationformitem.lab_id = lab.id '
. ' LEFT JOIN labtype ON lab.labtype_id = labtype.id ' . ' LEFT JOIN labtype ON lab.labtype_id = labtype.id '
...@@ -452,12 +440,10 @@ return function (App $app) { ...@@ -452,12 +440,10 @@ return function (App $app) {
}; };
}; };
$c['csv_export_newapplication'] = function ($c) { $c['csv_export_newapplication'] = function ($c) {
return function () use ($c) { return function () use ($c) {
$appFormIdsSql = 'SELECT id FROM applicationform WHERE (submitted) IN( SELECT MAX(submitted) FROM applicationform GROUP BY school_id)'; $appFormIdsSql = 'SELECT id FROM applicationform WHERE (submitted) IN( SELECT MAX(submitted) FROM applicationform GROUP BY school_id)';
$appFormIds = R::getCol($appFormIdsSql); $appFormIds = R::getCol($appFormIdsSql);
...@@ -475,6 +461,11 @@ return function (App $app) { ...@@ -475,6 +461,11 @@ return function (App $app) {
$sql = 'SELECT applicationform.id AS id, ' $sql = 'SELECT applicationform.id AS id, '
. ' school.registry_no AS school_registry_no, ' . ' school.registry_no AS school_registry_no, '
. ' school.name AS school_name, ' . ' school.name AS school_name, '
. ' regioneduadmin.name AS region_edu_admin, '
. ' FROM_UNIXTIME(applicationform.submitted) AS submitted, '
. ' lab.id AS lab_id, '
. ' TRIM(labtype.name) AS lab_type, '
. ' IF(lab.is_new = 1, "ΝΑΙ", "ΟΧΙ") AS is_new, '
. ' TRIM(itemcategory.name) AS category, ' . ' TRIM(itemcategory.name) AS category, '
. ' applicationformitem.qty AS qty, ' . ' applicationformitem.qty AS qty, '
. ' applicationformitem.qtyacquired AS qtyacquired, ' . ' applicationformitem.qtyacquired AS qtyacquired, '
...@@ -482,6 +473,8 @@ return function (App $app) { ...@@ -482,6 +473,8 @@ return function (App $app) {
. ' FROM applicationformitem ' . ' FROM applicationformitem '
. ' LEFT JOIN applicationform ON applicationformitem.applicationform_id = applicationform.id ' . ' LEFT JOIN applicationform ON applicationformitem.applicationform_id = applicationform.id '
. ' LEFT JOIN school ON applicationform.school_id = school.id ' . ' LEFT JOIN school ON applicationform.school_id = school.id '
. ' LEFT JOIN eduadmin ON school.eduadmin_id = eduadmin.id '
. ' LEFT JOIN regioneduadmin ON eduadmin.regioneduadmin_id = regioneduadmin.id '
. ' LEFT JOIN itemcategory ON applicationformitem.itemcategory_id = itemcategory.id ' . ' LEFT JOIN itemcategory ON applicationformitem.itemcategory_id = itemcategory.id '
. ' LEFT JOIN lab ON applicationformitem.lab_id = lab.id ' . ' LEFT JOIN lab ON applicationformitem.lab_id = lab.id '
. ' LEFT JOIN labtype ON lab.labtype_id = labtype.id ' . ' LEFT JOIN labtype ON lab.labtype_id = labtype.id '
...@@ -494,6 +487,7 @@ return function (App $app) { ...@@ -494,6 +487,7 @@ return function (App $app) {
return $appForms; return $appForms;
}; };
}; };
}); });
$events('on', 'app.bootstrap', function (App $app, Container $c) { $events('on', 'app.bootstrap', function (App $app, Container $c) {
......
...@@ -4,6 +4,7 @@ use Slim\App; ...@@ -4,6 +4,7 @@ use Slim\App;
use Slim\Container; use Slim\Container;
use Slim\Http\Request; use Slim\Http\Request;
use Slim\Http\Response; use Slim\Http\Response;
use GrEduLabs\OpenData\Action;
/** /**
* gredu_labs. * gredu_labs.
...@@ -13,12 +14,552 @@ use Slim\Http\Response; ...@@ -13,12 +14,552 @@ use Slim\Http\Response;
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/) * @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 * @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/ */
return function (App $app) { return function (App $app) {
$container = $app->getContainer(); $container = $app->getContainer();
$events = $container['events']; $events = $container['events'];
$filter_enabled_queries = ['schools', 'applications', 'application_items', 'new_applications', 'new_application_items', 'approved', 'labs'];
$raw_csv_export_providers = ['assets', 'software'];
$events('on', 'app.autoload', function ($autoloader) {
$autoloader->addPsr4('GrEduLabs\\OpenData\\', __DIR__ . '/src/');
});
/**
* Data queries specifications.
*/
$events('on', 'app.services', function ($container) {
$container['data_retrieve_query_specs'] = function ($container) {
return [
'schools' => [
'query' => 'SELECT school.registry_no AS registry_no, '
. ' school.name AS school_name, '
. ' schooltype.name as school_type, '
. ' prefecture.name AS prefecture, '
. ' school.municipality AS municipality, '
. ' eduadmin.name AS eduadmin, '
. ' regioneduadmin.name AS region_edu_admin, '
. ' educationlevel.name AS education_level '
. ' FROM school '
. ' LEFT JOIN eduadmin ON school.eduadmin_id = eduadmin.id '
. ' LEFT JOIN regioneduadmin ON eduadmin.regioneduadmin_id = regioneduadmin.id '
. ' LEFT JOIN educationlevel ON school.educationlevel_id = educationlevel.id '
. ' LEFT JOIN schooltype ON school.schooltype_id = schooltype.id '
. ' LEFT JOIN prefecture ON school.prefecture_id = prefecture.id '
. ' GROUP BY school.id '
. ' ORDER BY school_name',
'headers' => [
'registry_no' => 'Κωδικός μονάδας',
'school_name' => 'Ονομασία',
'school_type' => 'Τύπος μονάδας',
'prefecture' => 'Περιφερειακή ενότητα',
'municipality' => 'Δήμος',
'eduadmin' => 'Διεύθυνση εκπαίδευσης',
'region_edu_admin' => 'Περιφερειακή διεύθυνση εκπαίδευσης',
'education_level' => 'Βαθμίδα εκπαίδευσης',
],
],
'labs' => [
'query' => 'SELECT lab.id AS id, '
. ' school.registry_no AS school_registry_no, '
. ' school.name AS school_name, '
. ' TRIM(lab.name) AS name, '
. ' TRIM(labtype.name) AS type, '
. ' branch.name AS responsible_branch, '
. ' IF(lab.is_new = 1, "ΝΑΙ", "ΟΧΙ") AS is_new, '
. ' lab.area AS area, '
. ' lab.has_network AS has_network, '
. ' lab.has_server AS has_server, '
. ' GROUP_CONCAT(lesson.name SEPARATOR ", ") AS lessons, '
. ' TRIM(lab.use_in_program) AS use_in_program, '
. ' TRIM(lab.use_ext_program) AS use_ext_program '
. ' FROM lab '
. ' LEFT JOIN labtype ON lab.labtype_id = labtype.id '
. ' LEFT JOIN school ON lab.school_id = school.id '
. ' LEFT JOIN lab_lesson ON lab_lesson.lab_id = lab.id '
. ' LEFT JOIN lesson ON lab_lesson.lesson_id = lesson.id '
. ' LEFT JOIN teacher ON lab.responsible_id = teacher.id '
. ' LEFT JOIN branch ON branch.id = teacher.branch_id '
. ' LEFT JOIN eduadmin ON school.eduadmin_id = eduadmin.id '
. ' LEFT JOIN regioneduadmin ON eduadmin.regioneduadmin_id = regioneduadmin.id '
. ' LEFT JOIN prefecture ON school.prefecture_id = prefecture.id '
. ' GROUP BY lab.id '
. ' ORDER BY school_name ',
'headers' => [
'id' => 'ID',
'school_registry_no' => 'Κωδικός σχολείου',
'school_name' => 'Ονομασία σχολείου',
'name' => 'Ονομασία χώρου',
'type' => 'Τύπος χώρου',
'responsible_branch' => 'Ειδικότητα υπευθύνου',
'is_new' => 'Νέος χώρος',
'area' => 'Επιφάνεια (m^2)',
'has_network' => 'Σύνδεση στο δίκτυο',
'has_server' => 'Διαθέτει server',
'lessons' => 'Μαθήματα',
'use_in_program' => 'Χρήση στα πλαίσια μαθημάτων',
'use_ext_program' => 'Χρήση για δραστηριότητες εκτός εκπαιδευτικού προγράμματος',
],
],
'assets' => [
'query' => 'SELECT TRIM(itemcategory.name) AS category, '
. ' schoolasset.qty AS qty, '
. ' schoolasset.acquisition_year AS acquisition_year, '
. ' lab.id AS lab_id, '
. ' TRIM(labtype.name) AS lab_type, '
. ' school.registry_no AS school_registry_no, '
. ' school.name AS school_name, '
. ' schoolasset.comments AS comments '
. ' FROM schoolasset '
. ' LEFT JOIN itemcategory ON schoolasset.itemcategory_id = itemcategory.id '
. ' LEFT JOIN school ON schoolasset.school_id = school.id '
. ' LEFT JOIN lab ON schoolasset.lab_id = lab.id '
. ' LEFT JOIN labtype ON lab.labtype_id = labtype.id '
. ' GROUP BY schoolasset.id '
. ' ORDER BY lab.id',
'headers' => [
'category' => 'Είδος',
'qty' => 'Πλήθος ',
'acquisition_year' => 'Έτος κτήσης',
'lab_id' => 'ID χώρου',
'lab_type' => 'Τύπος χώρου',
'school_registry_no' => 'Κωδικός σχολείου',
'school_name' => 'Ονομασία σχολείου',
'comments' => 'Σχόλια - Παρατηρήσεις',
],
],
'software' => [
'query' => 'SELECT softwarecategory.name AS name, '
. ' school.registry_no AS school_registry_no, '
. ' school.name AS school_name, '
. ' lab.id AS lab_id, '
. ' TRIM(labtype.name) AS lab_type, '
. ' TRIM(software.title) AS title, '
. ' TRIM(software.vendor) AS vendor, '
. ' TRIM(software.url) AS url '
. ' FROM software '
. ' LEFT JOIN softwarecategory ON software.softwarecategory_id = softwarecategory.id '
. ' LEFT JOIN school ON software.school_id = school.id '
. ' LEFT JOIN lab ON software.lab_id = lab.id '
. ' LEFT JOIN labtype ON lab.labtype_id = labtype.id '
. ' ORDER BY school_name ',
'data_post_handle_callback' => function ($data) {
return array_map(function ($row) {
$row['url'] = strtolower($row['url']);
$row['url'] = str_replace('\\', '/', $row['url']);
$row['url'] = urldecode($row['url']);
return $row;
}, $data);
},
'headers' => [
'name' => 'Τύπος',
'school_registry_no' => 'Κωδικός σχολείου',
'school_name' => 'Ονομασία σχολείου',
'lab_id' => 'ID χώρου',
'lab_type' => 'Τύπος χώρου',
'title' => 'Ονομασία',
'vendor' => 'Κατασκευαστής',
'url' => 'URL',
],
],
'applications' => [
'query' => 'SELECT applicationform.id AS id, '
. ' school.registry_no AS school_registry_no, '
. ' school.name AS school_name, '
. ' eduadmin.name AS eduadmin, '
. ' regioneduadmin.name AS region_edu_admin, '
. ' FROM_UNIXTIME(applicationform.submitted) AS submitted, '
. ' TRIM(applicationform.comments) AS comments'
. ' FROM applicationformitem '
. ' LEFT JOIN applicationform ON applicationformitem.applicationform_id = applicationform.id '
. ' LEFT JOIN school ON applicationform.school_id = school.id '
. ' LEFT JOIN eduadmin ON school.eduadmin_id = eduadmin.id '
. ' LEFT JOIN regioneduadmin ON eduadmin.regioneduadmin_id = regioneduadmin.id '
. ' LEFT JOIN prefecture ON school.prefecture_id = prefecture.id '
. ' LEFT JOIN itemcategory ON applicationformitem.itemcategory_id = itemcategory.id '
. ' LEFT JOIN lab ON applicationformitem.lab_id = lab.id '
. ' LEFT JOIN labtype ON lab.labtype_id = labtype.id '
. ' WHERE applicationform.id IN '
. '('
. 'SELECT id FROM applicationform WHERE (submitted)IN (SELECT MAX( submitted )FROM applicationform '
. ' LEFT JOIN applicationformitem ON applicationformitem.applicationform_id = applicationform.id '
. ' LEFT JOIN school ON applicationform.school_id = school.id'
. ' LEFT JOIN itemcategory ON applicationformitem.itemcategory_id = itemcategory.id'
. ' LEFT JOIN lab ON applicationformitem.lab_id = lab.id'
. ' LEFT JOIN labtype ON lab.labtype_id = labtype.id'
. ' WHERE itemcategory.groupflag NOT IN ( :version )'
. ' GROUP BY school.id)'
. ')'
. ' GROUP BY school.id ',
'headers' => [
'id' => 'ID',
'school_registry_no' => 'Κωδικός σχολείου',
'school_name' => 'Ονομασία σχολείου',
'eduadmin' => 'Διεύθυνση εκπαίδευσης',
'region_edu_admin' => 'Περιφερειακή διεύθυνση εκπαίδευσης',
'submitted' => 'Ημερομηνία υποβολής',
'comments' => 'Σχόλια - Παρατηρήσεις',
],
'params_callback' => function ($container) {
$settings = $container->get('settings');
return [
':version' => $settings['application_form']['itemcategory']['currentversion'],
];
},
],
'new_applications' => [
'query' =>
'SELECT applicationform.id AS id, '