From 4f2ca62d05eeead90bb89706d82f0a3f83875b09 Mon Sep 17 00:00:00 2001 From: KarpAlex Date: Thu, 23 Feb 2023 19:27:45 +0100 Subject: [PATCH 01/20] Issues: enabled extensions to produce own plausichecks, IssueResolver: moved directory names to constants, deleted unused IIssueExistsChecker --- .../controllers/jobs/PlausiIssueProducer.php | 56 ++------------- .../system/issues/Plausichecks.php | 13 ++-- application/core/IIssueExistsChecker.php | 21 ------ application/core/IssueResolver_Controller.php | 15 +++- .../core/PlausiIssueProducer_Controller.php | 66 ++++++++++++++++++ .../issues/PlausicheckDefinitionLib.php | 55 +++++++++++++++ .../libraries/issues/PlausicheckLib.php | 3 + .../issues/PlausicheckProducerLib.php | 68 ++++++------------- 8 files changed, 172 insertions(+), 125 deletions(-) delete mode 100644 application/core/IIssueExistsChecker.php create mode 100644 application/core/PlausiIssueProducer_Controller.php create mode 100644 application/libraries/issues/PlausicheckDefinitionLib.php diff --git a/application/controllers/jobs/PlausiIssueProducer.php b/application/controllers/jobs/PlausiIssueProducer.php index 943d7aa46..e94cd93dc 100644 --- a/application/controllers/jobs/PlausiIssueProducer.php +++ b/application/controllers/jobs/PlausiIssueProducer.php @@ -1,62 +1,18 @@ load->library('issues/PlausicheckProducerLib'); - $this->load->library('IssuesLib'); - } + $this->load->library('issues/PlausicheckDefinitionLib'); - /** - * Runs issue production job. - * @param studiensemester_kurzbz string job is run for students of a certain semester. - * @param studiengang_kz int job is run for students of certain Studiengang. - */ - public function run($studiensemester_kurzbz = null, $studiengang_kz = null) - { - $fehlerKurzbz = $this->plausicheckproducerlib->getFehlerKurzbz(); - - $this->logInfo("Plausicheck issue producer job started"); - - // get the data returned by Plausicheck - foreach ($fehlerKurzbz as $fehler_kurzbz) - { - // execute the check - $this->logInfo("Checking " . $fehler_kurzbz . "..."); - $plausicheckRes = $this->plausicheckproducerlib->producePlausicheckIssue($fehler_kurzbz, $studiensemester_kurzbz, $studiengang_kz); - - if (isError($plausicheckRes)) $this->logError(getError($plausicheckRes)); - - if (hasData($plausicheckRes)) - { - $plausicheckData = getData($plausicheckRes); - - foreach ($plausicheckData as $plausiData) - { - // get the data needed for issue production - $person_id = isset($plausiData['person_id']) ? $plausiData['person_id'] : null; - $oe_kurzbz = isset($plausiData['oe_kurzbz']) ? $plausiData['oe_kurzbz'] : null; - $fehlertext_params = isset($plausiData['fehlertext_params']) ? $plausiData['fehlertext_params'] : null; - $resolution_params = isset($plausiData['resolution_params']) ? $plausiData['resolution_params'] : null; - - // write the issue - $addIssueRes = $this->issueslib->addFhcIssue($fehler_kurzbz, $person_id, $oe_kurzbz, $fehlertext_params, $resolution_params); - - // log if error, or log info if inserted new issue - if (isError($addIssueRes)) - $this->logError(getError($addIssueRes)); - elseif (hasData($addIssueRes) && is_integer(getData($addIssueRes))) - $this->logInfo("Plausicheck issue " . $fehler_kurzbz . " successfully produced, person_id: " . $person_id); - } - } - } - - $this->logInfo("Plausicheck issue producer job stopped"); + // set fehler which can be produced by the job + // structure: fehler_kurzbz => class (library) name for resolving + $this->_fehlerLibMappings = $this->plausicheckdefinitionlib->getFehlerLibMappings(); } } diff --git a/application/controllers/system/issues/Plausichecks.php b/application/controllers/system/issues/Plausichecks.php index 748361321..ba7839bc4 100644 --- a/application/controllers/system/issues/Plausichecks.php +++ b/application/controllers/system/issues/Plausichecks.php @@ -15,6 +15,7 @@ class Plausichecks extends Auth_Controller // Load libraries $this->load->library('issues/PlausicheckProducerLib'); + $this->load->library('issues/PlausicheckDefinitionLib'); $this->load->library('WidgetLib'); // Load models @@ -44,16 +45,20 @@ class Plausichecks extends Auth_Controller // issues array for passing issue texts $issueTexts = array(); // all fehler kurzbz which are going to be checked - $fehlerKurzbz = !isEmptyString($fehler_kurzbz) ? array($fehler_kurzbz) : $this->plausicheckproducerlib->getFehlerKurzbz(); + $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; // get the data returned by Plausicheck foreach ($fehlerKurzbz as $fehler_kurzbz) { - // execute the check $issueTexts[$fehler_kurzbz] = array(); - $plausicheckRes = $this->plausicheckproducerlib->producePlausicheckIssue($fehler_kurzbz, $studiensemester_kurzbz, $studiengang_kz); + // get library name for producing issue + $libName = $fehlerLibMappings[$fehler_kurzbz]; + + // execute the check + $plausicheckRes = $this->plausicheckproducerlib->producePlausicheckIssue($libName, $studiensemester_kurzbz, $studiengang_kz); if (isError($plausicheckRes)) $this->terminateWithJsonError(getError($plausicheckRes)); @@ -121,7 +126,7 @@ class Plausichecks extends Auth_Controller if (isError($studiengaengeRes)) show_error(getError($studiengaengeRes)); - $fehlerKurzbz = $this->plausicheckproducerlib->getFehlerKurzbz(); + $fehlerKurzbz = $this->plausicheckdefinitionlib->getFehlerKurzbz(); return array( 'semester' => hasData($studiensemesterRes) ? getData($studiensemesterRes) : array(), diff --git a/application/core/IIssueExistsChecker.php b/application/core/IIssueExistsChecker.php deleted file mode 100644 index 7f5a6b6e5..000000000 --- a/application/core/IIssueExistsChecker.php +++ /dev/null @@ -1,21 +0,0 @@ -behebung_parameter) ? json_decode($issue->behebung_parameter, true) : array() ); - // if called from extension (extension name set), path includes extension names, otherwise it is the core library folder - $libRootPath = isset($this->_extensionName) ? 'extensions/' . $this->_extensionName . '/' : ''; + // TODO: what if extension/library folder changes? + + // 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 . '/'; - $issuesLibFilePath = DOC_ROOT . self::CI_PATH . '/' . $libRootPath . 'libraries/' . self::ISSUE_RESOLVERS_FOLDER . '/' . $libName . '.php'; + + // 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)) diff --git a/application/core/PlausiIssueProducer_Controller.php b/application/core/PlausiIssueProducer_Controller.php new file mode 100644 index 000000000..b12f2481d --- /dev/null +++ b/application/core/PlausiIssueProducer_Controller.php @@ -0,0 +1,66 @@ +load->library('issues/PlausicheckProducerLib'); + $this->load->library('IssuesLib'); + } + + /** + * Runs issue production job. + * @param studiensemester_kurzbz string job is run for students of a certain semester. + * @param studiengang_kz int job is run for students of certain Studiengang. + */ + public function run($studiensemester_kurzbz = null, $studiengang_kz = null) + { + $this->logInfo("Plausicheck issue producer job started"); + + // get the data returned by Plausicheck + foreach ($this->_fehlerLibMappings as $fehler_kurzbz => $libName) + { + // execute the check + $this->logInfo("Checking " . $fehler_kurzbz . "..."); + $plausicheckRes = $this->plausicheckproducerlib->producePlausicheckIssue( + $libName, + $studiensemester_kurzbz, + $studiengang_kz + ); + + if (isError($plausicheckRes)) $this->logError(getError($plausicheckRes)); + + if (hasData($plausicheckRes)) + { + $plausicheckData = getData($plausicheckRes); + + foreach ($plausicheckData as $plausiData) + { + // get the data needed for issue production + $person_id = isset($plausiData['person_id']) ? $plausiData['person_id'] : null; + $oe_kurzbz = isset($plausiData['oe_kurzbz']) ? $plausiData['oe_kurzbz'] : null; + $fehlertext_params = isset($plausiData['fehlertext_params']) ? $plausiData['fehlertext_params'] : null; + $resolution_params = isset($plausiData['resolution_params']) ? $plausiData['resolution_params'] : null; + + // write the issue + $addIssueRes = $this->issueslib->addFhcIssue($fehler_kurzbz, $person_id, $oe_kurzbz, $fehlertext_params, $resolution_params); + + // log if error, or log info if inserted new issue + if (isError($addIssueRes)) + $this->logError(getError($addIssueRes)); + elseif (hasData($addIssueRes) && is_integer(getData($addIssueRes))) + $this->logInfo("Plausicheck issue " . $fehler_kurzbz . " successfully produced, person_id: " . $person_id); + } + } + } + + $this->logInfo("Plausicheck issue producer job stopped"); + } +} diff --git a/application/libraries/issues/PlausicheckDefinitionLib.php b/application/libraries/issues/PlausicheckDefinitionLib.php new file mode 100644 index 000000000..63fd6f570 --- /dev/null +++ b/application/libraries/issues/PlausicheckDefinitionLib.php @@ -0,0 +1,55 @@ + class (library) name for resolving + private $_fehlerLibMappings = array( + 'AbbrecherAktiv' => 'AbbrecherAktiv', + 'AbschlussstatusFehlt' => 'AbschlussstatusFehlt', + 'AktSemesterNull' => 'AktSemesterNull', + 'AktiverStudentOhneStatus' => 'AktiverStudentOhneStatus', + 'AusbildungssemPrestudentUngleichAusbildungssemStatus' => 'AusbildungssemPrestudentUngleichAusbildungssemStatus', + 'BewerberNichtZumRtAngetreten' => 'BewerberNichtZumRtAngetreten', + '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' + //'StudienplanUngueltig' => 'StudienplanUngueltig' + ); + + /** + * Gets all fehler_kurzbz 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); + } +} diff --git a/application/libraries/issues/PlausicheckLib.php b/application/libraries/issues/PlausicheckLib.php index 5105169dd..e98070596 100644 --- a/application/libraries/issues/PlausicheckLib.php +++ b/application/libraries/issues/PlausicheckLib.php @@ -2,6 +2,9 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); +/** + * Library containing database queries for execution of core plausichecks. + */ class PlausicheckLib { private $_ci; // Code igniter instance diff --git a/application/libraries/issues/PlausicheckProducerLib.php b/application/libraries/issues/PlausicheckProducerLib.php index c1e15151f..3297ecd1d 100644 --- a/application/libraries/issues/PlausicheckProducerLib.php +++ b/application/libraries/issues/PlausicheckProducerLib.php @@ -4,43 +4,15 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); class PlausicheckProducerLib { - const CI_LIBRARY_PATH = 'application/libraries'; + const CI_PATH = 'application'; + const CI_LIBRARY_FOLDER = 'libraries'; + const EXTENSIONS_FOLDER = 'extensions'; const PLAUSI_ISSUES_FOLDER = 'issues/plausichecks'; const EXECUTE_PLAUSI_CHECK_METHOD_NAME = 'executePlausiCheck'; private $_ci; // ci instance private $_currentStudiensemester; // current Studiensemester - // set fehler which can be produced by the job - // structure: fehler_kurzbz => class (library) name for resolving - private $_fehlerLibMappings = array( - 'AbbrecherAktiv' => 'AbbrecherAktiv', - 'AbschlussstatusFehlt' => 'AbschlussstatusFehlt', - 'AktSemesterNull' => 'AktSemesterNull', - 'AktiverStudentOhneStatus' => 'AktiverStudentOhneStatus', - 'AusbildungssemPrestudentUngleichAusbildungssemStatus' => 'AusbildungssemPrestudentUngleichAusbildungssemStatus', - 'BewerberNichtZumRtAngetreten' => 'BewerberNichtZumRtAngetreten', - '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' - //'StudienplanUngueltig' => 'StudienplanUngueltig' - ); - public function __construct() { $this->_ci =& get_instance(); // get ci instance @@ -54,27 +26,37 @@ class PlausicheckProducerLib } /** - * Executes check for a fehler_kurzbz, returns the result. - * @param $fehler_kurzbz string + * Executes plausicheck using a given library, returns the result. + * @param $libName string * @param $studiensemester_kurzbz string optionally needed for issue production * @param $studiengang_kz int optionally needed for issue production */ - public function producePlausicheckIssue($fehler_kurzbz, $studiensemester_kurzbz = null, $studiengang_kz = null) + public function producePlausicheckIssue($libName, $studiensemester_kurzbz = null, $studiengang_kz = null) { - $libName = $this->_fehlerLibMappings[$fehler_kurzbz]; - // get Studiensemester if (isEmptyString($studiensemester_kurzbz)) $studiensemester_kurzbz = $this->_currentStudiensemester; + // 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::PLAUSI_ISSUES_FOLDER . '/'; + + // file path of library for check if file exists + $issuesLibFilePath = DOC_ROOT . self::CI_PATH + . '/' . $libRootPath . self::CI_LIBRARY_FOLDER . '/' . self::PLAUSI_ISSUES_FOLDER . '/' . $libName . '.php'; + // get path of library for issue to be produced - $issuesLibPath = DOC_ROOT . self::CI_LIBRARY_PATH . '/' . self::PLAUSI_ISSUES_FOLDER . '/'; - $issuesLibFilePath = $issuesLibPath . $libName . '.php'; + + //~ $issuesLibPath = DOC_ROOT . self::CI_LIBRARY_PATH . '/' . self::PLAUSI_ISSUES_FOLDER . '/'; + //~ $issuesLibFilePath = $issuesLibPath . $libName . '.php'; // check if library file exists if (!file_exists($issuesLibFilePath)) return error("Issue library file " . $issuesLibFilePath . " does not exist"); // load library connected to fehlercode - $this->_ci->load->library(self::PLAUSI_ISSUES_FOLDER . '/'.$libName); + //$this->_ci->load->library(self::PLAUSI_ISSUES_FOLDER . '/'.$libName); + $this->_ci->load->library($issuesLibPath . $libName); $lowercaseLibName = mb_strtolower($libName); @@ -91,12 +73,4 @@ class PlausicheckProducerLib // call the function for checking for issue production return $this->_ci->{$lowercaseLibName}->{self::EXECUTE_PLAUSI_CHECK_METHOD_NAME}($paramsForCheck); } - - /** - * Gets all fehler_kurzbz for fehler which need to be checked. - */ - public function getFehlerKurzbz() - { - return array_keys($this->_fehlerLibMappings); - } } From a667ddaf5e83dd361e0e1eeb70106bbbc5b9e1cb Mon Sep 17 00:00:00 2001 From: KarpAlex Date: Fri, 24 Feb 2023 13:32:37 +0100 Subject: [PATCH 02/20] Plausichecks: removed/changed comments --- application/core/IssueResolver_Controller.php | 2 -- application/libraries/issues/PlausicheckDefinitionLib.php | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/application/core/IssueResolver_Controller.php b/application/core/IssueResolver_Controller.php index 07210a2c9..758064ed8 100755 --- a/application/core/IssueResolver_Controller.php +++ b/application/core/IssueResolver_Controller.php @@ -62,8 +62,6 @@ abstract class IssueResolver_Controller extends JOB_Controller isset($issue->behebung_parameter) ? json_decode($issue->behebung_parameter, true) : array() ); - // TODO: what if extension/library folder changes? - // if called from extension (extension name set), path includes extension names $libRootPath = isset($this->_extensionName) ? self::EXTENSIONS_FOLDER . '/' . $this->_extensionName . '/' : ''; diff --git a/application/libraries/issues/PlausicheckDefinitionLib.php b/application/libraries/issues/PlausicheckDefinitionLib.php index 63fd6f570..cef28a736 100644 --- a/application/libraries/issues/PlausicheckDefinitionLib.php +++ b/application/libraries/issues/PlausicheckDefinitionLib.php @@ -38,7 +38,7 @@ class PlausicheckDefinitionLib ); /** - * Gets all fehler_kurzbz for fehler which need to be checked. + * Gets all fehler_kurzbz-library mappings for fehler which need to be checked. */ public function getFehlerLibMappings() { From 601eae1e95f8cf53b91347d0e7348f0998151537 Mon Sep 17 00:00:00 2001 From: KarpAlex Date: Fri, 24 Feb 2023 17:43:36 +0100 Subject: [PATCH 03/20] extension plausicheck bugfix: extension name is correctly passed to plausicheckproducerlib --- application/core/PlausiIssueProducer_Controller.php | 5 ++++- application/libraries/issues/PlausicheckProducerLib.php | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/application/core/PlausiIssueProducer_Controller.php b/application/core/PlausiIssueProducer_Controller.php index b12f2481d..e6d47297c 100644 --- a/application/core/PlausiIssueProducer_Controller.php +++ b/application/core/PlausiIssueProducer_Controller.php @@ -11,7 +11,10 @@ abstract class PlausiIssueProducer_Controller extends JOB_Controller { parent::__construct(); - $this->load->library('issues/PlausicheckProducerLib'); + // pass extension name if calling from extension + $extensionName = isset($this->_extensionName) ? $this->_extensionName : null; + + $this->load->library('issues/PlausicheckProducerLib', array('extensionName' => $extensionName)); $this->load->library('IssuesLib'); } diff --git a/application/libraries/issues/PlausicheckProducerLib.php b/application/libraries/issues/PlausicheckProducerLib.php index 3297ecd1d..2f3e03f04 100644 --- a/application/libraries/issues/PlausicheckProducerLib.php +++ b/application/libraries/issues/PlausicheckProducerLib.php @@ -12,9 +12,13 @@ class PlausicheckProducerLib private $_ci; // ci instance private $_currentStudiensemester; // current Studiensemester + private $_extensionName; - public function __construct() + public function __construct($params = null) { + // set extension name if called from extension + if (isset($params['extensionName'])) $this->_extensionName = $params['extensionName']; + $this->_ci =& get_instance(); // get ci instance // load models From a1a9b10ee1fe483c98a934346f5b4adc6ec2eebc Mon Sep 17 00:00:00 2001 From: KarpAlex Date: Tue, 4 Apr 2023 16:17:18 +0200 Subject: [PATCH 04/20] plausicheck issues: enabled generic passing of different parameters, not just core plausicheck specific. moved studiensemester param to specific PlausiIssueProducer controller --- .../controllers/jobs/PlausiIssueProducer.php | 23 ++++++++++++++++ .../core/PlausiIssueProducer_Controller.php | 11 +++----- .../issues/PlausicheckProducerLib.php | 27 ++----------------- 3 files changed, 28 insertions(+), 33 deletions(-) diff --git a/application/controllers/jobs/PlausiIssueProducer.php b/application/controllers/jobs/PlausiIssueProducer.php index e94cd93dc..9e6ef1884 100644 --- a/application/controllers/jobs/PlausiIssueProducer.php +++ b/application/controllers/jobs/PlausiIssueProducer.php @@ -5,14 +5,37 @@ */ class PlausiIssueProducer extends PlausiIssueProducer_Controller { + private $_currentStudiensemester; + public function __construct() { parent::__construct(); $this->load->library('issues/PlausicheckDefinitionLib'); + // load models + $this->load->model('organisation/studiensemester_model', 'StudiensemesterModel'); + + // get current Studiensemester + $studiensemesterRes = $this->StudiensemesterModel->getAkt(); + if (hasData($studiensemesterRes)) $this->_currentStudiensemester = getData($studiensemesterRes)[0]->studiensemester_kurzbz; + // set fehler which can be produced by the job // structure: fehler_kurzbz => class (library) name for resolving $this->_fehlerLibMappings = $this->plausicheckdefinitionlib->getFehlerLibMappings(); } + + /** + * Runs issue production job. + * @param studiensemester_kurzbz string job is run for students of a certain semester. + * @param studiengang_kz int job is run for students of certain Studiengang. + */ + public function run($studiensemester_kurzbz = null, $studiengang_kz = null) + { + // get Studiensemester + if (isEmptyString($studiensemester_kurzbz)) $studiensemester_kurzbz = $this->_currentStudiensemester; + + // producing issues for semester and optionally Studiengang + $this->producePlausicheckIssues(array('studiensemester_kurzbz' => $studiensemester_kurzbz, 'studiengang_kz' => $studiengang_kz)); + } } diff --git a/application/core/PlausiIssueProducer_Controller.php b/application/core/PlausiIssueProducer_Controller.php index e6d47297c..16d01e787 100644 --- a/application/core/PlausiIssueProducer_Controller.php +++ b/application/core/PlausiIssueProducer_Controller.php @@ -14,16 +14,12 @@ abstract class PlausiIssueProducer_Controller extends JOB_Controller // pass extension name if calling from extension $extensionName = isset($this->_extensionName) ? $this->_extensionName : null; + // load libraries $this->load->library('issues/PlausicheckProducerLib', array('extensionName' => $extensionName)); $this->load->library('IssuesLib'); } - /** - * Runs issue production job. - * @param studiensemester_kurzbz string job is run for students of a certain semester. - * @param studiengang_kz int job is run for students of certain Studiengang. - */ - public function run($studiensemester_kurzbz = null, $studiengang_kz = null) + protected function producePlausicheckIssues($params) { $this->logInfo("Plausicheck issue producer job started"); @@ -34,8 +30,7 @@ abstract class PlausiIssueProducer_Controller extends JOB_Controller $this->logInfo("Checking " . $fehler_kurzbz . "..."); $plausicheckRes = $this->plausicheckproducerlib->producePlausicheckIssue( $libName, - $studiensemester_kurzbz, - $studiengang_kz + $params ); if (isError($plausicheckRes)) $this->logError(getError($plausicheckRes)); diff --git a/application/libraries/issues/PlausicheckProducerLib.php b/application/libraries/issues/PlausicheckProducerLib.php index 2f3e03f04..c726fa6da 100644 --- a/application/libraries/issues/PlausicheckProducerLib.php +++ b/application/libraries/issues/PlausicheckProducerLib.php @@ -11,7 +11,6 @@ class PlausicheckProducerLib const EXECUTE_PLAUSI_CHECK_METHOD_NAME = 'executePlausiCheck'; private $_ci; // ci instance - private $_currentStudiensemester; // current Studiensemester private $_extensionName; public function __construct($params = null) @@ -20,13 +19,6 @@ class PlausicheckProducerLib if (isset($params['extensionName'])) $this->_extensionName = $params['extensionName']; $this->_ci =& get_instance(); // get ci instance - - // load models - $this->_ci->load->model('organisation/studiensemester_model', 'StudiensemesterModel'); - - // get current Studiensemester - $studiensemesterRes = $this->_ci->StudiensemesterModel->getAkt(); - if (hasData($studiensemesterRes)) $this->_currentStudiensemester = getData($studiensemesterRes)[0]->studiensemester_kurzbz; } /** @@ -35,11 +27,8 @@ class PlausicheckProducerLib * @param $studiensemester_kurzbz string optionally needed for issue production * @param $studiengang_kz int optionally needed for issue production */ - public function producePlausicheckIssue($libName, $studiensemester_kurzbz = null, $studiengang_kz = null) + public function producePlausicheckIssue($libName, $params) { - // get Studiensemester - if (isEmptyString($studiensemester_kurzbz)) $studiensemester_kurzbz = $this->_currentStudiensemester; - // if called from extension (extension name set), path includes extension names $libRootPath = isset($this->_extensionName) ? self::EXTENSIONS_FOLDER . '/' . $this->_extensionName . '/' : ''; @@ -50,16 +39,10 @@ class PlausicheckProducerLib $issuesLibFilePath = DOC_ROOT . self::CI_PATH . '/' . $libRootPath . self::CI_LIBRARY_FOLDER . '/' . self::PLAUSI_ISSUES_FOLDER . '/' . $libName . '.php'; - // get path of library for issue to be produced - - //~ $issuesLibPath = DOC_ROOT . self::CI_LIBRARY_PATH . '/' . self::PLAUSI_ISSUES_FOLDER . '/'; - //~ $issuesLibFilePath = $issuesLibPath . $libName . '.php'; - // check if library file exists if (!file_exists($issuesLibFilePath)) return error("Issue library file " . $issuesLibFilePath . " does not exist"); // load library connected to fehlercode - //$this->_ci->load->library(self::PLAUSI_ISSUES_FOLDER . '/'.$libName); $this->_ci->load->library($issuesLibPath . $libName); $lowercaseLibName = mb_strtolower($libName); @@ -68,13 +51,7 @@ class PlausicheckProducerLib if (!is_callable(array($this->_ci->{$lowercaseLibName}, self::EXECUTE_PLAUSI_CHECK_METHOD_NAME))) return error("Method " . self::EXECUTE_PLAUSI_CHECK_METHOD_NAME . " is not defined in library $lowercaseLibName"); - // pass the data needed for issue check - $paramsForCheck = array( - 'studiensemester_kurzbz' => $studiensemester_kurzbz, - 'studiengang_kz' => $studiengang_kz - ); - // call the function for checking for issue production - return $this->_ci->{$lowercaseLibName}->{self::EXECUTE_PLAUSI_CHECK_METHOD_NAME}($paramsForCheck); + return $this->_ci->{$lowercaseLibName}->{self::EXECUTE_PLAUSI_CHECK_METHOD_NAME}($params); } } From a63a79ab91a2a2233e974328ad0e7ff0efc327ae Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Fri, 7 Apr 2023 14:10:30 +0200 Subject: [PATCH 05/20] add param tableOnly & save for multiple components on one page --- public/js/components/filter/Filter.js | 247 +++++++++++++++----------- 1 file changed, 142 insertions(+), 105 deletions(-) diff --git a/public/js/components/filter/Filter.js b/public/js/components/filter/Filter.js index e153042ad..7a46fd629 100644 --- a/public/js/components/filter/Filter.js +++ b/public/js/components/filter/Filter.js @@ -23,6 +23,8 @@ import {CoreFetchCmpt} from '../../components/Fetch.js'; const FILTER_COMPONENT_NEW_FILTER = 'Filter Component New Filter'; const FILTER_COMPONENT_NEW_FILTER_TYPE = 'Filter Component New Filter Type'; +var _uuid = 0; + /** * */ @@ -42,10 +44,12 @@ export const CoreFilterCmpt = { required: true }, tabulatorOptions: Object, - tabulatorEvents: Array + tabulatorEvents: Array, + tableOnly: Boolean }, data: function() { return { + uuid: 0, // FilterCmpt properties filterName: null, fields: null, @@ -54,7 +58,6 @@ export const CoreFilterCmpt = { selectedFields: null, notSelectedFields: null, filterFields: null, - columnsAlias: null, availableFilters: null, @@ -64,104 +67,136 @@ export const CoreFilterCmpt = { fetchCmptApiFunctionParams: null, fetchCmptDataFetched: null, - tabulator: null + tabulator: null, + tableBuilt: false }; }, - created: function() { - this.getFilter(); // get the filter data - }, - updated: function() { - // - let dataset = JSON.parse(JSON.stringify(this.dataset)); - let fields = JSON.parse(JSON.stringify(this.fields)); - let selectedFields = JSON.parse(JSON.stringify(this.selectedFields)); + computed: { + filteredData() { + if (!this.dataset) + return []; + return JSON.parse(JSON.stringify(this.dataset)); + }, + filteredColumns() { + let fields = JSON.parse(JSON.stringify(this.fields)) || []; + let selectedFields = JSON.parse(JSON.stringify(this.selectedFields)) || []; - // - let columns = null; + let columns = null; - // If the tabulator options has been provided and it contains the property columns - if (this.tabulatorOptions != null && this.tabulatorOptions.hasOwnProperty('columns')) - { - columns = this.tabulatorOptions.columns; - } + // If the tabulator options has been provided and it contains the property columns + if (this.tabulatorOptions && this.tabulatorOptions.hasOwnProperty('columns')) + columns = this.tabulatorOptions.columns; - // If columns is not an array or it is an array with less elements then the array fields - if (!Array.isArray(columns) || (Array.isArray(columns) && columns.length < fields.length)) - { - columns = []; // set it as an empty array - - // Loop throught all the retrieved columns from database - for (let i = 0; i < fields.length; i++) + // If columns is not an array or it is an array with less elements then the array fields + if (!Array.isArray(columns) || (Array.isArray(columns) && columns.length < fields.length)) { - // Create a new column having the title equal to the field name - let column = { - title: fields[i], - field: fields[i] - }; + columns = []; // set it as an empty array - // If the column has to be displayed or not - selectedFields.indexOf(fields[i]) >= 0 ? column.visible = true : column.visible = false; - - // Add the new column to the list of columns - columns.push(column); - } - } - else // the property columns has been provided in the tabulator options - { - // Loop throught the property columns of the tabulator options - for (let i = 0; i < columns.length; i++) - { - // If the column has to be displayed or not - selectedFields.indexOf(columns[i].field) >= 0 ? columns[i].visible = true : columns[i].visible = false; - - if (columns[i].hasOwnProperty('resizable')) + // Loop throught all the retrieved columns from database + for (let field of fields) { - columns[i].visible ? columns[i].resizable = true : columns[i].resizable = false; - } + // Create a new column having the title equal to the field name + let column = { + title: field, + field: field + }; + + // If the column has to be displayed or not + column.visible = selectedFields.indexOf(field) >= 0; + + // Add the new column to the list of columns + columns.push(column); + } } - } - - this.columnsAlias = columns; - - // Define a default tabulator options in case it was not provided - let tabulatorOptions = { - height: 500, - layout: "fitColumns", - movableColumns: true, - reactiveData: true, - columns: columns, - data: JSON.parse(JSON.stringify(this.dataset)) - }; - - // If it was provided - if (this.tabulatorOptions != null) - { - // Then copy it... - tabulatorOptions = this.tabulatorOptions; - // ...and overwrite the properties data, reactiveData, movableColumns and columns - tabulatorOptions.data = JSON.parse(JSON.stringify(this.dataset)); - tabulatorOptions.columns = columns; - tabulatorOptions.reactiveData = true; - tabulatorOptions.movableColumns = true; - } - - // Start the tabulator with the buid options - this.tabulator = new Tabulator( - "#filterTableDataset", - tabulatorOptions - ); - - // If event handlers have been provided - if (Array.isArray(this.tabulatorEvents) && this.tabulatorEvents.length > 0) - { - // Attach all the provided event handlers to the started tabulator - for (let i = 0; i < this.tabulatorEvents.length; i++) + else // the property columns has been provided in the tabulator options { - this.tabulator.on(this.tabulatorEvents[i].event, this.tabulatorEvents[i].handler); + // Loop throught the property columns of the tabulator options + for (let col of columns) + { + // If the column has to be displayed or not + col.visible = selectedFields.indexOf(col.field) >= 0; + + if (col.hasOwnProperty('resizable')) + col.resizable = col.visible; + } } + + return columns; + }, + fieldNames() { + if (!this.tableBuilt) + return {}; + return this.tabulator.getColumns().reduce((res, col) => { + res[col.getField()] = col.getDefinition().title; + return res; + }, {}); + }, + idExtra() { + if (!this.uuid) + return ''; + return '-' + this.uuid; } }, + beforeCreate() { + if (!this.tableOnly == !this.filterType) + console.warn('You can not have a filter-type in table-only mode!'); + }, + created() { + this.uuid = _uuid++; + if (!this.tableOnly) + this.getFilter(); // get the filter data + }, + mounted() { + this.initTabulator(); + }, methods: { + initTabulator() { + // Define a default tabulator options in case it was not provided + let tabulatorOptions = {...{ + height: 500, + layout: "fitColumns", + movableColumns: true, + reactiveData: true + }, ...(this.tabulatorOptions || {})}; + + if (!this.tableOnly) { + tabulatorOptions.data = this.filteredData; + tabulatorOptions.columns = this.filteredColumns; + } + + // Start the tabulator with the build options + this.tabulator = new Tabulator( + this.$refs.table, + tabulatorOptions + ); + // If event handlers have been provided + if (Array.isArray(this.tabulatorEvents) && this.tabulatorEvents.length > 0) + { + // Attach all the provided event handlers to the started tabulator + for (let evt of this.tabulatorEvents) + this.tabulator.on(evt.event, evt.handler); + } + this.tabulator.on('tableBuilt', () => this.tableBuilt = true); + if (this.tableOnly) { + this.tabulator.on('tableBuilt', () => { + const cols = this.tabulator.getColumns(); + this.fields = cols.map(col => col.getField()); + this.selectedFields = cols.filter(col => col.isVisible()).map(col => col.getField()); + }); + } + }, + updateTabulator() { + if (this.tabulator) { + if (this.tableBuilt) + this._updateTabulator(); + else + this.tabulator.on('tableBuilt', this._updateTabulator); + } + }, + _updateTabulator() { + this.tabulator.setData(this.filteredData); + this.tabulator.setColumns(this.filteredColumns); + }, /** * */ @@ -209,6 +244,7 @@ export const CoreFilterCmpt = { { this.setDropDownMenu(data); } + this.updateTabulator(); } else { @@ -335,7 +371,7 @@ export const CoreFilterCmpt = { this.startFetchCmpt( CoreFilterAPIs.saveCustomFilter, { - customFilterName: document.getElementById('customFilterName').value + customFilterName: this.$refscustomFilterName.value }, this.getFilter ); @@ -463,22 +499,22 @@ export const CoreFilterCmpt = { /* * */ - handlerToggleSelectedField: function(event) { + handlerToggleSelectedField(field) { // If it is a selected field - if (this.selectedFields.indexOf(event.target.innerText) != -1) + if (this.selectedFields.indexOf(field) != -1) { // then hide it - this.tabulator.hideColumn(event.target.innerText); + this.tabulator.hideColumn(field); // and remove it from the this.selectedFields property - this.selectedFields.splice(this.selectedFields.indexOf(event.target.innerText), 1); + this.selectedFields.splice(this.selectedFields.indexOf(field), 1); } else // otherwise { // show it - this.tabulator.showColumn(event.target.innerText); + this.tabulator.showColumn(field); // and add it to the this.selectedFields property - this.selectedFields.push(event.target.innerText); + this.selectedFields.push(field); } }, /** @@ -527,6 +563,7 @@ export const CoreFilterCmpt = { template: ` -
+
- [ {{ filterName }} ] - - + [ {{ filterName }} ] + +
-
+
@@ -558,9 +595,9 @@ export const CoreFilterCmpt = {
- {{ fieldToDisplay }} + {{ fieldNames[fieldToDisplay] || fieldToDisplay }}
@@ -568,7 +605,7 @@ export const CoreFilterCmpt = {
-
+
@@ -591,7 +628,7 @@ export const CoreFilterCmpt = {
-
+