Added Reihungstest-chronjob -> sends info with Sancho mail

The job
-- checks if there are active studyplans which have no public placement tests assigned yet 
-- retrieves faculty and amount of free places for each public placement test date.

This information is then sent by email in Sancho design.
This commit is contained in:
Cris
2018-12-05 16:57:23 +01:00
parent 535275adb1
commit 41b55cf571
4 changed files with 394 additions and 0 deletions
@@ -0,0 +1,193 @@
<?php
/**
* FH-Complete
*
* @package FHC-API
* @author FHC-Team
* @copyright Copyright (c) 2016, fhcomplete.org
* @license GPLv3
* @link http://fhcomplete.org
* @since Version 1.0
* @filesource
*/
if (! defined('BASEPATH'))
exit('No direct script access allowed');
class ReihungstestJob extends FHC_Controller
{
private $VILESCI_RT_VERWALTUNGS_URL;
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
// Allow script execution only from CLI
if ($this->input->is_cli_request())
{
$cli = true;
}
else
{
$this->output->set_status_header(403, 'Jobs must be run from the CLI');
echo "Jobs must be run from the CLI";
exit;
}
$this->VILESCI_RT_VERWALTUNGS_URL = site_url(). "/organisation/Reihungstest";
// Load libraries
$this->load->library('ReihungstestLib');
// Load helpers
$this->load->helper('hlp_sancho_helper');
}
/**
* Main function index as help
*
* @return void
*/
public function index()
{
$result = "The following are the available command line interface commands\n\n";
$result .= "php index.ci.php jobs/ReihungstestJob runReihungstestInfo";
echo $result. PHP_EOL;
}
public function runReihungstestJob()
{
// Get study plans that have no assigned placement tests yet
$result = $this->reihungstestlib->checkMissingReihungstest();
$missing_rt_arr = array();
if (hasData($result))
{
$missing_rt_arr = $result->retval;
}
elseif (isError($result))
{
show_error($result->error);
}
// Get free places
$result = $this->reihungstestlib->getFreePlaces();
$free_places_arr = array();
if (hasData($result))
{
$free_places_arr = $result->retval;
}
elseif (isError($result))
{
show_error($result->error);
}
// Prepare data for mail template 'ReihungstestJob'
$content_data_arr = $this->_getContentData($missing_rt_arr, $free_places_arr);
// Send email in Sancho design
if (!empty($missing_rt_arr) || !empty($free_places_arr))
{
sendSanchoMail(
'ReihungstestJob',
$content_data_arr,
MAIL_INFOCENTER,
'Support für die Reihungstest-Verwaltung');
}
}
// ------------------------------------------------------------------------
// Private methods
/**
* Returns associative array with data as needed in the reihungstest job template.
* @param array $missing_rt_arr Array with studienpläne, which have no assigned placement tests.
* @param array $free_places_arr Array with info and amount of free placement test places.
* @return array
*/
private function _getContentData($missing_rt_arr, $free_places_arr)
{
$style_tbl1 = ' cellpadding="0" cellspacing="10" width="100%" style="font-family: courier, verdana, sans-serif; font-size: 0.95em; border: 1px solid #000000;" ';
$style_tbl2 = ' cellpadding="0" cellspacing="20" width="100%" style="font-family: courier, verdana, sans-serif; font-size: 0.95em; border: 1px solid #000000;" ';
// Prepare HTML table with study plans that have no placement tests yet
if (!empty($missing_rt_arr))
{
$studienplan_list = '
<table'. $style_tbl2.'>
';
foreach ($missing_rt_arr as $rt)
{
$studienplan_list .= '
<tr><td>'. $rt->bezeichnung. '</td></tr>
';
}
$studienplan_list .= '
</table>
';
}
else
{
$studienplan_list = '
<table'. $style_tbl1.'>
<tr><td>Alles okay! Alle Studienpläne haben zumindest einen Reihungstest.</td></tr>
</table>
';
}
// Prepare HTML table with information and amount of free places
if (!empty($free_places_arr))
{
$freie_plaetze_list = '
<table'. $style_tbl2.'>
<tr>
<th>Fakultät</th>
<th>Reihungstesttermine</th>
<th>Freie Plätze</th>
</tr>
';
foreach ($free_places_arr as $free_place)
{
$datum = new DateTime($free_place->datum);
$style_alarm = ($free_place->freie_plaetze <= 5) ? ' style=" color: red; font-weight: bold" ' : ''; // mark if <=5 free places
$freie_plaetze_list .= '
<tr>
<td width="350">'. $free_place->fakultaet. '</td>
<td align="center">'. $datum->format('d.m.Y'). '</td>
<td align="center"'. $style_alarm.'>'. $free_place->freie_plaetze. '</td>
</tr>
';
}
$freie_plaetze_list .= '
</table>
';
}
else
{
$freie_plaetze_list = '
<table'. $style_tbl1.'>
<tr><td>Es gibt heute keine Ergebnisse zu freien Reihungstestplätze.</td></tr>
</table>
';
}
// Set associative array with the prepared HTML tables and URL be used by the template's variables
$content_data_arr['studienplan_list'] = $studienplan_list;
$content_data_arr['freie_plaetze_list'] = $freie_plaetze_list;
$content_data_arr['link'] = $this->VILESCI_RT_VERWALTUNGS_URL;
;
return $content_data_arr;
}
}
+23
View File
@@ -81,4 +81,27 @@ class ReihungstestLib
return false;
}
/**
* Checks if there are active studyplans which have no public placement tests assigned yet.
* Only check studyplans that are
* - bachelor,
* - active,
* - set as online application
* - valid for 1st term
* @return type
*/
public function checkMissingReihungstest()
{
return $this->ci->ReihungstestModel->checkMissingReihungstest();
}
/** Gets amount of free places.
* Retrieves faculty and amount of free places for each public placement test date.
* @return array
*/
public function getFreePlaces()
{
return $this->ci->ReihungstestModel->getFreePlaces();
}
}
@@ -38,4 +38,180 @@ class Reihungstest_model extends DB_Model
return $this->execQuery($query, array($reihungstest_id));
}
/**
* Checks if there are active studyplans which have no public placement tests assigned yet.
*/
public function checkMissingReihungstest()
{
$query = '
SELECT
bezeichnung
FROM
lehre.tbl_studienplan
WHERE
studienplan_id
IN
(
SELECT DISTINCT
studienplan_id
FROM
public.tbl_studiensemester
JOIN
lehre.tbl_studienplan_semester
USING (studiensemester_kurzbz)
JOIN
lehre.tbl_studienplan
USING (studienplan_id)
JOIN
lehre.tbl_studienordnung
USING (studienordnung_id)
JOIN
public.tbl_studiengang
USING (studiengang_kz)
WHERE
tbl_studiensemester.onlinebewerbung = \'t\'
AND
tbl_studienplan.onlinebewerbung_studienplan = \'t\'
AND
semester = 1
AND
typ = \'b\'
EXCEPT
SELECT DISTINCT
studienplan_id
FROM
public.tbl_reihungstest
JOIN
public.tbl_rt_studienplan
USING (reihungstest_id)
WHERE
datum >= now()
AND
oeffentlich = \'t\'
)
';
return $this->execQuery($query);
}
/** Gets amount of free places.
* Retrieves faculty and amount of free places for each public placement test date.
*/
public function getFreePlaces()
{
$query = '
SELECT
datum,
fakultaet,
max_plaetze - anzahl_angemeldet AS freie_plaetze
FROM
(
SELECT
studiengang_kz,
oeffentlich,
tbl_studiengang.bezeichnung,
reihungstest_id,
tbl_reihungstest.datum,
COALESCE
(
max_teilnehmer,
(
SELECT
sum(arbeitsplaetze) - ceil(sum(arbeitsplaetze)/100.0*'. REIHUNGSTEST_ARBEITSPLAETZE_SCHWUND. ')
FROM
public.tbl_rt_ort
JOIN
public.tbl_ort
ON (tbl_rt_ort.ort_kurzbz = tbl_ort.ort_kurzbz)
WHERE
tbl_rt_ort.rt_id = tbl_reihungstest.reihungstest_id
)
)
AS max_plaetze,
(
SELECT
count(*)
FROM
public.tbl_rt_person
WHERE
rt_id = tbl_reihungstest.reihungstest_id
)
AS anzahl_angemeldet,
(
WITH RECURSIVE meine_oes
(
oe_kurzbz,
oe_parent_kurzbz,
organisationseinheittyp_kurzbz
)
AS
(
SELECT
oe_kurzbz, oe_parent_kurzbz, organisationseinheittyp_kurzbz
FROM
public.tbl_organisationseinheit
WHERE
oe_kurzbz in
(
SELECT
oe_kurzbz
FROM
public.tbl_rt_studienplan
JOIN
lehre.tbl_studienplan sp USING (studienplan_id)
JOIN
lehre.tbl_studienordnung USING (studienordnung_id)
JOIN
public.tbl_studiengang sg USING (studiengang_kz)
WHERE
tbl_rt_studienplan.reihungstest_id = tbl_reihungstest.reihungstest_id
)
AND
aktiv = true
UNION ALL
SELECT
o.oe_kurzbz, o.oe_parent_kurzbz, o.organisationseinheittyp_kurzbz
FROM
public.tbl_organisationseinheit o, meine_oes
WHERE
o.oe_kurzbz = meine_oes.oe_parent_kurzbz
AND
aktiv = true
)
SELECT
ARRAY_TO_STRING(ARRAY_AGG(DISTINCT tbl_organisationseinheit.bezeichnung),\', \')
FROM
meine_oes
JOIN public.tbl_organisationseinheit USING(oe_kurzbz)
WHERE
meine_oes.organisationseinheittyp_kurzbz=\'Fakultaet\'
)
AS fakultaet
FROM
public.tbl_reihungstest
JOIN
public.tbl_studiengang
USING (studiengang_kz)
WHERE
tbl_reihungstest.datum >= now()
AND
tbl_reihungstest.oeffentlich = \'t\'
GROUP BY
tbl_studiengang.bezeichnung,
oe_kurzbz,
reihungstest_id
)
AS tbl
ORDER BY
fakultaet,
freie_plaetze
';
return $this->execQuery($query);
}
}
+2
View File
@@ -141,6 +141,8 @@ define('MAIL_IT', 'invalid@example.com');
define('MAIL_SUPPORT', 'invalid@example.com');
// Lehrgaenge
define('MAIL_LG', 'invalid@example.com');
// Infocenter
define('MAIL_INFOCENTER','invalid@example.com');
// Default Anmerkung fuer neue Lehreinheiten
// Beispiel: 'Abhaengigkeiten von anderen LV\'s\n\nSpez. Software/Equipment:\n\n'