Commit 3951a5c0 authored by Aspasia Katsi's avatar Aspasia Katsi Committed by Σταύρος Παπαδάκης

Updated CSV exports for old and new applications

parent 23ea9a1f
......@@ -134,7 +134,6 @@ class ApplicationForm {
$items_version = array_values($appForm['items'])[0]['version'];
}
$this->container['logger']->info("DO THE MIGRATION CHECK TO VERSION [{$this->version}] FROM VERSION [{$items_version}]");
if ($this->version != $items_version &&
isset($appForm['items']) &&
isset($this->container['settings']['application_form']['itemcategory']['map']) &&
......
......@@ -53,8 +53,6 @@ class SchoolApplicationForm
$items_version = array_values($appForm['items'])[0]['version'];
}
$this->container['logger']->info("DO THE MIGRATION CHECK TO VERSION [{$currentVersion}] FROM VERSION [{$items_version}]");
$appForm['items'] = array_reduce($appForm['items'], function ($aggr, $item) use ($currentVersion, $items_version) {
$category = $item['itemcategory_id'];
if (!isset($aggr[$category])) {
......
......@@ -67,6 +67,19 @@ return function (App $app) {
'Ονομασία σχολείου',
'Σχόλια - Παρατηρήσεις',
],
],
'software' => [
'data_callback' => 'csv_export_software',
'headers' => [
'Τύπος',
'Κωδικός σχολείου',
'Ονομασία σχολείου',
'ID χώρου',
'Τύπος χώρου',
'Ονομασία',
'Κατασκευαστής',
'URL',
],
],
'appforms' => [
'data_callback' => 'csv_export_appforms',
......@@ -78,6 +91,19 @@ return function (App $app) {
'Σχόλια - Παρατηρήσεις',
],
],
'appnewforms' => [
'data_callback' => 'csv_export_appnewforms',
'headers' => [
'ID',
'Κωδικός σχολείου',
'Ονομασία σχολείου',
'Ημερομηνία υποβολής',
'Σχόλια - Παρατηρήσεις',
],
],
'appforms_items' => [
'data_callback' => 'csv_export_appforms_items',
'headers' => [
......@@ -93,19 +119,6 @@ return function (App $app) {
'Αιτιολογία χρήσης',
],
],
'software' => [
'data_callback' => 'csv_export_software',
'headers' => [
'Τύπος',
'Κωδικός σχολείου',
'Ονομασία σχολείου',
'ID χώρου',
'Τύπος χώρου',
'Ονομασία',
'Κατασκευαστής',
'URL',
],
],
'newapplication' => [
'data_callback' => 'csv_export_newapplication',
'headers' => [
......@@ -115,6 +128,7 @@ return function (App $app) {
'Είδος',
'Πλήθος Υπαρχόντων που λειτουργούν',
'Πλήθος Αιτουμένων',
'Αιτιολογία χρήσης',
],
],
];
......@@ -235,60 +249,145 @@ return function (App $app) {
};
};
$c['csv_export_appforms'] = function ($c) {
$c['csv_export_software'] = function ($c) {
return function () {
$sql = 'SELECT applicationform.id AS id, '
$sql = '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 ';
$software = R::getAll($sql);
$software = array_map(function ($row) {
$row['url'] = strtolower($row['url']);
$row['url'] = str_replace('\\', '/', $row['url']);
$row['url'] = urldecode($row['url']);
return $row;
}, $software);
return $software;
};
};
$c['csv_export_appforms'] = function ($c) {
//return function () {
return function () use ($c) {
$settings = $c->get('settings');
$version = $settings['application_form']['itemcategory']['currentversion'];
$appFormIdsSql = '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)';
$appFormIds = R::getCol($appFormIdsSql);
if (empty($appFormIds)) {
return [];
}
$in = implode(',', array_fill(0, count($appFormIds), '?'));
$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 '
. ' 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 '
. ' GROUP BY school.id '
. ' HAVING MAX(applicationform.submitted)';
. ' 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(' . $in . ')'
. ' GROUP BY school.id ';
$appForms = R::getAll($sql);
$appForms = R::getAll($sql, $appFormIds);
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_appforms_items'] = function ($c) {
return function () {
$c['csv_export_appnewforms'] = function ($c) {
$appFormIdsSql = 'SELECT id FROM applicationform WHERE (submitted) IN( SELECT MAX(submitted) FROM applicationform GROUP BY school_id)';
return function () use ($c) {
//$appFormIdsSql = 'SELECT applicationform.id '
// . ' FROM applicationform '
// . ' GROUP BY school_id '
// . ' HAVING MAX(applicationform.submitted)';
$appFormIdsSql = 'SELECT id FROM applicationform WHERE (submitted) IN( SELECT MAX(submitted) FROM applicationform GROUP BY school_id)';
$appFormIds = R::getCol($appFormIdsSql);
if (empty($appFormIds)) {
return [];
}
$in = implode(',', array_fill(0, count($appFormIds), '?'));
$settings = $c->get('settings');
$version = $settings['application_form']['itemcategory']['currentversion'];
$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, '
. ' 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, '
. ' applicationformitem.qty AS qty, '
. ' TRIM(applicationformitem.reasons) AS reasons '
. ' 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 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(' . $in . ') ';
. ' WHERE applicationform.id IN(' . $in . ')'
. ' AND itemcategory.groupflag IN(' . $version . ')'
. ' GROUP BY school.id ';
$appForms = R::getAll($sql, $appFormIds);
......@@ -296,39 +395,64 @@ return function (App $app) {
};
};
$c['csv_export_software'] = function ($c) {
return function () {
$sql = 'SELECT softwarecategory.name AS name, '
$c['csv_export_appforms_items'] = function ($c) {
return function () use ($c){
$settings = $c->get('settings');
$version = $settings['application_form']['itemcategory']['currentversion'];
$appFormIdsSql = '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)';
// $appFormIdsSql = 'SELECT applicationform.id '
// . ' FROM applicationform '
// . ' GROUP BY school_id '
// . ' HAVING MAX(applicationform.submitted)';
$appFormIds = R::getCol($appFormIdsSql);
if (empty($appFormIds)) {
return [];
}
$in = implode(',', array_fill(0, count($appFormIds), '?'));
$sql = 'SELECT applicationform.id AS id, '
. ' school.registry_no AS school_registry_no, '
. ' school.name AS school_name, '
. ' FROM_UNIXTIME(applicationform.submitted) AS submitted, '
. ' 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 '
. ' IF(lab.is_new = 1, "ΝΑΙ", "ΟΧΙ") AS is_new, '
. ' TRIM(itemcategory.name) AS category, '
. ' applicationformitem.qty AS qty, '
. ' TRIM(applicationformitem.reasons) AS reasons '
. ' FROM applicationformitem '
. ' LEFT JOIN applicationform 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 '
. ' ORDER BY school_name ';
$software = R::getAll($sql);
$software = array_map(function ($row) {
$row['url'] = strtolower($row['url']);
$row['url'] = str_replace('\\', '/', $row['url']);
$row['url'] = urldecode($row['url']);
. ' WHERE applicationform.id IN(' . $in . ') ';
return $row;
}, $software);
$appForms = R::getAll($sql, $appFormIds);
return $software;
return $appForms;
};
};
$c['csv_export_newapplication'] = function ($c) {
return function () use ($c) {
......@@ -345,8 +469,6 @@ return function (App $app) {
$in = implode(',', array_fill(0, count($appFormIds), '?'));
// $version = container['settings']['application_form']['itemcategory']['currentversion'];
// echo "lalalala".$version . "lalalala";
$settings = $c->get('settings');
$version = $settings['application_form']['itemcategory']['currentversion'];
......
......@@ -12,7 +12,8 @@
<table class="table">
<thead>
<tr>
<th colspan="2">Λίστα αρχείων</th>
<th>Δεδομένα</th>
<th>Μεταφόρτωση αρχείου</th>
<tr>
</thead>
<tbody>
......@@ -21,16 +22,16 @@
<td>
<a href="{{ path_for('export.csv', {type: 'schools'}) }}">
<i class="fa fa-download"></i>
Μεταφόρτωση αρχείου .csv
Αρχείο .csv
</a>
</td>
</tr>
</tr>
<tr>
<td>Χώροι μονάδων που καταγράφηκαν από τη δράση</td>
<td>
<a href="{{ path_for('export.csv', {type: 'labs'}) }}">
<i class="fa fa-download"></i>
Μεταφόρτωση αρχείου .csv
Αρχείο .csv
</a>
</td>
</tr>
......@@ -39,7 +40,7 @@
<td>
<a href="{{ path_for('export.csv', {type: 'assets'}) }}">
<i class="fa fa-download"></i>
Μεταφόρτωση αρχείου .csv
Αρχείο .csv
</a>
</td>
</tr>
......@@ -48,7 +49,7 @@
<td>
<a href="{{ path_for('export.csv', {type: 'software'}) }}">
<i class="fa fa-download"></i>
Μεταφόρτωση αρχείου .csv
Αρχείο .csv
</a>
</td>
</tr>
......@@ -57,21 +58,35 @@
<td>
<a href="{{ path_for('export.csv', {type: 'appforms'}) }}">
<i class="fa fa-download"></i>
Μεταφόρτωση αρχείου .csv
Αρχείο .csv
</a>
</td>
</tr>
<tr>
<tr>
<td>Εξοπλισμός που αιτήθηκαν οι μονάδες</td>
<td>
<a href="{{ path_for('export.csv', {type: 'appforms_items'}) }}">
<i class="fa fa-download"></i>
Μεταφόρτωση αρχείου .csv
Αρχείο .csv
</a>
</td>
</tr>
<tr>
<td>Νές αιτήσεις που συγκεντρώθηκαν από τις μονάδες</td>
<td>
<a href="{{ path_for('export.csv', {type: 'appnewforms'}) }}">
<i class="fa fa-download"></i>
Αρχείο .csv
</a>
</td>
</tr>
<tr>
<tr>
<td>Εξοπλισμός που αιτήθηκαν οι μονάδες με τις νέες αιτήσεις</td>
<td>
<a href="{{ path_for('export.csv', {type: 'newapplication'}) }}">
......@@ -81,6 +96,8 @@
</td>
</tr>
</tbody>
<tfoot>
<tr><th colspan="2"></th><tr>
......
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