diff --git a/application/controllers/api/frontend/v1/stv/Config.php b/application/controllers/api/frontend/v1/stv/Config.php index d52016943..b08af66bb 100644 --- a/application/controllers/api/frontend/v1/stv/Config.php +++ b/application/controllers/api/frontend/v1/stv/Config.php @@ -33,6 +33,7 @@ class Config extends FHCAPI_Controller { // TODO(chris): permissions parent::__construct([ + 'filter' => ['admin:r', 'assistenz:r'], 'student' => ['admin:r', 'assistenz:r'], 'students' => ['admin:r', 'assistenz:r'] ]); @@ -52,6 +53,158 @@ class Config extends FHCAPI_Controller $this->load->config('stv'); } + /** + * Get the config for the student filters + * + * @return void + */ + public function filter() + { + $this->load->library('VariableLib', ['uid' => getAuthUID()]); + + $this->load->model('crm/Buchungstyp_model', 'BuchungstypModel'); + + $this->BuchungstypModel->addOrder('beschreibung'); + + $result = $this->BuchungstypModel->load(); + + $buchungstyp_kurzbz = $this->getDataOrTerminateWithError($result); + $buchungstyp_kurzbz_plus_all = array_merge([[ + 'buchungstyp_kurzbz' => 'all', + 'beschreibung' => $this->p->t('stv', 'konto_all_types') + ]], $buchungstyp_kurzbz); + + $this->load->model('crm/Statusgrund_model', 'StatusgrundModel'); + + $result = $this->StatusgrundModel->getAktiveGruende(); + + $statusgruende = $this->getDataOrTerminateWithError($result); + + $result = []; + + $result[] = [ + 'id' => 'filter_konto_count_0', + 'label' => $this->p->t('stv', 'filter_konto_count_0'), + 'type' => 'konto', + 'fixed' => [ + 'missing' => true, + 'usestdsem' => true + ], + 'dynamic' => [ + 'buchungstyp_kurzbz' => [ + 'type' => 'select', + 'values' => $buchungstyp_kurzbz, + 'value_key' => 'buchungstyp_kurzbz', + 'label_key' => 'beschreibung' + ] + ] + ]; + $result[] = [ + 'id' => 'filter_konto_missing_counter', + 'label' => $this->p->t('stv', 'filter_konto_missing_counter'), + 'type' => 'konto_counter', + 'dynamic' => [ + 'buchungstyp_kurzbz' => [ + 'type' => 'select', + 'values' => $buchungstyp_kurzbz_plus_all, + 'value_key' => 'buchungstyp_kurzbz', + 'label_key' => 'beschreibung' + ], + 'samestg' => [ + 'type' => 'bool', + 'label' => $this->p->t('stv', 'filter_konto_samestg'), + 'default' => $this->variablelib->getVar('kontofilterstg') == 'true' + ] + ] + ]; + $result[] = [ + 'id' => 'filter_documents', + 'label' => $this->p->t('stv', 'filter_documents'), + 'type' => 'documents' + ]; + $result[] = [ + 'id' => 'filter_konto_missing_counter_past', + 'label' => $this->p->t('stv', 'filter_konto_missing_counter_past'), + 'type' => 'konto_counter', + 'fixed' => [ + 'past' => true + ], + 'dynamic' => [ + 'buchungstyp_kurzbz' => [ + 'type' => 'select', + 'values' => $buchungstyp_kurzbz_plus_all, + 'value_key' => 'buchungstyp_kurzbz', + 'label_key' => 'beschreibung' + ], + 'samestg' => [ + 'type' => 'bool', + 'label' => $this->p->t('stv', 'filter_konto_samestg'), + 'default' => $this->variablelib->getVar('kontofilterstg') == 'true' + ] + ] + ]; + $result[] = [ + 'id' => 'filter_konto_missing_studiengebuehr', + 'label' => $this->p->t('stv', 'filter_konto_missing_studiengebuehr'), + 'type' => 'konto', + 'fixed' => [ + 'missing' => true, + 'usestdsem' => true + ], + 'dynamic' => [ + 'buchungstyp_kurzbz' => [ + 'type' => 'select', + 'values' => $buchungstyp_kurzbz, + 'value_key' => 'buchungstyp_kurzbz', + 'label_key' => 'beschreibung' + ] + ] + ]; + $result[] = [ + 'id' => 'filter_konto_studiengebuehrerhoeht', + 'label' => $this->p->t('stv', 'filter_konto_studiengebuehrerhoeht'), + 'type' => 'konto', + 'fixed' => [ + 'usestdsem' => true + ], + 'dynamic' => [ + 'buchungstyp_kurzbz' => [ + 'type' => 'select', + 'values' => $buchungstyp_kurzbz, + 'value_key' => 'buchungstyp_kurzbz', + 'label_key' => 'beschreibung' + ] + ] + ]; + $result[] = [ + 'id' => 'filter_zgv_without_date', + 'label' => $this->p->t('stv', 'filter_zgv_without_date'), + 'type' => 'zgv' + ]; + $result[] = [ + 'id' => 'filter_statusgrund', + 'label' => $this->p->t('stv', 'filter_statusgrund'), + 'type' => 'statusgrund', + 'fixed' => [ + 'usestdsem' => true + ], + 'dynamic' => [ + 'statusgrund_id' => [ + 'type' => 'select', + 'values' => $statusgruende, + 'value_key' => 'statusgrund_id', + 'label_key' => 'bezeichnung' + ] + ] + ]; + + Events::trigger('stv_conf_filter', function & () use (&$result) { + return $result; + }); + + $this->terminateWithSuccess($result); + } + public function student() { $result = []; diff --git a/application/controllers/api/frontend/v1/stv/Students.php b/application/controllers/api/frontend/v1/stv/Students.php index 9de0c29b1..49fecbfcd 100644 --- a/application/controllers/api/frontend/v1/stv/Students.php +++ b/application/controllers/api/frontend/v1/stv/Students.php @@ -44,7 +44,6 @@ class Students extends FHCAPI_Controller } // Load Libraries - $this->load->library('VariableLib', ['uid' => getAuthUID()]); $this->load->library('PhrasesLib'); $this->loadPhrases( array( @@ -854,40 +853,20 @@ class Students extends FHCAPI_Controller */ protected function addFilter($studiensemester_kurzbz) { - $filter = json_decode($this->input->get('filter'), true); + $filter = $this->input->post('filter'); + if (!is_array($filter)) { - $this->addMeta('addfilter', 'invalid filter: ' . $this->input->get('filter')); + $this->addMeta('addfilter', 'invalid filter: ' . json_encode($this->input->post('filter'))); return; } - if (isset($filter['konto_count_0'])) { - $bt = $this->PrestudentModel->escape($filter['konto_count_0']); - $stdsem = $this->PrestudentModel->escape($studiensemester_kurzbz); - - $this->PrestudentModel->db->where('( - SELECT count(*) - FROM public.tbl_konto - WHERE person_id=tbl_prestudent.person_id - AND buchungstyp_kurzbz=' . $bt . ' - AND studiensemester_kurzbz=' . $stdsem . ' - ) =', 0); - $this->PrestudentModel->db->where('get_rolle_prestudent(tbl_prestudent.prestudent_id, NULL) !=', 'Incoming'); - } - if (isset($filter['konto_missing_counter'])) { - $bt = $this->PrestudentModel->escape($filter['konto_missing_counter']); - $stg = ''; - if ($this->variablelib->getVar('kontofilterstg') == 'true') - $stg = ' AND studiengang_kz=tbl_prestudent.studiengang_kz'; - - $bt = $bt == 'alle' ? '' : ' AND buchungstyp_kurzbz=' . $bt; - - $this->PrestudentModel->db->where('( - SELECT sum(betrag) - FROM public.tbl_konto - WHERE person_id=tbl_prestudent.person_id' . - $bt . - $stg . ' - ) !=', 0); + foreach ($filter as $item) { + if (isset($item['usestdsem']) && $item['usestdsem']) + $item['studiensemester_kurzbz'] = $studiensemester_kurzbz; + if (!$this->PrestudentModel->addFilter($item)) { + $this->addMeta('addfilter', 'invalid filter: ' . json_encode($item)); + return; + } } } } diff --git a/application/models/crm/Prestudent_model.php b/application/models/crm/Prestudent_model.php index ff56c3268..ad5c3e141 100644 --- a/application/models/crm/Prestudent_model.php +++ b/application/models/crm/Prestudent_model.php @@ -1,5 +1,7 @@ execQuery($query, array($person_id)); } + + /** + * Adds a filter to the query builder + * + * @param array $filter + * @return boolean + */ + public function addFilter($filter) + { + if (!isset($filter['type'])) + return false; + + switch ($filter['type']) { + case 'konto': + $bt = ''; + $stdsem = ''; + $comp = '!='; + + if (isset($filter['buchungstyp_kurzbz']) && $filter['buchungstyp_kurzbz'] != 'all') + $bt = ' AND buchungstyp_kurzbz=' . $this->escape($filter['buchungstyp_kurzbz']); + + if (isset($filter['studiensemester_kurzbz'])) + $stdsem = ' AND studiensemester_kurzbz=' . $this->escape($filter['studiensemester_kurzbz']); + + if (isset($filter['missing']) && $filter['missing']) { + $comp = '='; + $this->db->where('get_rolle_prestudent(tbl_prestudent.prestudent_id, NULL) !=', 'Incoming'); + } + + $this->db->where('( + SELECT count(*) + FROM public.tbl_konto + WHERE person_id=tbl_prestudent.person_id + ' . $bt . ' + ' . $stdsem . ' + ) ' . $comp, 0); + break; + + case 'konto_counter': + $bt = ''; + $samestg = ''; + $past = ''; + + if (isset($filter['buchungstyp_kurzbz']) && $filter['buchungstyp_kurzbz'] != 'all') + $bt = ' AND buchungstyp_kurzbz = ' . $this->escape($filter['buchungstyp_kurzbz']); + + if (isset($filter['samestg']) && $filter['samestg']) + $samestg = ' AND studiengang_kz = tbl_prestudent.studiengang_kz'; + + if (isset($filter['past']) && $filter['past']) + $past = ' AND buchungsdatum < NOW()'; + + $this->db->where('( + SELECT sum(betrag) + FROM public.tbl_konto + WHERE person_id = tbl_prestudent.person_id + ' . $bt . ' + ' . $samestg . ' + ' . $past . ' + ) !=', 0); + break; + + case 'zgv': + $this->db + ->group_start() + ->group_start() + ->where('zgv_code IS NOT NULL') + ->where('zgvdatum IS NULL') + ->group_end() + ->or_group_start() + ->where('zgvmas_code IS NOT NULL') + ->where('zgvmadatum IS NULL') + ->group_end() + ->or_group_start() + ->where('zgvdoktor_code IS NOT NULL') + ->where('zgvdoktordatum IS NULL') + ->group_end() + ->group_end(); + break; + + case 'documents': + $this->db->where('( + SELECT count(*) + FROM public.tbl_dokumentstudiengang + WHERE dokument_kurzbz NOT IN ( + SELECT dokument_kurzbz + FROM tbl_dokumentprestudent + WHERE prestudent_id=tbl_prestudent.prestudent_id + ) + AND studiengang_kz=tbl_prestudent.studiengang_kz + ) !=', 0); + break; + + case 'statusgrund': + if (!isset($filter['statusgrund_id'])) + return false; + + if (isset($filter['studiensemester_kurzbz'])) + $stdsem = ' AND studiensemester_kurzbz=' . $this->escape($filter['studiensemester_kurzbz']); + + $this->db->where('( + SELECT count(*) + FROM public.tbl_prestudentstatus + WHERE prestudent_id = tbl_prestudent.prestudent_id + AND statusgrund_id = ' . $this->escape($filter['statusgrund_id']) . ' + ' . $stdsem . ' + ) !=', 0); + break; + } + + Events::trigger('prestudent_add_filter', $filter); + + return true; + } } diff --git a/public/js/api/factory/stv/app.js b/public/js/api/factory/stv/app.js index 6fcf46700..d75207c26 100644 --- a/public/js/api/factory/stv/app.js +++ b/public/js/api/factory/stv/app.js @@ -16,6 +16,12 @@ */ export default { + configFilter() { + return { + method: 'get', + url: 'api/frontend/v1/stv/config/filter' + }; + }, configStudent() { return { method: 'get', diff --git a/public/js/components/Stv/Studentenverwaltung/List.js b/public/js/components/Stv/Studentenverwaltung/List.js index 67cada523..56f3cb0d5 100644 --- a/public/js/components/Stv/Studentenverwaltung/List.js +++ b/public/js/components/Stv/Studentenverwaltung/List.js @@ -1,12 +1,14 @@ import {CoreFilterCmpt} from "../../filter/Filter.js"; import ListNew from './List/New.js'; +import ListFilter from './List/Filter.js'; export default { name: "ListPrestudents", components: { CoreFilterCmpt, - ListNew + ListNew, + ListFilter }, inject: { 'lists': { @@ -119,7 +121,7 @@ export default { { return Promise.resolve({ data: []}); } - return this.$api.call({url, params}); + return this.$api.call({method: 'post', url, params}); }, ajaxResponse: (url, params, response) => { return response?.data; @@ -157,8 +159,7 @@ export default { ], focusObj: null, // TODO(chris): this should be in the filter component lastSelected: null, - filterKontoCount0: undefined, - filterKontoMissingCounter: undefined, + filter: [], count: 0, filteredcount: 0, selectedcount: 0, @@ -194,6 +195,10 @@ export default { } } }, + updateFilter(filter) { + this.filter = filter; + this.updateUrl(); + }, updateUrl(endpoint, first) { this.lastSelected = first ? undefined : this.selected; @@ -214,14 +219,9 @@ export default { encodeURIComponent(this.currentSemester) ); - const params = {}, filter = {}; - if (this.filterKontoCount0) - filter.konto_count_0 = this.filterKontoCount0; - if (this.filterKontoMissingCounter) - filter.konto_missing_counter = this.filterKontoMissingCounter; - - if (filter.konto_count_0 || filter.konto_missing_counter) - params.filter = filter; + const params = {}; + if (this.filter.length) + params.filter = this.filter; if (!this.$refs.table.tableBuilt) { if (!this.$refs.table.tabulator) { @@ -311,9 +311,9 @@ export default { }, // TODO(chris): focusin, focusout, keydown and tabindex should be in the filter component // TODO(chris): filter component column chooser has no accessibilty features - template: ` + template: /* html */`