From d5eff7d6154e94e42a00b8164553c337fb6f7a49 Mon Sep 17 00:00:00 2001 From: KarpAlex Date: Thu, 15 Sep 2022 18:56:18 +0200 Subject: [PATCH] issue plausichecks: added issue producer files, code formatting --- .../controllers/jobs/PlausiIssueProducer.php | 40 +++++++ application/core/IIssueExistsChecker.php | 10 +- application/core/IssueProducer_Controller.php | 101 +++++++----------- application/core/IssueResolver_Controller.php | 6 +- application/libraries/IssuesLib.php | 14 ++- .../libraries/issues/PlausicheckLib.php | 25 +++++ 6 files changed, 127 insertions(+), 69 deletions(-) create mode 100644 application/controllers/jobs/PlausiIssueProducer.php create mode 100644 application/libraries/issues/PlausicheckLib.php diff --git a/application/controllers/jobs/PlausiIssueProducer.php b/application/controllers/jobs/PlausiIssueProducer.php new file mode 100644 index 000000000..03fa6866f --- /dev/null +++ b/application/controllers/jobs/PlausiIssueProducer.php @@ -0,0 +1,40 @@ + class (library) name for resolving + $this->_fehlerLibMappings = array( + 'zgvDatumInZukunft' => 'ZgvDatumInZukunft', + 'zgvDatumVorGeburtsdatum' => 'ZgvDatumVorGeburtsdatum', + 'zgvMasterDatumInZukunft' => 'ZgvMasterDatumInZukunft', + 'zgvMasterDatumVorZgvdatum' => 'ZgvMasterDatumVorZgvdatum', + 'zgvMasterDatumVorGeburtsdatum' => 'ZgvMasterDatumVorGeburtsdatum', + 'keinAufenthaltszweckPlausi' => 'KeinAufenthaltszweckPlausi', + 'zuVieleZweckeIncomingPlausi' => 'ZuVieleZweckeIncomingPlausi', + 'falscherIncomingZweckPlausi' => 'FalscherIncomingZweckPlausi', + 'outgoingAufenthaltfoerderungfehltPlausi' => 'OutgoingAufenthaltfoerderungfehltPlausi', + 'outgoingAngerechneteEctsFehlenPlausi' => 'OutgoingAngerechneteEctsFehlenPlausi', + 'outgoingErworbeneEctsFehlenPlausi' => 'OutgoingErworbeneEctsFehlenPlausi' + ); + + $this->load->model('studiensemester_model', 'StudiensemesterModel'); + } + + public function run() + { + $semRes = $this->StudiensemesterModel->getAkt(); + + if (hasData($semRes)) + { + $studiensemester_kurzbz = getData($semRes)[0]->studiensemester_kurzbz; + } + } +} diff --git a/application/core/IIssueExistsChecker.php b/application/core/IIssueExistsChecker.php index 7a79b26ae..0aecaa796 100644 --- a/application/core/IIssueExistsChecker.php +++ b/application/core/IIssueExistsChecker.php @@ -7,9 +7,15 @@ interface IIssueExistsChecker { /** * Checks if an issue exists. - * Classes for checking if a certain issue exists implement this method. * @param array $params parameters needed for issue detection * @return object with success(true) if issue exists, success(false) otherwise */ - public function checkIfIssueExists($params); + public function checkIfIssueExists($paramsForChecking); + + /** + * Produces an issue. + * @param array $params parameters needed for issue detection + * @return object with success(true) if issue exists, success(false) otherwise + */ + public function produceIssue($person_id, $oe_kurzbz, $paramsForProducing); } diff --git a/application/core/IssueProducer_Controller.php b/application/core/IssueProducer_Controller.php index 625702a07..e0de28d88 100644 --- a/application/core/IssueProducer_Controller.php +++ b/application/core/IssueProducer_Controller.php @@ -7,8 +7,9 @@ abstract class IssueProducer_Controller extends JOB_Controller { const ISSUES_FOLDER = 'issues'; const CHECK_ISSUE_EXISTS_METHOD_NAME = 'checkIfIssueExists'; + const PRODUCE_ISSUE_METHOD_NAME = 'produceIssue'; - protected $_codeLibMappings; + protected $_fehlerLibMappings; public function __construct() { @@ -20,73 +21,51 @@ abstract class IssueProducer_Controller extends JOB_Controller } /** - * Initializes issue resolution. + * Initializes issue production. */ - public function run() + public function produceIssue($fehler_kurzbz, $person_id, $oe_kurzbz, $paramsForChecking, $paramsForProduction) { - $this->logInfo("Issue producer job started"); + // get libname from fehler_kurzbz + $libName = $this->_fehlerLibMappings[$fehler_kurzbz]; + + // 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 . '/' : ''; + $issuesLibPath = $libRootPath . self::ISSUES_FOLDER . '/'; + $issuesLibFilePath = DOC_ROOT . 'application/' . $libRootPath . 'libraries/' . self::ISSUES_FOLDER . '/' . $libName . '.php'; - foreach ($this->_codeLibMappings as $fehlercode => $library) + // check if library file exists + if (!file_exists($issuesLibFilePath)) return error("Issue library file " . $issuesLibFilePath . " does not exist"); + + // load library connected to fehler_kurzbz + $this->load->library($issuesLibPath . $libName); + + $lowercaseLibName = mb_strtolower($libName); + + // check if method is defined in library class + if (!is_callable(array($this->{$lowercaseLibName}, self::CHECK_ISSUE_EXISTS_METHOD_NAME))) + return error("Method " . self::CHECK_ISSUE_EXISTS_METHOD_NAME . " is not defined in library $lowercaseLibName"); + + // call the function for checking for issue resolution + $issueExistsRes = $this->{$lowercaseLibName}->{self::CHECK_ISSUE_EXISTS_METHOD_NAME}($paramsForChecking); + + if (isError($issueExistsRes)) return $issueExistsRes; + + $issueExistsData = getData($issueExistsRes); + + if ($issueExistsData === true) { - // 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), - isset($issue->behebung_parameter) ? json_decode($issue->behebung_parameter, true) : array() + // write issue if it was detected + $produceRes = $this->{$lowercaseLibName}->{self::PRODUCE_ISSUE_METHOD_NAME}( + $fehler_kurzbz, + isset($params['person_id']) ? $params['person_id'] : null, + isset($params['oe_kurzbz']) ? $params['oe_kurzbz'] : null, + $paramsForProduction ); - // 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 . '/' : ''; - $issuesLibPath = $libRootPath . self::ISSUES_FOLDER . '/'; - $issuesLibFilePath = DOC_ROOT . 'application/' . $libRootPath . 'libraries/' . self::ISSUES_FOLDER . '/' . $libName . '.php'; + if (isError($produceRes)) + return $produceRes; - // check if library file exists - if (!file_exists($issuesLibFilePath)) - { - // log error and continue with next issue if not - $this->logError("Issue library file " . $issuesLibFilePath . " does not exist"); - continue; - } - - // load library connected to fehlercode - $this->load->library( - $issuesLibPath . $libName - ); - - $lowercaseLibName = mb_strtolower($libName); - - // check if method is defined in libary class - if (!is_callable(array($this->{$lowercaseLibName}, self::CHECK_ISSUE_EXISTS_METHOD_NAME))) - { - // log error and continue with next issue if not - $this->logError("Method " . self::CHECK_ISSUE_EXISTS_METHOD_NAME . " is not defined in library $lowercaseLibName"); - continue; - } - - // call the function for checking for issue resolution - $issueResolvedRes = $this->{$lowercaseLibName}->{self::CHECK_ISSUE_EXISTS_METHOD_NAME}($params); - - if (isError($issueResolvedRes)) - { - $this->logError(getError($issueResolvedRes)); - } - else - { - $issueResolvedData = getData($issueResolvedRes); - - if ($issueResolvedData === true) - { - // set issue to resolved if needed - $behobenRes = $this->issueslib->setBehoben($issue->issue_id, null); - - if (isError($behobenRes)) - $this->logError(getError($behobenRes)); - else - $this->logInfo("Issue " . $issue->issue_id . " successfully resolved"); - } - } + return success("Issue " . $issue->issue_id . " successfully written"); } - - $this->logInfo("Issue resolve job ended"); } } diff --git a/application/core/IssueResolver_Controller.php b/application/core/IssueResolver_Controller.php index 77d14f408..ec47a060c 100755 --- a/application/core/IssueResolver_Controller.php +++ b/application/core/IssueResolver_Controller.php @@ -73,13 +73,11 @@ abstract class IssueResolver_Controller extends JOB_Controller } // load library connected to fehlercode - $this->load->library( - $issuesLibPath . $libName - ); + $this->load->library($issuesLibPath . $libName); $lowercaseLibName = mb_strtolower($libName); - // check if method is defined in libary class + // check if method is defined in library class if (!is_callable(array($this->{$lowercaseLibName}, self::CHECK_ISSUE_RESOLVED_METHOD_NAME))) { // log error and continue with next issue if not diff --git a/application/libraries/IssuesLib.php b/application/libraries/IssuesLib.php index d6488bc36..e31cb88c6 100644 --- a/application/libraries/IssuesLib.php +++ b/application/libraries/IssuesLib.php @@ -169,6 +169,9 @@ class IssuesLib return $this->_changeIssueStatus($issue_id, $data, $user); } + // -------------------------------------------------------------------------------------------------------------- + // Private methods + /** * Changes status of an issue. * @param int $issue_id @@ -215,8 +218,15 @@ class IssuesLib * @param string $inhalt_extern * @return object success or error */ - private function _addIssue($fehlercode, $person_id = null, $oe_kurzbz = null, $fehlertext_params = null, $resolution_params = null, $fehlercode_extern = null, $inhalt_extern = null) - { + private function _addIssue( + $fehlercode, + $person_id = null, + $oe_kurzbz = null, + $fehlertext_params = null, + $resolution_params = null, + $fehlercode_extern = null, + $inhalt_extern = null + ) { if (isEmptyString($person_id) && isEmptyString($oe_kurzbz)) return error("Person_id or oe_kurzbz must be set."); diff --git a/application/libraries/issues/PlausicheckLib.php b/application/libraries/issues/PlausicheckLib.php new file mode 100644 index 000000000..26b079c21 --- /dev/null +++ b/application/libraries/issues/PlausicheckLib.php @@ -0,0 +1,25 @@ +_ci =& get_instance(); + + $this->_ci->load->model('', ''); + } + + public function getStudents() + { + $qry = ' + + '; + } +}