diff --git a/application/config/fehler.php b/application/config/fehler.php new file mode 100644 index 000000000..68e833cd7 --- /dev/null +++ b/application/config/fehler.php @@ -0,0 +1,448 @@ + 'CORE_ZGV_0001', + 'fehler_kurzbz' => 'zgvDatumInZukunft', + 'fehlercode_extern' => null, + 'fehlertext' => 'ZGV Datum in Zukunft', + 'fehlertyp_kurzbz' => 'error', + 'app' => array('core'), + 'producerLibName' => null, + 'resolverLibName' => 'CORE_ZGV_0001', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_ZGV_0002', + 'fehler_kurzbz' => 'zgvDatumVorGeburtsdatum', + 'fehlercode_extern' => null, + 'fehlertext' => 'ZGV Datum vor Geburtsdatum', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => null, + 'resolverLibName' => 'CORE_ZGV_0002', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_ZGV_0003', + 'fehler_kurzbz' => 'zgvMasterDatumInZukunft', + 'fehlercode_extern' => null, + 'fehlertext' => 'ZGV Masterdatum in Zukunft', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => null, + 'resolverLibName' => 'CORE_ZGV_0003', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_ZGV_0004', + 'fehler_kurzbz' => 'zgvMasterDatumVorZgvdatum', + 'fehlercode_extern' => null, + 'fehlertext' => 'ZGV Masterdatum vor Zgvdatum', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => null, + 'resolverLibName' => 'CORE_ZGV_0004', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_ZGV_0005', + 'fehler_kurzbz' => 'zgvMasterDatumVorGeburtsdatum', + 'fehlercode_extern' => null, + 'fehlertext' => 'ZGV Masterdatum vor Geburtsdatum', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => null, + 'resolverLibName' => 'CORE_ZGV_0005', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_INOUT_0001', + 'fehler_kurzbz' => 'keinAufenthaltszweckPlausi', + 'fehlercode_extern' => null, + 'fehlertext' => 'Kein Aufenthaltszweck gefunden', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => null, + 'resolverLibName' => 'CORE_INOUT_0001', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_INOUT_0002', + 'fehler_kurzbz' => 'zuVieleZweckeIncomingPlausi', + 'fehlercode_extern' => null, + 'fehlertext' => 'Es sind %s Aufenthaltszwecke eingetragen (max. 1 Zweck für Incomings)', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => null, + 'resolverLibName' => 'CORE_INOUT_0002', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_INOUT_0003', + 'fehler_kurzbz' => 'falscherIncomingZweckPlausi', + 'fehlercode_extern' => null, + 'fehlertext' => 'Aufenthaltszweckcode ist %s (für Incomings ist nur Zweck 1, 2, 3 erlaubt)', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => null, + 'resolverLibName' => 'CORE_INOUT_0003', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_INOUT_0004', + 'fehler_kurzbz' => 'outgoingAufenthaltfoerderungfehltPlausi', + 'fehlercode_extern' => null, + 'fehlertext' => 'Keine Aufenthaltsfoerderung angegeben (bei Outgoings >= 29 Tage Monat im Ausland muss mind. 1 gemeldet werden)', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => null, + 'resolverLibName' => 'CORE_INOUT_0004', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_INOUT_0005', + 'fehler_kurzbz' => 'outgoingAngerechneteEctsFehlenPlausi', + 'fehlercode_extern' => null, + 'fehlertext' => 'Angerechnete ECTS fehlen (Meldepflicht bei Outgoings >= 29 Tage Monat im Ausland)', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => null, + 'resolverLibName' => 'CORE_INOUT_0005', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_INOUT_0006', + 'fehler_kurzbz' => 'outgoingErworbeneEctsFehlenPlausi', + 'fehlercode_extern' => null, + 'fehlertext' => 'Erworbene ECTS fehlen (Meldepflicht bei Outgoings >= 29 Tage Monat im Ausland)', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => null, + 'resolverLibName' => 'CORE_INOUT_0006', + 'producerIsResolver' => false + ), + + /** Plausichecks **/ + array( + 'fehlercode' => 'CORE_INOUT_0007', + 'fehler_kurzbz' => 'IncomingHeimatNationOesterreich', + 'fehlercode_extern' => null, + 'fehlertext' => 'Heimatnation bei Incoming Österreich', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => 'IncomingHeimatNationOesterreich', + 'resolverLibName' => 'CORE_INOUT_0007', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_INOUT_0008', + 'fehler_kurzbz' => 'IncomingOhneIoDatensatz', + 'fehlercode_extern' => null, + 'fehlertext' => 'Incoming hat keinen IO Datensatz (prestudent_id %s)', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => 'IncomingOhneIoDatensatz', + 'resolverLibName' => 'CORE_INOUT_0008', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_INOUT_0009', + 'fehler_kurzbz' => 'IncomingOrGsFoerderrelevant', + 'fehlercode_extern' => null, + 'fehlertext' => 'Incoming oder gemeinsames Studium ist nicht als nicht förderrelevant markiert. (prestudent_id %s)', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => 'IncomingOrGsFoerderrelevant', + 'resolverLibName' => 'CORE_INOUT_0009', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_STG_0001', + 'fehler_kurzbz' => 'StgPrestudentUngleichStgStudent', + 'fehlercode_extern' => null, + 'fehlertext' => 'Studiengang des Prestudenten ist ungleich dem Studiengang des Studenten. (prestudent_id %s)', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => 'StgPrestudentUngleichStgStudent', + 'resolverLibName' => 'CORE_STG_0001', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_STG_0002', + 'fehler_kurzbz' => 'OrgformStgUngleichOrgformPrestudent', + 'fehlercode_extern' => null, + 'fehlertext' => 'Es ist kein Studienplan mit Studiengang (%s) und Organisationsform (%s) des Studenten zugewiesen. (prestudent_id %s, Studiensemester %s)', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => 'OrgformStgUngleichOrgformPrestudent', + 'resolverLibName' => 'CORE_STG_0002', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_STG_0003', + 'fehler_kurzbz' => 'PrestudentMischformOhneOrgform', + 'fehlercode_extern' => null, + 'fehlertext' => 'Organisationsform ist für Studierenden/BewerberIn in Mischformstudiengang nicht eingetragen. (prestudent_id %s, Studiensemester %s)', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => 'PrestudentMischformOhneOrgform', + 'resolverLibName' => 'CORE_STG_0003', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_STG_0004', + 'fehler_kurzbz' => 'StgPrestudentUngleichStgStudienplan', + 'fehlercode_extern' => null, + 'fehlertext' => 'Studiengang des Prestudenten passt nicht zu Studiengang des Studienplans. (prestudent_id %s, Studienplan %s)', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => 'StgPrestudentUngleichStgStudienplan', + 'resolverLibName' => 'CORE_STG_0004', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_STUDENTSTATUS_0001', + 'fehler_kurzbz' => 'AbbrecherAktiv', + 'fehlercode_extern' => null, + 'fehlertext' => 'AbbrecherIn hat aktiven Benutzer. (prestudent_id %s)', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => 'AbbrecherAktiv', + 'resolverLibName' => null, + 'producerIsResolver' => true + ), + array( + 'fehlercode' => 'CORE_STUDENTSTATUS_0002', + 'fehler_kurzbz' => 'StudentstatusNachAbbrecher', + 'fehlercode_extern' => null, + 'fehlertext' => 'Aktiver Status nach Abbrecher Status. (prestudent_id %s)', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => 'StudentstatusNachAbbrecher', + 'resolverLibName' => 'CORE_STUDENTSTATUS_0002', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_STUDENTSTATUS_0003', + 'fehler_kurzbz' => 'AusbildungssemPrestudentUngleichAusbildungssemStatus', + 'fehlercode_extern' => null, + 'fehlertext' => 'Ausbildungssemester %s des aktuellen Status stimmt nicht mit Ausbildungssemester %s bei StudentIn (Lehrverband) überein. (student_uid %s, prestudent_id %s, Studiensemester %s)', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => 'AusbildungssemPrestudentUngleichAusbildungssemStatus', + 'resolverLibName' => 'CORE_STUDENTSTATUS_0003', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_STUDENTSTATUS_0004', + 'fehler_kurzbz' => 'InaktiverStudentAktiverStatus', + 'fehlercode_extern' => null, + 'fehlertext' => 'Inaktiver Benutzer hat aktiven Status. (prestudent_id %s)', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => 'InaktiverStudentAktiverStatus', + 'resolverLibName' => 'CORE_STUDENTSTATUS_0004', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_STUDENTSTATUS_0005', + 'fehler_kurzbz' => 'InskriptionVorLetzerBismeldung', + 'fehlercode_extern' => null, + 'fehlertext' => 'Datum der Inskription liegt vor dem Datum der letzten BIS-Meldung %s. (prestudent_id %s, Studiensemester %s)', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => 'InskriptionVorLetzerBismeldung', + 'resolverLibName' => 'CORE_STUDENTSTATUS_0005', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_STUDENTSTATUS_0006', + 'fehler_kurzbz' => 'DatumStudiensemesterFalscheReihenfolge', + 'fehlercode_extern' => null, + 'fehlertext' => 'Datum und Studiensemester sind bei den Status in falscher Reihenfolge. (prestudent_id %s)', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => 'DatumStudiensemesterFalscheReihenfolge', + 'resolverLibName' => 'CORE_STUDENTSTATUS_0006', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_STUDENTSTATUS_0007', + 'fehler_kurzbz' => 'AktiverStudentOhneStatus', + 'fehlercode_extern' => null, + 'fehlertext' => 'Aktive/r StudentIn ohne aktuellen Status (prestudent_id %s)', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => 'AktiverStudentOhneStatus', + 'resolverLibName' => 'CORE_STUDENTSTATUS_0007', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_STUDENTSTATUS_0008', + 'fehler_kurzbz' => 'StudienplanUngueltig', + 'fehlercode_extern' => null, + 'fehlertext' => 'Studienplan %s ist im Ausbildungssemester %s nicht gültig (prestudent_id %s)', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => 'StudienplanUngueltig', + 'resolverLibName' => 'CORE_STUDENTSTATUS_0008', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_STUDENTSTATUS_0009', + 'fehler_kurzbz' => 'FalscheAnzahlAbschlusspruefungen', + 'fehlercode_extern' => null, + 'fehlertext' => 'Mehrere oder keine bestandenen Abschlussprüfungen (prestudent_id %s)', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => 'FalscheAnzahlAbschlusspruefungen', + 'resolverLibName' => 'CORE_STUDENTSTATUS_0009', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_STUDENTSTATUS_0010', + 'fehler_kurzbz' => 'DatumAbschlusspruefungFehlt', + 'fehlercode_extern' => null, + 'fehlertext' => 'Kein Abschlussprüfung Datum (prestudent_id %s, abschlusspruefung_id %s)', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => 'DatumAbschlusspruefungFehlt', + 'resolverLibName' => 'CORE_STUDENTSTATUS_0010', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_STUDENTSTATUS_0011', + 'fehler_kurzbz' => 'DatumSponsionFehlt', + 'fehlercode_extern' => null, + 'fehlertext' => 'Kein Sponsionsdatum (prestudent_id %s, abschlusspruefung_id %s)', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => 'DatumSponsionFehlt', + 'resolverLibName' => 'CORE_STUDENTSTATUS_0011', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_STUDENTSTATUS_0012', + 'fehler_kurzbz' => 'BewerberNichtZumRtAngetreten', + 'fehlercode_extern' => null, + 'fehlertext' => 'Bewerber nicht zum Reihungstest angetreten (prestudent_id %s)', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => 'BewerberNichtZumRtAngetreten', + 'resolverLibName' => 'CORE_STUDENTSTATUS_0012', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_STUDENTSTATUS_0013', + 'fehler_kurzbz' => 'AktSemesterNull', + 'fehlercode_extern' => null, + 'fehlertext' => 'Aktuelles Ausbildungssemester ist 0 (prestudent_id %s, Studiensemester %s)', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => 'AktSemesterNull', + 'resolverLibName' => 'CORE_STUDENTSTATUS_0013', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_STUDENTSTATUS_0014', + 'fehler_kurzbz' => 'AbschlussstatusFehlt', + 'fehlercode_extern' => null, + 'fehlertext' => 'Kein Abschlussstatus (prestudent_id %s)', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => 'AbschlussstatusFehlt', + 'resolverLibName' => 'CORE_STUDENTSTATUS_0014', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_STUDENTSTATUS_0015', + 'fehler_kurzbz' => 'AktiverStudentstatusOhneKontobuchung', + 'fehlercode_extern' => null, + 'fehlertext' => 'Keine Kontobuchung bei aktivem Studentstatus (prestudent_id %s, Studiensemester %s)', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => 'AktiverStudentstatusOhneKontobuchung', + 'resolverLibName' => 'CORE_STUDENTSTATUS_0015', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_STUDENTSTATUS_0016', + 'fehler_kurzbz' => 'DualesStudiumOhneMarkierung', + 'fehlercode_extern' => null, + 'fehlertext' => 'StudentIn in dualem Studiengang nicht als dual markiert (prestudent_id %s, Studienplan %s)', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => 'DualesStudiumOhneMarkierung', + 'resolverLibName' => 'CORE_STUDENTSTATUS_0016', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_PERSON_0001', + 'fehler_kurzbz' => 'GbDatumWeitZurueck', + 'fehlercode_extern' => null, + 'fehlertext' => 'Geburtsdatum vor dem 01.01.1920', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => 'GbDatumWeitZurueck', + 'resolverLibName' => 'CORE_PERSON_0001', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_PERSON_0002', + 'fehler_kurzbz' => 'NationNichtOesterreichAberGemeinde', + 'fehlercode_extern' => null, + 'fehlertext' => 'Nation der Adresse ist ungleich Österreich, es ist aber eine österreichische Gemeinde (%s) angegeben (adresse_id %s)', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => 'NationNichtOesterreichAberGemeinde', + 'resolverLibName' => 'CORE_PERSON_0002', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_PERSON_0003', + 'fehler_kurzbz' => 'FalscheAnzahlHeimatadressen', + 'fehlercode_extern' => null, + 'fehlertext' => 'Es sind mehrere oder keine Heimatadressen eingetragen', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => 'FalscheAnzahlHeimatadressen', + 'resolverLibName' => 'CORE_PERSON_0003', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_PERSON_0004', + 'fehler_kurzbz' => 'FalscheAnzahlZustelladressen', + 'fehlercode_extern' => null, + 'fehlertext' => 'Es sind mehrere oder keine Zustelladressen eingetragen', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => 'FalscheAnzahlZustelladressen', + 'resolverLibName' => 'CORE_PERSON_0004', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_PERSON_0005', + 'fehler_kurzbz' => 'geburtsnationFehlt', + 'fehlercode_extern' => null, + 'fehlertext' => 'Geburtsnation nicht vorhanden', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => null, + 'resolverLibName' => 'CORE_PERSON_0005', + 'producerIsResolver' => false + ), + array( + 'fehlercode' => 'CORE_PERSON_0006', + 'fehler_kurzbz' => 'uhstatPersonkennungFehltCore', + 'fehlercode_extern' => null, + 'fehlertext' => 'Personkennung fehlt (vBpk AS, vBpk BF oder Ersatzkennzeichen fehlt)', + 'fehlertyp_kurzbz' => 'error', + 'app' => 'core', + 'producerLibName' => null, + 'resolverLibName' => 'CORE_PERSON_0006', + 'producerIsResolver' => false + ) +); diff --git a/application/controllers/api/frontend/v1/issues/IssueChecker.php b/application/controllers/api/frontend/v1/issues/IssueChecker.php index 4cd662029..d09a01af0 100644 --- a/application/controllers/api/frontend/v1/issues/IssueChecker.php +++ b/application/controllers/api/frontend/v1/issues/IssueChecker.php @@ -7,8 +7,7 @@ class IssueChecker extends FHCAPI_Controller protected $person_id; protected $_extensionName = null; - protected $_codeLibMappings = []; - protected $_codeProducerLibMappings = []; + protected $_fehlercodes = []; protected $_app = null; protected $errors = []; @@ -25,13 +24,40 @@ class IssueChecker extends FHCAPI_Controller { $this->terminateWithError("Issue Checker: permissions must be an array"); } - + $merged_permissions = array_merge($default_permissions, $permissions); - + parent::__construct($merged_permissions); $this->load->model('system/Issue_model', 'IssueModel'); + $this->load->model('system/Fehler_model', 'FehlerModel'); $this->load->model('person/Person_model', 'PersonModel'); + + // get fehler kurzbz from fehlercodes + $this->FehlerModel->addSelect('fehler_kurzbz'); + if (!isEmptyArray($this->_fehlercodes))$this->FehlerModel->db->where_in('tbl_fehler.fehlercode', $this->_fehlercodes); + $fehlerKurzbzRes = $this->FehlerModel->load(); + + if (isError($fehlerKurzbzRes)) $this->terminateWithError(getError($fehlerKurzbzRes), self::ERROR_TYPE_GENERAL); + + $fehlerKurzbz = hasData($fehlerKurzbzRes) ? array_column(getData($fehlerKurzbzRes), 'fehler_kurzbz') : []; + + // load producer and checker libraries with fehler kurbz and fehlercode list + $this->load->library( + 'issues/PlausicheckProducerLib', + array( + 'fehlerKurzbz' => $fehlerKurzbz + ), + 'PlausicheckProducerLib' + ); + + $this->load->library( + 'issues/PlausicheckResolverLib', + array( + 'fehlercodes' => $this->_fehlercodes + ), + 'PlausicheckResolverLib' + ); } public function checkPerson() @@ -47,32 +73,11 @@ class IssueChecker extends FHCAPI_Controller $persRes = $this->PersonModel->load($this->person_id); if (!hasData($persRes)) $this->terminateWithError('Person with id ' . $this->person_id . ' not found.', self::ERROR_TYPE_GENERAL); - $allCodeLibMappings = array_merge($this->_codeLibMappings, $this->_codeProducerLibMappings); - - $this->load->library( - 'issues/PlausicheckProducerLib', - array( - 'extensionName' => $this->_extensionName, - 'codeLibMappings' => $allCodeLibMappings - ), - 'PlausicheckProducerLib' - ); - - $this->load->library( - 'issues/PlausicheckResolverLib', - array( - 'extensionName' => $this->_extensionName, - 'codeLibMappings' => $this->_codeLibMappings, - 'codeProducerLibMappings' => $this->_codeProducerLibMappings - ), - 'PlausicheckResolverLib' - ); - $this->_produceIssues(); $this->_resolveIssues(); $this->_produceIssues(); - $openIssueCountRes = $this->_countOpenIssues(array_keys($allCodeLibMappings)); + $openIssueCountRes = $this->_countOpenIssues(); if (isError($openIssueCountRes)) $this->terminateWithError(getError($openIssueCountRes), self::ERROR_TYPE_GENERAL); $data = array( @@ -100,7 +105,7 @@ class IssueChecker extends FHCAPI_Controller if (!hasData($persRes)) $this->terminateWithError('Person with id ' . $this->person_id . ' not found.', self::ERROR_TYPE_GENERAL); - $openIssueCountRes = $this->_countOpenIssues(array_keys(array_merge($this->_codeLibMappings, $this->_codeProducerLibMappings))); + $openIssueCountRes = $this->_countOpenIssues(); if (isError($openIssueCountRes)) $this->terminateWithError(getError($openIssueCountRes), self::ERROR_TYPE_GENERAL); $data = array( @@ -114,13 +119,13 @@ class IssueChecker extends FHCAPI_Controller $this->terminateWithSuccess($data); } - protected function _countOpenIssues($fehlercodes) + protected function _countOpenIssues() { - if (isEmptyArray($fehlercodes)) return success([]); + if (isEmptyArray($this->_fehlercodes)) return success([]); // load open issues with given errorcodes $openIssuesRes = $this->IssueModel->getOpenIssues( - $fehlercodes, + $this->_fehlercodes, $this->person_id, $oe_kurzbz = null, $fehlercode_extern = null, @@ -138,10 +143,6 @@ class IssueChecker extends FHCAPI_Controller protected function _produceIssues() { - if (isEmptyArray($this->_codeLibMappings) && isEmptyArray($this->_codeProducerLibMappings)) return success([]); - - $allCodeLibMappings = array_merge($this->_codeLibMappings, $this->_codeProducerLibMappings); - $result = $this->PlausicheckProducerLib->producePlausicheckIssues( array('person_id' => $this->person_id) ); @@ -157,7 +158,7 @@ class IssueChecker extends FHCAPI_Controller { // load open issues with given errorcodes $openIssuesRes = $this->IssueModel->getOpenIssues( - array_keys(array_merge($this->_codeLibMappings, $this->_codeProducerLibMappings)), + $this->_fehlercodes, $this->person_id ); diff --git a/application/controllers/jobs/IssueResolver.php b/application/controllers/jobs/IssueResolver.php index fe7ee21f5..05befd0ba 100755 --- a/application/controllers/jobs/IssueResolver.php +++ b/application/controllers/jobs/IssueResolver.php @@ -5,58 +5,46 @@ */ class IssueResolver extends IssueResolver_Controller { - public function __construct() - { - parent::__construct(); - - // set fehler codes which can be resolved by the job, with own resolver defined - // structure: fehlercode => class (library) name for resolving in "resolvers" folder - $this->_codeLibMappings = array( - 'CORE_ZGV_0001' => 'CORE_ZGV_0001', - 'CORE_ZGV_0002' => 'CORE_ZGV_0002', - 'CORE_ZGV_0003' => 'CORE_ZGV_0003', - 'CORE_ZGV_0004' => 'CORE_ZGV_0004', - 'CORE_ZGV_0005' => 'CORE_ZGV_0005', - 'CORE_INOUT_0001' => 'CORE_INOUT_0001', - 'CORE_INOUT_0002' => 'CORE_INOUT_0002', - 'CORE_INOUT_0003' => 'CORE_INOUT_0003', - 'CORE_INOUT_0004' => 'CORE_INOUT_0004', - 'CORE_INOUT_0005' => 'CORE_INOUT_0005', - 'CORE_INOUT_0006' => 'CORE_INOUT_0006', - 'CORE_INOUT_0007' => 'CORE_INOUT_0007', - 'CORE_INOUT_0008' => 'CORE_INOUT_0008', - 'CORE_INOUT_0009' => 'CORE_INOUT_0009', - 'CORE_STG_0001' => 'CORE_STG_0001', - 'CORE_STG_0002' => 'CORE_STG_0002', - 'CORE_STG_0003' => 'CORE_STG_0003', - 'CORE_STG_0004' => 'CORE_STG_0004', - 'CORE_STUDENTSTATUS_0002' => 'CORE_STUDENTSTATUS_0002', - 'CORE_STUDENTSTATUS_0003' => 'CORE_STUDENTSTATUS_0003', - 'CORE_STUDENTSTATUS_0004' => 'CORE_STUDENTSTATUS_0004', - 'CORE_STUDENTSTATUS_0005' => 'CORE_STUDENTSTATUS_0005', - 'CORE_STUDENTSTATUS_0006' => 'CORE_STUDENTSTATUS_0006', - 'CORE_STUDENTSTATUS_0007' => 'CORE_STUDENTSTATUS_0007', - 'CORE_STUDENTSTATUS_0008' => 'CORE_STUDENTSTATUS_0008', - 'CORE_STUDENTSTATUS_0009' => 'CORE_STUDENTSTATUS_0009', - 'CORE_STUDENTSTATUS_0010' => 'CORE_STUDENTSTATUS_0010', - 'CORE_STUDENTSTATUS_0011' => 'CORE_STUDENTSTATUS_0011', - 'CORE_STUDENTSTATUS_0012' => 'CORE_STUDENTSTATUS_0012', - 'CORE_STUDENTSTATUS_0013' => 'CORE_STUDENTSTATUS_0013', - 'CORE_STUDENTSTATUS_0014' => 'CORE_STUDENTSTATUS_0014', - 'CORE_STUDENTSTATUS_0015' => 'CORE_STUDENTSTATUS_0015', - 'CORE_STUDENTSTATUS_0016' => 'CORE_STUDENTSTATUS_0016', - 'CORE_PERSON_0001' => 'CORE_PERSON_0001', - 'CORE_PERSON_0002' => 'CORE_PERSON_0002', - 'CORE_PERSON_0003' => 'CORE_PERSON_0003', - 'CORE_PERSON_0004' => 'CORE_PERSON_0004', - 'CORE_PERSON_0005' => 'CORE_PERSON_0005', - 'CORE_PERSON_0006' => 'CORE_PERSON_0006' - ); - - // fehler which are resolved by the job the same way as they are produced - // structure: fehlercode => class (library) name for resolving in "plausichecks" folder - $this->_codeProducerLibMappings = array( - 'CORE_STUDENTSTATUS_0001' => 'AbbrecherAktiv', - ); - } + protected $_fehlercodes = array( + 'CORE_ZGV_0001', + 'CORE_ZGV_0002', + 'CORE_ZGV_0003', + 'CORE_ZGV_0004', + 'CORE_ZGV_0005', + 'CORE_INOUT_0001', + 'CORE_INOUT_0002', + 'CORE_INOUT_0003', + 'CORE_INOUT_0004', + 'CORE_INOUT_0005', + 'CORE_INOUT_0006', + 'CORE_INOUT_0007', + 'CORE_INOUT_0008', + 'CORE_INOUT_0009', + 'CORE_STG_0001', + 'CORE_STG_0002', + 'CORE_STG_0003', + 'CORE_STG_0004', + 'CORE_STUDENTSTATUS_0001', + 'CORE_STUDENTSTATUS_0002', + 'CORE_STUDENTSTATUS_0003', + 'CORE_STUDENTSTATUS_0004', + 'CORE_STUDENTSTATUS_0005', + 'CORE_STUDENTSTATUS_0006', + 'CORE_STUDENTSTATUS_0007', + 'CORE_STUDENTSTATUS_0008', + 'CORE_STUDENTSTATUS_0009', + 'CORE_STUDENTSTATUS_0010', + 'CORE_STUDENTSTATUS_0011', + 'CORE_STUDENTSTATUS_0012', + 'CORE_STUDENTSTATUS_0013', + 'CORE_STUDENTSTATUS_0014', + 'CORE_STUDENTSTATUS_0015', + 'CORE_STUDENTSTATUS_0016', + 'CORE_PERSON_0001', + 'CORE_PERSON_0002', + 'CORE_PERSON_0003', + 'CORE_PERSON_0004', + 'CORE_PERSON_0005', + 'CORE_PERSON_0006' + ); } diff --git a/application/controllers/jobs/PlausiIssueProducer.php b/application/controllers/jobs/PlausiIssueProducer.php index 77d4518ff..e41b887c5 100644 --- a/application/controllers/jobs/PlausiIssueProducer.php +++ b/application/controllers/jobs/PlausiIssueProducer.php @@ -6,7 +6,7 @@ class PlausiIssueProducer extends PlausiIssueProducer_Controller { private $_currentStudiensemester; - protected $_app = 'core'; + protected $_apps = 'core'; public function __construct() { @@ -23,7 +23,7 @@ class PlausiIssueProducer extends PlausiIssueProducer_Controller // set fehler which can be produced by the job // structure: fehler_kurzbz => class (library) name for resolving - $this->_fehlerLibMappings = $this->plausicheckdefinitionlib->getFehlerLibMappings(); + $this->_fehlerKurzbz = $this->plausicheckdefinitionlib->getFehlerKurzbz(); } /** diff --git a/application/controllers/system/issues/Plausichecks.php b/application/controllers/system/issues/Plausichecks.php index 53ff8afe8..eb0d01e9e 100644 --- a/application/controllers/system/issues/Plausichecks.php +++ b/application/controllers/system/issues/Plausichecks.php @@ -16,7 +16,7 @@ class Plausichecks extends Auth_Controller ); // Load libraries - $this->load->library('issues/PlausicheckProducerLib', array('app' => 'core')); + $this->load->library('issues/PlausicheckProducerLib', array('apps' => 'core')); $this->load->library('issues/PlausicheckDefinitionLib'); $this->load->library('WidgetLib'); @@ -46,9 +46,10 @@ class Plausichecks extends Auth_Controller // issues array for passing issue texts $allIssues = array(); + // all fehler kurzbz which are going to be checked $fehlerKurzbz = !isEmptyString($fehler_kurzbz) ? array($fehler_kurzbz) : $this->plausicheckdefinitionlib->getFehlerKurzbz(); - $fehlerLibMappings = $this->plausicheckdefinitionlib->getFehlerLibMappings(); + // set Studiengang to null if not passed if (isEmptyString($studiengang_kz)) $studiengang_kz = null; @@ -70,12 +71,8 @@ class Plausichecks extends Auth_Controller // initialize issue array $allIssues[$fehler_kurzbz] = array('fehlercode' => $fehler->fehlercode, 'data' => array()); - // get library name for producing issue - $libName = $fehlerLibMappings[$fehler_kurzbz]; - // execute the check $plausicheckRes = $this->plausicheckproducerlib->producePlausicheckIssue( - $libName, $fehler_kurzbz, array( 'studiensemester_kurzbz' => $studiensemester_kurzbz, diff --git a/application/core/IssueResolver_Controller.php b/application/core/IssueResolver_Controller.php index ea278ddb0..0ddf31fbd 100755 --- a/application/core/IssueResolver_Controller.php +++ b/application/core/IssueResolver_Controller.php @@ -5,11 +5,8 @@ */ abstract class IssueResolver_Controller extends JOB_Controller { - // mappings in form fehlercode -> resolverlibrary name, fehler which have explicit resolver class defined - protected $_codeLibMappings = []; - - // mappings in form fehlercode -> producer library name, fehler which are resolved the same way they are produced - protected $_codeProducerLibMappings = []; + // codes of fehler to be resolved + protected $fehlercodes = []; public function __construct() { @@ -27,9 +24,7 @@ abstract class IssueResolver_Controller extends JOB_Controller $this->load->library( 'issues/PlausicheckResolverLib', [ - 'extensionName' => $this->_extensionName ?? null, - 'codeLibMappings' => $this->_codeLibMappings, - 'codeProducerLibMappings' => $this->_codeProducerLibMappings + 'fehlercodes' => $this->_fehlercodes ] ); @@ -37,7 +32,7 @@ abstract class IssueResolver_Controller extends JOB_Controller // load open issues with given errorcodes $openIssuesRes = $this->IssueModel->getOpenIssues( - array_merge(array_keys($this->_codeLibMappings), array_keys($this->_codeProducerLibMappings)) + $this->_fehlercodes ); $openIssues = hasData($openIssuesRes) ? getData($openIssuesRes) : []; diff --git a/application/core/PlausiIssueProducer_Controller.php b/application/core/PlausiIssueProducer_Controller.php index 5216d284c..6004a3e0e 100644 --- a/application/core/PlausiIssueProducer_Controller.php +++ b/application/core/PlausiIssueProducer_Controller.php @@ -5,14 +5,14 @@ */ abstract class PlausiIssueProducer_Controller extends JOB_Controller { - protected $_fehlerLibMappings = []; - protected $_app; + protected $_fehlerKurzbz = []; + protected $_apps; protected function producePlausicheckIssues($params) { $this->load->library( 'issues/PlausicheckProducerLib', - ['extensionName' => $this->_extensionName ?? null, 'app' => $this->_app, 'fehlerLibMappings' => $this->_fehlerLibMappings] + ['apps' => $this->_apps, 'fehlerKurzbz' => $this->_fehlerKurzbz] ); $this->logInfo("Plausicheck issue producer job started"); diff --git a/application/libraries/issues/PlausicheckDefinitionLib.php b/application/libraries/issues/PlausicheckDefinitionLib.php index d8c26d43a..d760fbc7d 100644 --- a/application/libraries/issues/PlausicheckDefinitionLib.php +++ b/application/libraries/issues/PlausicheckDefinitionLib.php @@ -9,48 +9,40 @@ class PlausicheckDefinitionLib { // set fehler for core plausichecks // structure: fehler_kurzbz => class (library) name for resolving - private $_fehlerLibMappings = array( - 'AbbrecherAktiv' => 'AbbrecherAktiv', - 'AbschlussstatusFehlt' => 'AbschlussstatusFehlt', - 'AktSemesterNull' => 'AktSemesterNull', - 'AktiverStudentOhneStatus' => 'AktiverStudentOhneStatus', - 'AusbildungssemPrestudentUngleichAusbildungssemStatus' => 'AusbildungssemPrestudentUngleichAusbildungssemStatus', - 'DatumAbschlusspruefungFehlt' => 'DatumAbschlusspruefungFehlt', - 'DatumSponsionFehlt' => 'DatumSponsionFehlt', - 'DatumStudiensemesterFalscheReihenfolge' => 'DatumStudiensemesterFalscheReihenfolge', - 'FalscheAnzahlAbschlusspruefungen' => 'FalscheAnzahlAbschlusspruefungen', - 'FalscheAnzahlHeimatadressen' => 'FalscheAnzahlHeimatadressen', - 'FalscheAnzahlZustelladressen' => 'FalscheAnzahlZustelladressen', - 'GbDatumWeitZurueck' => 'GbDatumWeitZurueck', - 'InaktiverStudentAktiverStatus' => 'InaktiverStudentAktiverStatus', - 'IncomingHeimatNationOesterreich' => 'IncomingHeimatNationOesterreich', - 'IncomingOhneIoDatensatz' => 'IncomingOhneIoDatensatz', - 'IncomingOrGsFoerderrelevant' => 'IncomingOrGsFoerderrelevant', - 'InskriptionVorLetzerBismeldung' => 'InskriptionVorLetzerBismeldung', - 'NationNichtOesterreichAberGemeinde' => 'NationNichtOesterreichAberGemeinde', - 'OrgformStgUngleichOrgformPrestudent' => 'OrgformStgUngleichOrgformPrestudent', - 'PrestudentMischformOhneOrgform' => 'PrestudentMischformOhneOrgform', - 'StgPrestudentUngleichStgStudienplan' => 'StgPrestudentUngleichStgStudienplan', - 'StgPrestudentUngleichStgStudent' => 'StgPrestudentUngleichStgStudent', - 'StudentstatusNachAbbrecher' => 'StudentstatusNachAbbrecher', + private $_fehlerKurzbz = array( + 'AbbrecherAktiv', + 'AbschlussstatusFehlt', + 'AktSemesterNull', + 'AktiverStudentOhneStatus', + 'AusbildungssemPrestudentUngleichAusbildungssemStatus', + 'DatumAbschlusspruefungFehlt', + 'DatumSponsionFehlt', + 'DatumStudiensemesterFalscheReihenfolge', + 'FalscheAnzahlAbschlusspruefungen', + 'FalscheAnzahlHeimatadressen', + 'FalscheAnzahlZustelladressen', + 'GbDatumWeitZurueck', + 'InaktiverStudentAktiverStatus', + 'IncomingHeimatNationOesterreich', + 'IncomingOhneIoDatensatz', + 'IncomingOrGsFoerderrelevant', + 'InskriptionVorLetzerBismeldung', + 'NationNichtOesterreichAberGemeinde', + 'OrgformStgUngleichOrgformPrestudent', + 'PrestudentMischformOhneOrgform', + 'StgPrestudentUngleichStgStudienplan', + 'StgPrestudentUngleichStgStudent', + 'StudentstatusNachAbbrecher', 'DualesStudiumOhneMarkierung' => 'DualesStudiumOhneMarkierung' - //'StudienplanUngueltig' => 'StudienplanUngueltig' - //'BewerberNichtZumRtAngetreten' => 'BewerberNichtZumRtAngetreten' + //'StudienplanUngueltig', + //'BewerberNichtZumRtAngetreten' ); - /** - * Gets all fehler_kurzbz-library mappings for fehler which need to be checked. - */ - public function getFehlerLibMappings() - { - return $this->_fehlerLibMappings; - } - /** * Gets all fehler_kurzbz for fehler which need to be checked. */ public function getFehlerKurzbz() { - return array_keys($this->_fehlerLibMappings); + return $this->_fehlerKurzbz; } } diff --git a/application/libraries/issues/PlausicheckProducerLib.php b/application/libraries/issues/PlausicheckProducerLib.php index cea9967fb..da332d83d 100644 --- a/application/libraries/issues/PlausicheckProducerLib.php +++ b/application/libraries/issues/PlausicheckProducerLib.php @@ -9,33 +9,41 @@ class PlausicheckProducerLib const EXTENSIONS_FOLDER = 'extensions'; const PLAUSI_ISSUES_FOLDER = 'issues/plausichecks'; const EXECUTE_PLAUSI_CHECK_METHOD_NAME = 'executePlausiCheck'; + const CONFIG_FEHLER_FILENAME = 'fehler.php'; + const CONFIG_FEHLER_NAME = 'fehler'; + const FEHLER_KURZBZ_NAME = 'fehler_kurzbz'; + const PRODUCER_LIB_NAME = 'producerLibName'; + const EXTENSION_NAME = 'extensionName'; private $_ci; // ci instance - private $_extensionName; // name of extension private $_konfiguration = []; // configuration parameters + private $_fehlerKurzbz = []; // fehler to produce private $_fehlerLibMappings = []; // mappings of fehler and libraries for producing them - private $_isForResolutionCheck = false; // mappings of fehler and libraries for producing them + private $_apps = []; // apps of fehler to produce public function __construct($params = null) { - // set extension name if called from extension - if (isset($params['extensionName'])) $this->_extensionName = $params['extensionName']; - if (isset($params['fehlerLibMappings'])) $this->_fehlerLibMappings = $params['fehlerLibMappings']; - if (isset($params['isForResolutionCheck'])) $this->_isForResolutionCheck = $params['isForResolutionCheck']; - - // set application - $app = isset($params['app']) ? $params['app'] : null; + // set application(s)) + if (isset($params['apps'])) + { + if (is_string($params['apps'])) $params['apps'] = [$params['apps']]; + if (is_array($params['apps'])) $this->_apps = $params['apps']; + } $this->_ci =& get_instance(); // get ci instance // load libraries $this->_ci->load->library('IssuesLib'); + $this->_ci->load->library('ExtensionsLib'); // load models + $this->_ci->load->model('system/Fehler_model', 'FehlerModel'); $this->_ci->load->model('system/Fehlerkonfiguration_model', 'FehlerkonfigurationModel'); - // get all configuration parameters for the application - $fehlerkonfigurationRes = $this->_ci->FehlerkonfigurationModel->getKonfiguration($app); + $this->_ci->load->config('fehler'); + + // get all configuration parameters for the application(s)) + $fehlerkonfigurationRes = $this->_ci->FehlerkonfigurationModel->getKonfiguration($this->_apps); if (hasData($fehlerkonfigurationRes)) { @@ -46,10 +54,86 @@ class PlausicheckProducerLib $this->_konfiguration[$fk->fehler_kurzbz][$fk->konfigurationstyp_kurzbz] = $fk->konfiguration; } } + + // get all fehler to be produced (by kurzbz array or app) + if (isset($params['fehlerKurzbz']) && !isEmptyArray($params['fehlerKurzbz'])) + { + $this->_fehlerKurzbz = $params['fehlerKurzbz']; + } + else + { + $this->_ci->FehlerModel->addSelect('fehler_kurzbz'); + if (!isEmptyArray($this->_apps)) $this->_ci->FehlerModel->db->where_in('app', $this->_apps); + $fehlerRes = $this->_ci->FehlerModel->load(); + + if (hasData($fehlerRes)) + { + $this->_fehlerKurzbz = array_column(getData($fehlerRes), 'fehler_kurzbz'); + } + } + + // get producer file paths for the fehler + + // Load Fehler Entries of Core + $configArray = $this->_ci->config->item(self::CONFIG_FEHLER_NAME); + + foreach ($configArray as $coreEntry) + { + if (!isset($coreEntry[self::FEHLER_KURZBZ_NAME]) + || !isset($coreEntry[self::PRODUCER_LIB_NAME]) + || !in_array($coreEntry[self::FEHLER_KURZBZ_NAME], $this->_fehlerKurzbz) + ) { + continue; + } + + $this->_fehlerLibMappings[$coreEntry[self::FEHLER_KURZBZ_NAME]][self::PRODUCER_LIB_NAME] = $coreEntry[self::PRODUCER_LIB_NAME]; + } + + // load fehler entries of extensions + $extensions = $this->_ci->extensionslib->getInstalledExtensions(); + + if (hasData($extensions)) + { + $extensionArray = array(); + + $extensionsData = getData($extensions); + + + foreach ($extensionsData as $ext) + { + $configFilename = APPPATH.'config/'.ExtensionsLib::EXTENSIONS_DIR_NAME.'/'.$ext->name.'/'.self::CONFIG_FEHLER_FILENAME; + + if (file_exists($configFilename)) + { + $config = array(); // default value + + include($configFilename); + + if (isset($config[self::CONFIG_FEHLER_NAME]) && is_array($config[self::CONFIG_FEHLER_NAME])) + { + foreach ($config[self::CONFIG_FEHLER_NAME] as $extensionEntry) + { + if ( + !isset($extensionEntry[self::FEHLER_KURZBZ_NAME]) + || !isset($extensionEntry[self::PRODUCER_LIB_NAME]) + || !in_array($extensionEntry[self::FEHLER_KURZBZ_NAME], $this->_fehlerKurzbz) + ) { + continue; + } + + $fehler_kurzbz = $extensionEntry[self::FEHLER_KURZBZ_NAME]; + + $this->_fehlerLibMappings[$fehler_kurzbz][self::PRODUCER_LIB_NAME] = $extensionEntry[self::PRODUCER_LIB_NAME]; + $this->_fehlerLibMappings[$fehler_kurzbz][self::EXTENSION_NAME] = $ext->name; + } + } + } + } + } } /** - * Produces multiple plausicheck issues at once and saved them to db. + * Produces multiple plausicheck issues at once, and saves them in the database. * @param array $params passed to each plausicheck * @return result object with occured error and info */ @@ -58,11 +142,17 @@ class PlausicheckProducerLib $result = new StdClass(); $result->errors = []; $result->infos = []; + $mappingFehlerKurbz = array_keys($this->_fehlerLibMappings); - foreach ($this->_fehlerLibMappings as $fehler_kurzbz => $libName) + // check if all issues to produce could be found in database + $notFoundFehlerKurzbz = array_diff($this->_fehlerKurzbz, $mappingFehlerKurbz); + + if (!isEmptyArray($notFoundFehlerKurzbz)) + $result->errors[] = error('Fehler to produce not defined in config: '.implode(', ', $notFoundFehlerKurzbz)); + + foreach ($mappingFehlerKurbz as $fehler_kurzbz) { $plausicheckRes = $this->producePlausicheckIssue( - $libName, $fehler_kurzbz, $params ); @@ -96,14 +186,22 @@ class PlausicheckProducerLib /** * Executes plausicheck using a given library, returns the result. - * @param $libName string name of library producing the issue * @param $fehler_kurzbz string unique short name of fehler, for which issue is produced * @param $params parameters passed to issue production method */ - public function producePlausicheckIssue($libName, $fehler_kurzbz, $params) + public function producePlausicheckIssue($fehler_kurzbz, $params) { + if (!isset($this->_fehlerLibMappings[$fehler_kurzbz])) return error("Mapping for Fehler " . $fehler_kurzbz . " was not found"); + + $mapping = $this->_fehlerLibMappings[$fehler_kurzbz]; + + if (!isset($mapping[self::PRODUCER_LIB_NAME]) || isEmptyString($mapping[self::PRODUCER_LIB_NAME])) + return error("No producer lib name set for Fehler " . $fehler_kurzbz); + + $libName = $mapping[self::PRODUCER_LIB_NAME]; + // if called from extension (extension name set), path includes extension names - $libRootPath = isset($this->_extensionName) ? self::EXTENSIONS_FOLDER . '/' . $this->_extensionName . '/' : ''; + $libRootPath = isset($mapping[self::EXTENSION_NAME]) ? self::EXTENSIONS_FOLDER . '/' . $mapping[self::EXTENSION_NAME] . '/' : ''; // path for loading issue library $issuesLibPath = $libRootPath . self::PLAUSI_ISSUES_FOLDER . '/'; @@ -121,7 +219,7 @@ class PlausicheckProducerLib // load library connected to fehlercode $this->_ci->load->library( $issuesLibPath . $libName, - ['configurationParams' => $config, 'isForResolutionCheck' => $this->_isForResolutionCheck] + ['configurationParams' => $config] ); $lowercaseLibName = mb_strtolower($libName); diff --git a/application/libraries/issues/PlausicheckResolverLib.php b/application/libraries/issues/PlausicheckResolverLib.php index 2b20a7d93..bbbd79203 100644 --- a/application/libraries/issues/PlausicheckResolverLib.php +++ b/application/libraries/issues/PlausicheckResolverLib.php @@ -9,28 +9,106 @@ class PlausicheckResolverLib const EXTENSIONS_FOLDER = 'extensions'; const ISSUE_RESOLVERS_FOLDER = 'issues/resolvers'; const CHECK_ISSUE_RESOLVED_METHOD_NAME = 'checkIfIssueIsResolved'; + const CONFIG_FEHLER_FILENAME = 'fehler.php'; + const CONFIG_FEHLER_NAME = 'fehler'; + const FEHLERCODE_NAME = 'fehlercode'; + const FEHLER_KURZBZ_NAME = 'fehler_kurzbz'; + const RESOLVER_LIB_NAME = 'resolverLibName'; + const PRODUCER_IS_RESOLVER_NAME = 'producerIsResolver'; + const EXTENSION_NAME = 'extensionName'; + private $_ci; // ci instance private $_extensionName; // name of extension + private $_fehlercodes = []; // name of extension private $_codeLibMappings = []; // mappings for issues which explicitly defined resolver - private $_codeProducerLibMappings = []; // mappings for issues which are resolved with the same check as they are produced + private $_defaultIssueParams = ['issue_id' => 'issue_id', 'issue_person_id' => 'person_id', 'issue_oe_kurzbz' => 'oe_kurzbz']; public function __construct($params = null) { - // set extension name if called from extension - if (isset($params['extensionName'])) $this->_extensionName = $params['extensionName']; - if (isset($params['codeLibMappings'])) $this->_codeLibMappings = $params['codeLibMappings']; - if (isset($params['codeProducerLibMappings'])) $this->_codeProducerLibMappings = $params['codeProducerLibMappings']; + // get all fehler to be produced (by kurzbz array or app) + if (isset($params['fehlercodes']) && !isEmptyArray($params['fehlercodes'])) + { + $this->_fehlercodes = $params['fehlercodes']; + } $this->_ci =& get_instance(); // get ci instance $this->_ci->load->library('IssuesLib'); - $this->_ci->load->library('issues/PlausicheckProducerLib', ['extensionName' => $this->_extensionName, 'isForResolutionCheck' => true]); + $this->_ci->load->library('ExtensionsLib'); + + $this->_ci->load->config('fehler'); + + // Load Fehler Entries of Core + $configArray = $this->_ci->config->item(self::CONFIG_FEHLER_NAME); + + $fehlerKurzbzArr = []; + + foreach ($configArray as $coreEntry) + { + if (!isset($coreEntry[self::FEHLERCODE_NAME]) + || !in_array($coreEntry[self::FEHLERCODE_NAME], $this->_fehlercodes) + ) { + continue; + } + + if (isset($coreEntry[self::FEHLER_KURZBZ_NAME])) $fehlerKurzbzArr[] = $coreEntry[self::FEHLER_KURZBZ_NAME]; + + $this->_codeLibMappings[$coreEntry[self::FEHLERCODE_NAME]][self::RESOLVER_LIB_NAME] = $coreEntry[self::RESOLVER_LIB_NAME] ?? null; + $this->_codeLibMappings[$coreEntry[self::FEHLERCODE_NAME]][self::PRODUCER_IS_RESOLVER_NAME] + = $coreEntry[self::PRODUCER_IS_RESOLVER_NAME] ?? false; + } + + // load fehler entries of extensions + $extensions = $this->_ci->extensionslib->getInstalledExtensions(); + + if (hasData($extensions)) + { + $extensionArray = array(); + + $extensionsData = getData($extensions); + + foreach ($extensionsData as $ext) + { + $configFilename = APPPATH.'config/'.ExtensionsLib::EXTENSIONS_DIR_NAME.'/'.$ext->name.'/'.self::CONFIG_FEHLER_FILENAME; + + if (file_exists($configFilename)) + { + $config = array(); // default value + + include($configFilename); + + if (isset($config[self::CONFIG_FEHLER_NAME]) && is_array($config[self::CONFIG_FEHLER_NAME])) + { + foreach ($config[self::CONFIG_FEHLER_NAME] as $extensionEntry) + { + if ( + !isset($extensionEntry[self::FEHLERCODE_NAME]) + || !in_array($extensionEntry[self::FEHLERCODE_NAME], $this->_fehlercodes) + ) { + continue; + } + + $fehlercode = $extensionEntry[self::FEHLERCODE_NAME]; + if (isset($extensionEntry[self::FEHLER_KURZBZ_NAME])) $fehlerKurzbzArr[] = $extensionEntry[self::FEHLER_KURZBZ_NAME]; + + $this->_codeLibMappings[$fehlercode][self::RESOLVER_LIB_NAME] + = $extensionEntry[self::RESOLVER_LIB_NAME] ?? null; + $this->_codeLibMappings[$fehlercode][self::EXTENSION_NAME] = $ext->name; + $this->_codeLibMappings[$fehlercode][self::PRODUCER_IS_RESOLVER_NAME] + = $extensionEntry[self::PRODUCER_IS_RESOLVER_NAME] ?? false; + + } + } + } + } + } + + $this->_ci->load->library('issues/PlausicheckProducerLib', ['fehlerKurzbz' => $fehlerKurzbzArr]); } /** * Reseolves multiple plausicheck issues at once. - * @param array $codeLibMappings contains fehler type to check and library responsible for check (fehlercode => libName) * @param array $openIssues passed issues to resolve * @return result object with occured error and info */ @@ -40,12 +118,25 @@ class PlausicheckResolverLib $result->errors = []; $result->infos = []; + // check if all issues to resolve could be found in database + $mappingFehlerCodes = array_keys($this->_codeLibMappings); + $notFoundFehlerCodes = array_diff($this->_fehlercodes, $mappingFehlerCodes); + + if (!isEmptyArray($notFoundFehlerCodes)) + $result->errors[] = error('Fehler to resolve not defined in config: '.implode(', ', $notFoundFehlerCodes)); + foreach ($openIssues as $issue) { + $params = []; + foreach ($this->_defaultIssueParams as $index => $propertyName) + { + $params[$index] = $issue->{$propertyName}; + } + // add person id and oe kurzbz automatically as params, merge it with additional params // decode bewerbung_parameter into assoc array $params = array_merge( - array('issue_id' => $issue->issue_id, 'issue_person_id' => $issue->person_id, 'issue_oe_kurzbz' => $issue->oe_kurzbz), + $params, isset($issue->behebung_parameter) ? json_decode($issue->behebung_parameter, true) : array() ); @@ -54,69 +145,72 @@ class PlausicheckResolverLib // ignore if Fehlercode is not in libmappings (shouldn't be checked) if (isset($this->_codeLibMappings[$issue->fehlercode])) { - $libName = $this->_codeLibMappings[$issue->fehlercode]; + $codeLibMapping = $this->_codeLibMappings[$issue->fehlercode]; + $libName = $codeLibMapping[self::RESOLVER_LIB_NAME]; + $extensionName = $codeLibMapping[self::EXTENSION_NAME] ?? null; + $producerIsResolver = $codeLibMapping[self::PRODUCER_IS_RESOLVER_NAME] ?? false; - // if called from extension (extension name set), path includes extension names - $libRootPath = isset($this->_extensionName) ? self::EXTENSIONS_FOLDER . '/' . $this->_extensionName . '/' : ''; - - // path for loading issue library - $issuesLibPath = $libRootPath . self::ISSUE_RESOLVERS_FOLDER . '/'; - - // file path of library for check if file exists - $issuesLibFilePath = DOC_ROOT . self::CI_PATH - . '/' . $libRootPath . self::CI_LIBRARY_FOLDER . '/' . self::ISSUE_RESOLVERS_FOLDER . '/' . $libName . '.php'; - - // check if library file exists - if (!file_exists($issuesLibFilePath)) + if ($producerIsResolver) { - // log error and continue with next issue if not - $result->errors[] = "Issue library file " . $issuesLibFilePath . " does not exist"; - continue; - } + // execute same check as used for issue production + $issueResolvedRes = $this->_ci->plausicheckproducerlib->producePlausicheckIssue( + $issue->fehler_kurzbz, + $params + ); - // load library connected to fehlercode - $this->_ci->load->library($issuesLibPath . $libName); - - $lowercaseLibName = mb_strtolower($libName); - - // check if method is defined in library class - if (!is_callable(array($this->_ci->{$lowercaseLibName}, self::CHECK_ISSUE_RESOLVED_METHOD_NAME))) - { - // log error and continue with next issue if not - $result->errors[] = "Method " . self::CHECK_ISSUE_RESOLVED_METHOD_NAME . " is not defined in library $lowercaseLibName"; - continue; - } - - // call the function for checking for issue resolution - $issueResolvedRes = $this->_ci->{$lowercaseLibName}->{self::CHECK_ISSUE_RESOLVED_METHOD_NAME}($params); - - if (isError($issueResolvedRes)) - { - $result->errors[] = getError($issueResolvedRes); + if (isError($issueResolvedRes)) + { + $result->errors[] = getError($issueResolvedRes); + } + else + { + $issueResolved = !hasData($issueResolvedRes); + } } else { - $issueResolved = getData($issueResolvedRes) === true; - } - } - elseif (isset($this->_codeProducerLibMappings[$issue->fehlercode])) // check if it is an issue without explicit resolver, "self-resolving" - { - $libName = $this->_codeProducerLibMappings[$issue->fehlercode]; + // if called from extension (extension name set), path includes extension names + $libRootPath = isset($extensionName) ? self::EXTENSIONS_FOLDER . '/' . $extensionName . '/' : ''; - // execute same check as used for issue production - $issueResolvedRes = $this->_ci->plausicheckproducerlib->producePlausicheckIssue( - $libName, - $issue->fehler_kurzbz, - $params - ); + // path for loading issue library + $issuesLibPath = $libRootPath . self::ISSUE_RESOLVERS_FOLDER . '/'; - if (isError($issueResolvedRes)) - { - $result->errors[] = getError($issueResolvedRes); - } - else - { - $issueResolved = !hasData($issueResolvedRes); + // file path of library for check if file exists + $issuesLibFilePath = DOC_ROOT . self::CI_PATH + . '/' . $libRootPath . self::CI_LIBRARY_FOLDER . '/' . self::ISSUE_RESOLVERS_FOLDER . '/' . $libName . '.php'; + + // check if library file exists + if (!file_exists($issuesLibFilePath)) + { + // log error and continue with next issue if not + $result->errors[] = "Issue library file " . $issuesLibFilePath . " does not exist"; + continue; + } + + // load library connected to fehlercode + $this->_ci->load->library($issuesLibPath . $libName); + + $lowercaseLibName = mb_strtolower($libName); + + // check if method is defined in library class + if (!is_callable(array($this->_ci->{$lowercaseLibName}, self::CHECK_ISSUE_RESOLVED_METHOD_NAME))) + { + // log error and continue with next issue if not + $result->errors[] = "Method " . self::CHECK_ISSUE_RESOLVED_METHOD_NAME . " is not defined in library $lowercaseLibName"; + continue; + } + + // call the function for checking for issue resolution + $issueResolvedRes = $this->_ci->{$lowercaseLibName}->{self::CHECK_ISSUE_RESOLVED_METHOD_NAME}($params); + + if (isError($issueResolvedRes)) + { + $result->errors[] = getError($issueResolvedRes); + } + else + { + $issueResolved = getData($issueResolvedRes) === true; + } } } diff --git a/application/libraries/issues/plausichecks/PlausiChecker.php b/application/libraries/issues/plausichecks/PlausiChecker.php index 7e5fe7db0..ccc999874 100644 --- a/application/libraries/issues/plausichecks/PlausiChecker.php +++ b/application/libraries/issues/plausichecks/PlausiChecker.php @@ -5,12 +5,12 @@ */ abstract class PlausiChecker { + const ISSUE_ID_NAME = 'issue_id'; + protected $_ci; // code igniter instance protected $_config; // all applicable configuration parameters for this plausicheck protected $_db; // database for queries - protected $_isForResolutionCheck; // if true, additional parameters only needed for resolution are checked - protected $_config_params = []; // name of all config params which should be applied for this plausicheck, with sql [name] => [sql] protected $_params_for_checking = []; // name of all passed params for checking, with sql [name] => [sql] @@ -24,8 +24,6 @@ abstract class PlausiChecker // set configuration $this->_config = $params['configurationParams'] ?? []; - $this->_isForResolutionCheck = $params['isForResolutionCheck'] ?? false; - // get database for queries $this->_db = new DB_Model(); } @@ -41,15 +39,20 @@ abstract class PlausiChecker $params = []; $qry = $this->_base_sql; - if ($this->_isForResolutionCheck == true) + // if issue id is set, issue is resolving - check if behebung parameter are present + if (isset($paramsForChecking[self::ISSUE_ID_NAME])) { foreach ($this->_resolution_params as $resParam) { if (!isset($paramsForChecking[$resParam])) - return error("$resParam missing".(isset($paramsForChecking['issue_id']) ? ", issue ID: ".$paramsForChecking['issue_id'] : "")); + return error("$resParam missing" + .(isset($paramsForChecking[self::ISSUE_ID_NAME]) ? ", issue ID: ".$paramsForChecking[self::ISSUE_ID_NAME] : "")); } } + // get fehlertext and resolution params + + // add config params to query if (isset($this->_config_params) && !isEmptyArray($this->_config_params)) { diff --git a/application/models/system/Fehlerkonfiguration_model.php b/application/models/system/Fehlerkonfiguration_model.php index bf8de4cde..442c8212f 100644 --- a/application/models/system/Fehlerkonfiguration_model.php +++ b/application/models/system/Fehlerkonfiguration_model.php @@ -18,14 +18,16 @@ class Fehlerkonfiguration_model extends DB_Model * @param string $app * @return object success or error */ - public function getKonfiguration($app = null) + public function getKonfiguration($apps = null) { $fehlerkonfiguration = array(); + $apps = is_string($apps) ? [$apps] : $apps; $this->addSelect('fehlercode, konfigurationstyp_kurzbz, konfiguration, fehler_kurzbz'); $this->addJoin('system.tbl_fehler_konfigurationstyp konftyp', 'konfigurationstyp_kurzbz'); $this->addJoin('system.tbl_fehler fehler', 'fehlercode'); - $fehlerkonfigurationRes = isset($app) ? $this->loadWhere(array('fehler.app' => $app)) : $this->load(); + if (is_array($apps) && !isEmptyArray($apps)) $this->db->where_in('fehler.app', $apps); + $fehlerkonfigurationRes = $this->load(); if (isError($fehlerkonfigurationRes)) return $fehlerkonfigurationRes;