diff --git a/application/controllers/jobs/ReihungstestJob.php b/application/controllers/jobs/ReihungstestJob.php new file mode 100644 index 000000000..8f1ade01f --- /dev/null +++ b/application/controllers/jobs/ReihungstestJob.php @@ -0,0 +1,193 @@ +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 = ' + + '; + + foreach ($missing_rt_arr as $rt) + { + $studienplan_list .= ' + '. $rt->bezeichnung. ' + '; + } + + $studienplan_list .= ' + + '; + } + else + { + $studienplan_list = ' + + Alles okay! Alle Studienpläne haben zumindest einen Reihungstest. + + '; + } + + // Prepare HTML table with information and amount of free places + if (!empty($free_places_arr)) + { + $freie_plaetze_list = ' + + + Fakultät + Reihungstesttermine + Freie Plätze + + '; + + 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 .= ' + + '. $free_place->fakultaet. ' + '. $datum->format('d.m.Y'). ' + '. $free_place->freie_plaetze. ' + + '; + } + + $freie_plaetze_list .= ' + + '; + } + else + { + $freie_plaetze_list = ' + + Es gibt heute keine Ergebnisse zu freien Reihungstestplätze. + + '; + } + + // 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; + } +} + diff --git a/application/libraries/ReihungstestLib.php b/application/libraries/ReihungstestLib.php index 5b40e65e3..b90d9e6fc 100644 --- a/application/libraries/ReihungstestLib.php +++ b/application/libraries/ReihungstestLib.php @@ -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(); + } } diff --git a/application/models/crm/Reihungstest_model.php b/application/models/crm/Reihungstest_model.php index a8d048463..09f01fe5f 100644 --- a/application/models/crm/Reihungstest_model.php +++ b/application/models/crm/Reihungstest_model.php @@ -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); + } } \ No newline at end of file diff --git a/config/vilesci.config-default.inc.php b/config/vilesci.config-default.inc.php index 7cfff8938..eedefc2df 100644 --- a/config/vilesci.config-default.inc.php +++ b/config/vilesci.config-default.inc.php @@ -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'