diff --git a/DEVELOP.md b/DEVELOP.md index 0fee03bf69a48150b094a69770caa6fe2b445b88..b0fd04c0a019f74f5279670034d49fd44a4e5467 100644 --- a/DEVELOP.md +++ b/DEVELOP.md @@ -300,6 +300,13 @@ This module provides the services, views and javascript for schools to submit th This module overrides staff view of schools module. It allows school user to submit information about teachers using IT in education. +### in_numbers + +This module ovverides index page by placing a panel with the total numbers of schools +registered in application and of submitted application forms. + +It also provides the /in_numbers route where total numbers are analyzed by school type. + #### Dependencies - schools module diff --git a/config/settings/acl.global.php b/config/settings/acl.global.php index a70eef8521dad1a8e62293ea9540e639c5bc791c..041a0db9daebc845457760a653c349aa919051bb 100644 --- a/config/settings/acl.global.php +++ b/config/settings/acl.global.php @@ -35,6 +35,7 @@ return [ ['/tpe_survey/total-teachers', ['school'], ['post']], ['/forum', ['guest', 'user'], ['get']], ['/sch_sync/sync', ['school'], ['get']], + ['/in_numbers', ['guest', 'user'], ['get']], ], ], ], diff --git a/module/in_numbers/bootstrap.php b/module/in_numbers/bootstrap.php index 9f917abc9042cfedb2fee3ed03c1e888003eed8a..15ca9604bf3b0b1e9d6eaeaebe9e0aa937d71e17 100644 --- a/module/in_numbers/bootstrap.php +++ b/module/in_numbers/bootstrap.php @@ -14,16 +14,90 @@ return function (\Slim\App $app) { $container = $app->getContainer(); $events = $container['events']; + $events('on', 'app.services', function ($c) { + + $c['in_numbers_totals'] = function ($c) { + return function () { + return [ + 'schools_cnt' => RedBeanPHP\R::count('school'), + 'appforms_cnt' => (int) RedBeanPHP\R::getCell( + 'SELECT COUNT(distinct school_id ) FROM applicationform' + ), + ]; + }; + }; + + $c['in_numbers_by_school_type'] = function ($c) { + return function () { + $schoolTypes = RedBeanPHP\R::getAssoc('SELECT id, name FROM schooltype'); + $schoolsByType = RedBeanPHP\R::getAssoc( + 'SELECT school.schooltype_id, COUNT(*) AS cnt ' + . 'FROM school ' + . 'GROUP BY school.schooltype_id' + ); + $appFormByType = RedBeanPHP\R::getAssoc( + 'SELECT school.schooltype_id, COUNT(DISTINCT applicationform.school_id) AS cnt ' + . 'FROM applicationform INNER JOIN school ' + . 'ON applicationform.school_id = school.id ' + . 'GROUP BY school.schooltype_id' + ); + $results = []; + foreach ($schoolsByType as $type => $cnt) { + if (!isset($schoolTypes[$type])) { + continue; + } + $results[$type] = [ + 'type' => $schoolTypes[$type], + 'schools_cnt' => (int) $cnt, + 'appforms_cnt' => isset($appFormByType[$type]) ? (int) $appFormByType[$type] : 0, + ]; + } + usort($results, function ($a, $b) { + return strcasecmp($a['type'], $b['type']); + }); + + return $results; + }; + }; + }); + + $events('on', 'app.bootstrap', function ($app, $c) { + $app->get('/in_numbers', function (Slim\Http\Request $req, \Slim\Http\Response $res) use ($c) { + try { + $view = $c->get('view'); + $view->getEnvironment()->getLoader()->prependPath(__DIR__ . '/templates'); + $inNumbersFunction = $c->get('in_numbers_by_school_type'); + $schoolTypes = $inNumbersFunction(); + $totals = array_reduce($schoolTypes, function ($result, $type) { + $result['schools_total'] += $type['schools_cnt']; + $result['appforms_total'] += $type['appforms_cnt']; + + return $result; + }, ['schools_total' => 0, 'appforms_total' => 0]); + + return $view->render($res, 'in_numbers/index.twig', [ + 'school_types' => $schoolTypes, + 'totals' => $totals, + ]); + } catch (\Exception $ex) { + $c->get('logger')->error(sprintf('Exception: %s', $ex->getMessage()), ['file' => __FILE__, 'line' => __LINE__]); + + return []; + } + + })->setName('in_numbers'); + }); + $events('on', 'app.bootstrap', function ($app, $c) { $router = $c['router']; $route = $router->getNamedRoute('index'); $route->add(function (Slim\Http\Request $req, Slim\Http\Response $res, callable $next) use ($c) { - $view = $c->get('view'); try { - $view['total_schools'] = RedBeanPHP\R::count('school'); - $view['total_app_forms'] = (int) RedBeanPHP\R::getCell( - 'SELECT COUNT(*) FROM (SELECT id FROM applicationform GROUP BY school_id) AS cnt' - ); + $view = $c->get('view'); + $inNumbersFunction = $c->get('in_numbers_totals'); + list($total_schools, $total_app_forms) = array_values($inNumbersFunction()); + $view['total_schools'] = $total_schools; + $view['total_app_forms'] = $total_app_forms; $view->getEnvironment()->getLoader()->prependPath(__DIR__ . '/../application/templates', 'application'); $view->getEnvironment()->getLoader()->prependPath(__DIR__ . '/templates'); } catch (\Exception $ex) { diff --git a/module/in_numbers/templates/in_numbers/index.twig b/module/in_numbers/templates/in_numbers/index.twig new file mode 100644 index 0000000000000000000000000000000000000000..8a77209532605ddae430e4bfa22c64d648752182 --- /dev/null +++ b/module/in_numbers/templates/in_numbers/index.twig @@ -0,0 +1,31 @@ +{% extends "layout.twig" %} +{% block content %} +

EduLabs σε αριθμούς

+
+ + + + + + + + + + {% for row in school_types %} + + + + + + {% endfor %} + + + + + + + + +
Τύπος σχολείουΠλήθος καταχωρήσεωνΠλήθος αιτήσεων
{{ row.type }}{{ row.schools_cnt }}{{ row.appforms_cnt }}
{{ totals.schools_total }}{{ totals.appforms_total }}
+
+{% endblock %} \ No newline at end of file diff --git a/module/in_numbers/templates/index.twig b/module/in_numbers/templates/index.twig index aceeadb01f1f8f00d12ea580eab9d1597703a09d..b640d86aef975e7c8928c342485395adb24878ae 100644 --- a/module/in_numbers/templates/index.twig +++ b/module/in_numbers/templates/index.twig @@ -19,8 +19,16 @@

+ - + {% endblock %}