Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
gredu_labs
Commits
d408698d
Commit
d408698d
authored
Mar 31, 2016
by
Vassilis Kanellopoulos
Browse files
analyze numbers by school type
parent
163e2e17
Changes
5
Hide whitespace changes
Inline
Side-by-side
DEVELOP.md
View file @
d408698d
...
...
@@ -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
...
...
config/settings/acl.global.php
View file @
d408698d
...
...
@@ -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'
]],
],
],
],
...
...
module/in_numbers/bootstrap.php
View file @
d408698d
...
...
@@ -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
)
{
...
...
module/in_numbers/templates/in_numbers/index.twig
0 → 100644
View file @
d408698d
{%
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
module/in_numbers/templates/index.twig
View file @
d408698d
...
...
@@ -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
%}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment