analyze numbers by school type

parent 163e2e17
......@@ -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
......
......@@ -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']],
],
],
],
......
......@@ -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) {
......
{% extends "layout.twig" %}
{% block content %}
<h1>EduLabs σε αριθμούς</h1>
<div class="table-responsive">
<table class="table table-borderless table-hover table-striped">
<thead>
<tr>
<th>Τύπος σχολείου</th>
<th style="width: 1%;white-space: nowrap">Πλήθος καταχωρήσεων</th>
<th style="width: 1%;white-space: nowrap">Πλήθος αιτήσεων</th>
</tr>
</thead>
<tbody>
{% for row in school_types %}
<tr>
<th>{{ row.type }}</th>
<td class="text-center">{{ row.schools_cnt }}</td>
<td class="text-center">{{ row.appforms_cnt }}</td>
</tr>
{% endfor %}
</tbody>
<tfoot>
<tr>
<td></td>
<th class="text-center">{{ totals.schools_total }}</th>
<th class="text-center">{{ totals.appforms_total }}</th>
</tr>
</tfoot>
</table>
</div>
{% endblock %}
\ No newline at end of file
......@@ -19,8 +19,16 @@
</p>
<div class="clearfix"></div>
</div>
<div class="panel-footer">
<div class="text-right">
<a href="{{ path_for('in_numbers') }}" title="Δείτε αναλυτικά">
Δείτε αναλυτικά
<i class="fa fa-chevron-right"></i>
</a>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
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