diff --git a/application/controllers/api/frontend/v1/education/Ferien.php b/application/controllers/api/frontend/v1/education/Ferien.php index 932bbca10..d8f5d1610 100644 --- a/application/controllers/api/frontend/v1/education/Ferien.php +++ b/application/controllers/api/frontend/v1/education/Ferien.php @@ -26,6 +26,8 @@ if (!defined('BASEPATH')) exit('No direct script access allowed'); */ class Ferien extends FHCAPI_Controller { + const DEFAULT_STUDIENGANG_KZ = 0; + /** * Calls the parent's constructor and prepares libraries and phrases */ @@ -33,6 +35,10 @@ class Ferien extends FHCAPI_Controller { parent::__construct([ 'getFerien' => 'basis/ferien:r', + 'getDefaultVonBis' => 'basis/ferien:r', + 'getOe' => 'basis/ferien:r', + 'getStudienplaene' => 'basis/ferien:r', + 'getFerientypen' => 'basis/ferien:r', 'getStg' => 'basis/ferien:r', 'insert' => 'basis/ferien:w', 'update' => 'basis/ferien:w', @@ -41,6 +47,7 @@ class Ferien extends FHCAPI_Controller // Load models $this->load->model('organisation/Ferien_model', 'FerienModel'); + $this->load->model('organisation/Studiengang_model', 'StudiengangModel'); // Load language phrases $this->loadPhrases([ @@ -53,25 +60,31 @@ class Ferien extends FHCAPI_Controller /** * Get Ferien - * - * @return void */ public function getFerien() { - $studiengang_kz = $this->input->get('studiengang_kz'); + // TODO check input - $this->addMeta('stgkz', $studiengang_kz); + $filterVonDatum = $this->input->get('filterVonDatum'); + $filterBisDatum = $this->input->get('filterBisDatum'); - if (!isset($studiengang_kz)) $this->terminateWithSuccess([]); + $this->FerienModel->addSelect( + 'tbl_ferien.ferien_id, tbl_ferien.bezeichnung, tbl_ferien.vondatum, tbl_ferien.bisdatum, + plan.studienplan_id, stg.studiengang_kz, oe.oe_kurzbz, fetyp.ferientyp_kurzbz, + oe.bezeichnung AS oe_bezeichnung, UPPER(stg.typ::varchar(1) || stg.kurzbz) AS studiengang_kuerzel, + plan.studienplan_id, plan.bezeichnung AS studienplan_bezeichnung, fetyp.mitarbeiter AS mitarbeiterrelevant, fetyp.studierende AS studierendenrelevant, + fetyp.lehre' + ); + $this->FerienModel->addJoin('public.tbl_studiengang stg', 'studiengang_kz', 'LEFT'); + $this->FerienModel->addJoin('lehre.tbl_studienplan plan', 'studienplan_id', 'LEFT'); + $this->FerienModel->addJoin('public.tbl_organisationseinheit oe', 'tbl_ferien.oe_kurzbz = oe.oe_kurzbz', 'LEFT'); + $this->FerienModel->addJoin('lehre.tbl_ferientyp fetyp', 'ferientyp_kurzbz', 'LEFT'); - //~ if (isset($studiengang_kz) && !is_numeric($studiengang_kz)) - //~ $this->terminateWithError($this->p->t('ui', 'errorMissingOrInvalidParameters', ['parameter'=> 'Studiengang']), self::ERROR_TYPE_GENERAL); + if (isset($filterVonDatum)) + $this->FerienModel->db->where('tbl_ferien.bisdatum >=', $filterVonDatum); - $this->FerienModel->addSelect('tbl_ferien.*, , UPPER(typ::varchar(1) || kurzbz) AS studiengang_kuerzel'); - $this->FerienModel->addJoin('public.tbl_studiengang', 'studiengang_kz'); - - if (isset($studiengang_kz) && is_numeric($studiengang_kz)) - $this->FerienModel->db->where('studiengang_kz', $studiengang_kz); + if (isset($filterBisDatum)) + $this->FerienModel->db->where('tbl_ferien.vondatum <=', $filterBisDatum); $this->FerienModel->addOrder('vondatum', 'DESC'); $result = $this->FerienModel->load(); @@ -82,17 +95,39 @@ class Ferien extends FHCAPI_Controller } /** - * Get list of Studiengaenge - * - * @return void + * Gets default dates (from - to) for filtering Ferien. */ - public function getStg() + public function getDefaultVonBis() { - $this->load->model('organisation/Studiengang_model', 'StudiengangModel'); + $defaultVonBis = ['defaultVon' => null, 'defaultBis' => null]; - $this->StudiengangModel->addSelect(' tbl_studiengang.*, UPPER(typ::varchar(1) || kurzbz) AS kuerzel'); - $this->StudiengangModel->addOrder('typ, kurzbz'); - $result = $this->StudiengangModel->load(); + // get current Studienjahr + $this->load->model('organisation/Studienjahr_model', 'StudienjahrModel'); + + $result = $this->StudienjahrModel->getAktOrNextStudienjahr(62); + + if (isError($result)) $this->terminateWithError(getError($result)); + + if (hasData($result)) + { + $studienjahr = getData($result)[0]; + $defaultVonBis['defaultVon'] = $studienjahr->beginn; + $defaultVonBis['defaultBis'] = $studienjahr->ende; + } + + $this->terminateWithSuccess($defaultVonBis); + } + + /** + * Get list of Organisationseinheiten + */ + public function getOe() + { + $this->load->model('organisation/Organisationseinheit_model', 'OrganisationseinheitModel'); + + //$this->StudiengangModel->addSelect(' tbl_studiengang.*, UPPER(typ::varchar(1) || kurzbz) AS kuerzel'); + $this->OrganisationseinheitModel->addOrder('organisationseinheittyp_kurzbz, oe_kurzbz'); + $result = $this->OrganisationseinheitModel->loadWhere(['aktiv' => true]); $data = $this->getDataOrTerminateWithError($result); @@ -100,9 +135,108 @@ class Ferien extends FHCAPI_Controller } /** - * Save Ferien - * - * @return void + * Get list of Studienplaene. + * Studienplaene are returned by Organisationseinheit, von and bis datum. + */ + public function getStudienplaene() + { + // check input + //~ $this->load->library('form_validation'); + + //~ $this->form_validation->set_rules('oe_kurzbz', 'Organisationseinheit', 'max_length[32]'); + //~ $this->form_validation->set_rules('vondatum', 'Von Datum', 'is_valid_date'); + //~ $this->form_validation->set_rules('bisdatum', 'Bis Datum', 'is_valid_date'); + + //~ if (!$this->form_validation->run()) + //~ $this->terminateWithValidationErrors($this->form_validation->error_array()); + + $oe_kurzbz = $this->input->get('oe_kurzbz'); + $vondatum = $this->input->get('vondatum'); + $bisdatum = $this->input->get('bisdatum'); + + // get Studiengang from Oe + $result = $this->StudiengangModel->loadWhere(['oe_kurzbz' => $oe_kurzbz]); + + + if (isError($result)) $this->terminateWithError(getError($result)); + if (!hasData($result)) $this->terminateWithSuccess([]); + $studiengangKzArr = array_column(getData($result), 'studiengang_kz'); + + // load models + $this->load->model('organisation/Studiensemester_model', 'StudiensemesterModel'); + $this->load->model('organisation/Studienplan_model', 'StudienplanModel'); + + // get all Studiensemester in requested date range + $result = $this->StudiensemesterModel->getByDateRange($vondatum, $bisdatum); + if (isError($result)) $this->terminateWithError(getError($result)); + if (!hasData($result)) $this->terminateWithSuccess([]); + $studiensemesterArr = array_column(getData($result), 'studiensemester_kurzbz'); + + $studienplaene = []; + foreach ($studiengangKzArr as $studiengang_kz) + { + foreach ($studiensemesterArr as $studiensemester_kurzbz) + { + // get studienplaene for each Studiengang and Studiensemester + $this->StudienplanModel->addDistinct("studienplan_id"); + $this->StudienplanModel->addSelect("lehre.tbl_studienplan.*"); + $this->StudienplanModel->addJoin("lehre.tbl_studienordnung", "studienordnung_id"); + $this->StudienplanModel->addJoin("lehre.tbl_studienplan_semester", "studienplan_id"); + + $whereArray = array( + "tbl_studienplan.aktiv" => "TRUE", + "tbl_studienordnung.studiengang_kz" => $studiengang_kz, + "tbl_studienplan_semester.studiensemester_kurzbz" => $studiensemester_kurzbz + ); + + $result = $this->StudienplanModel->loadWhere($whereArray); + + //$result = $this->StudienplanModel->getStudienplaeneBySemester($studiengang_kz, $studiensemester_kurzbz); + if (isError($result)) $this->terminateWithError(getError($result)); + if (!hasData($result)) continue; + + foreach (getData($result) as $studienplan) + { + $studienplaene[$studienplan->studienplan_id] = $studienplan; + } + } + } + + $this->terminateWithSuccess($studienplaene); + } + + /** + * Get list of Ferientypen + */ + public function getFerientypen() + { + $this->load->model('organisation/Ferientyp_model', 'FerientypModel'); + + $this->FerientypModel->addOrder('ferientyp_kurzbz'); + $result = $this->FerientypModel->load(); + + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); + } + + /** + * Get list of Studiengaenge + */ + public function getStg() + { + $this->StudiengangModel->addSelect(' tbl_studiengang.*, UPPER(typ::varchar(1) || kurzbz) AS kuerzel'); + $this->StudiengangModel->addOrder('typ, kurzbz'); + $result = $this->StudiengangModel->loadWhere(['aktiv' => true]); + + $data = $this->getDataOrTerminateWithError($result); + + $this->terminateWithSuccess($data); + } + + + /** + * Add Ferien */ public function insert() { @@ -110,11 +244,15 @@ class Ferien extends FHCAPI_Controller $data = $this->_getData(); - // TODO add insertaum and updateamum? - //~ $data = [ - //~ 'insertamum' => date('c'), - //~ 'insertvon' => getAuthUID() - //~ ]; + // get studiengang_kz from oe, otherwise default kz + $this->StudiengangModel->addSelect('studiengang_kz'); + $this->StudiengangModel->addLimit(1); + $result = $this->StudiengangModel->loadWhere(['oe_kurzbz' => $data['oe_kurzbz']]); + + $data['studiengang_kz'] = hasData($result) ? getData($result)[0]->studiengang_kz : self::DEFAULT_STUDIENGANG_KZ; + + $data = array_merge($data, ['insertamum' => date('c'), 'insertvon' => getAuthUID()]); + $id = $this->getDataOrTerminateWithError($this->FerienModel->insert($data)); $this->terminateWithSuccess(hasData($id) ? getData($id) : null); @@ -122,8 +260,6 @@ class Ferien extends FHCAPI_Controller /** * Update Ferien - * - * @return void */ public function update() { @@ -137,13 +273,8 @@ class Ferien extends FHCAPI_Controller $data = $this->_getData(); if (isEmptyArray($data)) $this->terminateWithSuccess(null); - // TODO add insertaum and updateamum? - //~ $data = [ - //~ 'updateamum' => date('c'), - //~ 'updatevon' => getAuthUID() - //~ ]; - $data['ferien_id'] = $id; + $data = array_merge($data, ['ferien_id' => $id, 'updateamum' => date('c'), 'updatevon' => getAuthUID()]); $result = $this->FerienModel->update($id, $data); @@ -154,8 +285,6 @@ class Ferien extends FHCAPI_Controller /** * Delete Ferien - * - * @return void */ public function delete() { @@ -170,7 +299,6 @@ class Ferien extends FHCAPI_Controller $this->FerienModel->addSelect('ferien_id'); $result = $this->FerienModel->load($ferien_id); - $this->addMeta('res', $result); if (!hasData($result)) $this->terminateWithError($this->p->t('ferien', 'error_missing', [ @@ -196,8 +324,6 @@ class Ferien extends FHCAPI_Controller /** * Validate ferien post input. - * @param - * @return object success or error */ private function _validate() { @@ -206,7 +332,9 @@ class Ferien extends FHCAPI_Controller $this->form_validation->set_rules('vondatum', 'Von Datum', 'required|is_valid_date'); $this->form_validation->set_rules('bisdatum', 'Bis Datum', 'required|is_valid_date'); $this->form_validation->set_rules('bezeichnung', 'Bezeichnung', 'required|max_length[128]'); - $this->form_validation->set_rules('studiengang_kz', 'Studiengang', 'required|numeric'); + $this->form_validation->set_rules('oe_kurzbz', 'Organisationseinheit', 'required|max_length[32]'); + $this->form_validation->set_rules('studienplan_id', 'Studienplan', 'numeric'); + $this->form_validation->set_rules('ferientyp_kurzbz', 'Ferientyp', 'max_length[64]'); //Events::trigger('konto_insert_validation', $this->form_validation); @@ -216,7 +344,6 @@ class Ferien extends FHCAPI_Controller /** * Gets Ferien data from post input. - * @return array */ private function _getData() { @@ -226,13 +353,14 @@ class Ferien extends FHCAPI_Controller 'vondatum', 'bisdatum', 'bezeichnung', - 'studiengang_kz' + 'oe_kurzbz', + 'studienplan_id', + 'ferientyp_kurzbz' ]; - foreach ($allowed as $field) { - if ($this->input->post($field) !== null) $data[$field] = $this->input->post($field); + $data[$field] = $this->input->post($field); } return $data; diff --git a/application/models/organisation/Ferientyp_model.php b/application/models/organisation/Ferientyp_model.php new file mode 100644 index 000000000..e8d643c8f --- /dev/null +++ b/application/models/organisation/Ferientyp_model.php @@ -0,0 +1,15 @@ +dbTable = 'lehre.tbl_ferientyp'; + $this->pk = 'ferientyp_kurzbz'; + $this->hasSequence = false; + } +} diff --git a/application/models/organisation/Studienjahr_model.php b/application/models/organisation/Studienjahr_model.php index 1686ddc48..2752842dc 100644 --- a/application/models/organisation/Studienjahr_model.php +++ b/application/models/organisation/Studienjahr_model.php @@ -53,11 +53,9 @@ class Studienjahr_model extends DB_Model * @param int $days * @return array|stdClass|null */ - public function getLastOrAktStudienjahr($days = 60) + public function getLastOrAktStudienjahr($days = 0) { - if (!is_numeric($days)) { - $days = 60; - } + $days = is_numeric($days) ? $this->escape($days) : 0; $query = ' SELECT * @@ -77,19 +75,25 @@ class Studienjahr_model extends DB_Model * @param int $days * @return array|stdClass|null */ - public function getAktOrNextStudienjahr($days = 62) + public function getAktOrNextStudienjahr($days = 0) { - if (!is_numeric($days)) { - $days = 62; - } + $days = is_numeric($days) ? $this->escape($days) : 0; $query = ' - SELECT * - FROM public.tbl_studienjahr - JOIN public.tbl_studiensemester using(studienjahr_kurzbz) - WHERE start < NOW() + \'' . $days . ' DAYS\'::INTERVAL - ORDER by start DESC - LIMIT 1 + SELECT * FROM ( + SELECT + jahr.*, MIN(sem.start) AS beginn, MAX(sem.ende) AS ende + FROM + public.tbl_studienjahr jahr + JOIN public.tbl_studiensemester sem using(studienjahr_kurzbz) + GROUP BY + studienjahr_kurzbz + ) jahre + WHERE + ende >= NOW() + \'' . $days . ' DAYS\'::INTERVAL + ORDER BY + ende + LIMIT 1 '; return $this->execQuery($query); diff --git a/public/js/api/factory/ferienverwaltung/ferienverwaltung.js b/public/js/api/factory/ferienverwaltung/ferienverwaltung.js index 57d1fbf3a..f9b30b3fd 100644 --- a/public/js/api/factory/ferienverwaltung/ferienverwaltung.js +++ b/public/js/api/factory/ferienverwaltung/ferienverwaltung.js @@ -16,21 +16,51 @@ */ export default { - getFerien(studiengang_kz) { + getFerien(filterVonDatum, filterBisDatum) { return { method: 'get', url: 'api/frontend/v1/education/ferien/getFerien', params: { - studiengang_kz + filterVonDatum, + filterBisDatum } }; }, + getOe() { + return { + method: 'get', + url: 'api/frontend/v1/education/ferien/getOe' + }; + }, + getStudienplaene(oe_kurzbz, vondatum, bisdatum) { + return { + method: 'get', + url: 'api/frontend/v1/education/ferien/getStudienplaene', + params: { + oe_kurzbz, + vondatum, + bisdatum + } + }; + }, + getFerientypen() { + return { + method: 'get', + url: 'api/frontend/v1/education/ferien/getFerientypen' + }; + }, getStg() { return { method: 'get', url: 'api/frontend/v1/education/ferien/getStg' }; }, + getDefaultVonBis() { + return { + method: 'get', + url: 'api/frontend/v1/education/ferien/getDefaultVonBis' + }; + }, insert(params) { return { method: 'post', diff --git a/public/js/components/Ferienverwaltung/Ferienverwaltung.js b/public/js/components/Ferienverwaltung/Ferienverwaltung.js index c6545be48..b074129a2 100644 --- a/public/js/components/Ferienverwaltung/Ferienverwaltung.js +++ b/public/js/components/Ferienverwaltung/Ferienverwaltung.js @@ -20,21 +20,21 @@ export default { }, data() { return { - studiengang_kz_list: [], - studiengang_kz: null, + filterVonDatum: null, + filterBisDatum: null, loading: false, tabulatorOptions: { ajaxURL: 'dummy', ajaxRequestFunc: () => this.$api.call( - ApiFerienverwaltung.getFerien(this.studiengang_kz) + ApiFerienverwaltung.getFerien(this.filterVonDatum, this.filterBisDatum) ), ajaxResponse: (url, params, response) => response.data, columns: [ - {title:"Ferien Id", field:"ferien_id", visible: false}, - {title:"Studiengang", field:"studiengang_kuerzel"}, + {title:"Ferien Id", field:"ferien_id", visible: false, headerFilter: true}, { title:"Datum von", field:"vondatum", + headerFilter: true, formatter: function (cell) { const dateStr = cell.getValue(); if (!dateStr) return ""; @@ -51,6 +51,7 @@ export default { { title:"Datum bis", field:"bisdatum", + headerFilter: true, formatter: function (cell) { const dateStr = cell.getValue(); if (!dateStr) return ""; @@ -64,7 +65,56 @@ export default { }); } }, - {title:"Bezeichnung", field:"bezeichnung"}, + {title:"Bezeichnung", field:"bezeichnung", headerFilter: true}, + {title:"Organisationseinheit Kurzbezeichnung", field:"oe_kurzbz", visible: false, headerFilter: true}, + {title:"Organisationseinheit", field:"oe_bezeichnung", headerFilter: true}, + {title:"Studienplan", field:"studienplan_bezeichnung", visible: false, headerFilter: true}, + {title:"Ferientyp Kurzbezeichnung", field:"ferientyp_kurzbz", visible: false, headerFilter: true}, + { + title:"Mitarbeiterrelevant", + field:"mitarbeiterrelevant", + visible: false, + headerFilter: true, + hozAlign: "center", + formatter:'tickCross', formatterParams: { + tickElement: '', + crossElement: '' + }, + headerFilter:"tickCross", headerFilterParams: { + "tristate":true, elementAttributes:{"value":"true"} + }, + headerFilterEmptyCheck:function(value){return value === null} + }, + { + title:"Studierendenrelevant", + field:"studierendenrelevant", + visible: false, + headerFilter: true, + hozAlign: "center", + formatter:'tickCross', formatterParams: { + tickElement: '', + crossElement: '' + }, + headerFilter:"tickCross", headerFilterParams: { + "tristate":true, elementAttributes:{"value":"true"} + }, + headerFilterEmptyCheck:function(value){return value === null} + }, + { + title:"Lehre planbar", + field:"lehre", + visible: false, + headerFilter: true, + hozAlign: "center", + formatter:'tickCross', formatterParams: { + tickElement: '', + crossElement: '' + }, + headerFilter:"tickCross", headerFilterParams: { + "tristate":true, elementAttributes:{"value":"true"} + }, + headerFilterEmptyCheck:function(value){return value === null} + }, {title:"Aktionen", field: "actions", minWidth: 150, // Ensures Action-buttons will be always fully displayed formatter: (cell, formatterParams, onRendered) => { @@ -117,9 +167,6 @@ export default { cm.getColumnByField('ferien_id').component.updateDefinition({ title: this.$p.t('ferien', 'ferien_id'), }); - cm.getColumnByField('studiengang_kuerzel').component.updateDefinition({ - title: this.$p.t('ferien', 'studiengang_kuerzel'), - }); cm.getColumnByField('vondatum').component.updateDefinition({ title: this.$p.t('ferien', 'vondatum'), }); @@ -150,50 +197,74 @@ export default { //~ }, actionNew() { this.$refs.modal.open(); - }, - loadByStg() { - this.reload(); } }, created() { - this.loading = true; + //this.loading = true; + //~ this.$api + //~ .call(ApiFerienverwaltung.getOe()) + //~ .then(result => { + //~ this.oeList = result.data; + //~ } + //~ ) + //~ .catch(error => { + //~ if (error) + //~ this.$fhcAlert.handleSystemError(error); + //~ }); + this.$api - .call(ApiFerienverwaltung.getStg()) + .call(ApiFerienverwaltung.getDefaultVonBis()) .then(result => { - this.studiengang_kz_list = result.data; - this.loading = false; + this.filterVonDatum = result.data.defaultVon; + this.filterBisDatum = result.data.defaultBis; } ) .catch(error => { if (error) this.$fhcAlert.handleSystemError(error); - this.loading = false; }); }, template: `
-
-
- - -
+
+ + +
+
+ + +
+
+
-
+
- +
` diff --git a/public/js/components/Ferienverwaltung/Modal.js b/public/js/components/Ferienverwaltung/Modal.js new file mode 100644 index 000000000..194604a0a --- /dev/null +++ b/public/js/components/Ferienverwaltung/Modal.js @@ -0,0 +1,202 @@ +import BsModal from "../Bootstrap/Modal.js"; +import BsConfirm from "../Bootstrap/Confirm.js"; +import CoreForm from "../Form/Form.js"; +import FormValidation from "../Form/Validation.js"; +import FormInput from "../Form/Input.js"; + +import ApiFerien from '../../api/factory/ferienverwaltung/ferienverwaltung.js'; + +export default { + components: { + BsModal, + CoreForm, + FormValidation, + FormInput + }, + props: { + //~ ferien_id: { + //~ type: Number, + //~ default: null + //~ } + //~ studiengang_kz_list: { + //~ type: Array, + //~ required: true + //~ } + }, + data() { + return { + oeList: [], + studienplaeneList: [], + ferientypList: [], + loading: false, + data: {}, + }; + }, + computed: { + }, + methods: { + save() { + this.$refs.form.clearValidation(); + this.loading = true; + + //~ let params = this.data; + let saveFunc = this.data.ferien_id ? ApiFerien.update : ApiFerien.insert; + + //~ if (this.data.ferien_id) { // update + //~ params = { ...{ ferien_id: this.ferien_id }, ...this.data }; + //~ let saveFunc = ApiFerien.update; + //~ } + + this.$refs.form + .call(saveFunc(this.data)) + .then(result => { + this.$emit('saved', result.data); + this.loading = false; + this.$refs.modal.hide(); + this.$fhcAlert.alertSuccess(this.$p.t('ui/gespeichert')); + }) + .catch(error => { + if (error) + this.$fhcAlert.handleSystemError(error); + this.loading = false; + }); + }, + open(data) { + this.data = data ?? { + oe_kurzbz: null, + bezeichnung: '', + vondatum: null, + bisdatum: null, + studienplan_id: null + }; + + this.$api + .call(ApiFerien.getOe()) + .then(result => { + this.oeList = result.data; + //this.loading = false; + } + ) + .catch(error => { + if (error) + this.$fhcAlert.handleSystemError(error); + //this.loading = false; + }); + + + this.getStudienplaene(); + + this.$api + .call(ApiFerien.getFerientypen()) + .then(result => { + this.ferientypList = result.data; + } + ) + .catch(error => { + if (error) + this.$fhcAlert.handleSystemError(error); + }); + + this.$refs.modal.show(); + }, + getStudienplaene() { + this.$api + .call(ApiFerien.getStudienplaene(this.data.oe_kurzbz, this.data.vondatum, this.data.bisdatum)) + .then(result => { + this.studienplaeneList = result.data; + } + ) + .catch(error => { + if (error) + this.$fhcAlert.handleSystemError(error); + }); + }, + preventCloseOnLoading(ev) { + if (this.loading) + ev.returnValue = false; + } + }, + template: ` + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
` +}; \ No newline at end of file diff --git a/system/dbupdate_3.4/71405_ferienzeiten.php b/system/dbupdate_3.4/71405_ferienzeiten.php index 98d057e9e..dfd3e4ab7 100644 --- a/system/dbupdate_3.4/71405_ferienzeiten.php +++ b/system/dbupdate_3.4/71405_ferienzeiten.php @@ -119,3 +119,64 @@ if ($result = @$db->db_query("SELECT conname FROM pg_constraint WHERE conname = echo '
lehre.tbl_ferien: Primary Key tbl_ferien_pk (ferien_id) hinzugefügt'; } } + +if(!$result = @$db->db_query("SELECT oe_kurzbz FROM lehre.tbl_ferien LIMIT 1")) +{ + $qry = "ALTER TABLE lehre.tbl_ferien + ADD COLUMN IF NOT EXISTS oe_kurzbz VARCHAR(32), + ADD COLUMN IF NOT EXISTS studienplan_id SMALLINT DEFAULT NULL, + ADD CONSTRAINT tbl_ferien_studienplan_fk + FOREIGN KEY (studienplan_id) + REFERENCES lehre.tbl_studienplan(studienplan_id) + ON UPDATE CASCADE ON DELETE RESTRICT, + ADD CONSTRAINT tbl_ferien_oe_kurzbz_fk + FOREIGN KEY (oe_kurzbz) + REFERENCES public.tbl_organisationseinheit(oe_kurzbz) + ON UPDATE CASCADE ON DELETE RESTRICT, + ADD COLUMN IF NOT EXISTS insertamum timestamp DEFAULT NOW(), + ADD COLUMN IF NOT EXISTS insertvon VARCHAR(32), + ADD COLUMN IF NOT EXISTS updateamum timestamp, + ADD COLUMN IF NOT EXISTS updatevon VARCHAR(32)"; + + if(!$db->db_query($qry)) + echo 'lehre.tbl_ferien: '.$db->db_last_error().'
'; + else + echo '
lehre.tbl_ferien columns oe_kurzbz, studienplan_id, insertamum, insertvon, updateamum, updatevon hinzugefuegt'; +} + +// Creates table lehre.tbl_ferientyp if it doesn't exist and grants privileges +if (!$result = @$db->db_query('SELECT 0 FROM lehre.tbl_ferientyp WHERE 0 = 1')) +{ + $qry = 'CREATE TABLE lehre.tbl_ferientyp ( + ferientyp_kurzbz VARCHAR(64), + beschreibung VARCHAR(256) NOT NULL, + mitarbeiter boolean NOT NULL, + studierende boolean NOT NULL, + lehre boolean NOT NULL + ); + + COMMENT ON TABLE lehre.tbl_ferientyp IS \'Typ-Tabelle zum Speichern von Informationen zu Ferien.\'; + COMMENT ON COLUMN lehre.tbl_ferientyp.ferientyp_kurzbz IS \'Typ der Ferien.\'; + COMMENT ON COLUMN lehre.tbl_ferientyp.mitarbeiter IS \'Ob die Ferien für MitarbeiterInnen relevant sind.\'; + COMMENT ON COLUMN lehre.tbl_ferientyp.studierende IS \'Ob die Ferien für Studierende relevant sind.\'; + COMMENT ON COLUMN lehre.tbl_ferientyp.lehre IS \'Ob Lehre in den Ferien verplant werden kann.\'; + + ALTER TABLE lehre.tbl_ferientyp ADD CONSTRAINT pk_tbl_ferientyp PRIMARY KEY (ferientyp_kurzbz); + + ALTER TABLE lehre.tbl_ferien ADD COLUMN IF NOT EXISTS ferientyp_kurzbz VARCHAR(64) DEFAULT NULL; + + ALTER TABLE lehre.tbl_ferien ADD CONSTRAINT tbl_lehre_ferien_ferientyp_kurzbz_fk FOREIGN KEY (ferientyp_kurzbz) + REFERENCES lehre.tbl_ferientyp (ferientyp_kurzbz) MATCH FULL + ON DELETE SET NULL ON UPDATE CASCADE;'; + + if (!$db->db_query($qry)) + echo 'lehre.tbl_ferientyp: '.$db->db_last_error().'
'; + else + echo '
lehre.tbl_ferientyp table created'; + + $qry = 'GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE lehre.tbl_ferientyp TO vilesci;'; + if (!$db->db_query($qry)) + echo 'lehre.tbl_ferientyp: '.$db->db_last_error().'
'; + else + echo '
Granted privileges to vilesci on lehre.tbl_ferientyp'; +}