diff --git a/application/controllers/jobs/PlausiIssueProducer.php b/application/controllers/jobs/PlausiIssueProducer.php index 03fa6866f..d67c8693b 100644 --- a/application/controllers/jobs/PlausiIssueProducer.php +++ b/application/controllers/jobs/PlausiIssueProducer.php @@ -3,38 +3,120 @@ /** * Job for producing Plausicheck issues */ -class PlausiIssueProducer extends IssueProducer_Controller +class PlausiIssueProducer extends JOB_Controller { + const PLAUSI_ISSUES_FOLDER = 'issues/plausichecks'; + const EXECUTE_PLAUSI_CHECK_METHOD_NAME = 'executePlausiCheck' + + private _fehlerLibMappings; + public function __construct() { parent::__construct(); - // set fehler codes which can be produced by the job - // structure: fehlercode => class (library) name for resolving + // set fehler which can be produced by the job + // structure: fehler_kurzbz => 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' + '' => '' + //'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('organisation/studiensemester_model', 'StudiensemesterModel'); - $this->load->model('studiensemester_model', 'StudiensemesterModel'); + $this->load->library('IssuesLib'); } - public function run() + /** + * Initializes issue production. + */ + public function run($studiensemester_kurzbz = null) { - $semRes = $this->StudiensemesterModel->getAkt(); - - if (hasData($semRes)) + if (isEmptyString($studiensemester_kurzbz)) { - $studiensemester_kurzbz = getData($semRes)[0]->studiensemester_kurzbz; + $studiensemesterRes = $this->StudiensemesterModel->getAkt(); + + if (isError($studiensemesterRes)) $this->logError(getError($studiensemesterRes)); + + if (hasData($studiensemesterRes)) + { + $studiensemester_kurzbz = getData($studiensemesterRes); + } } + + + $this->logInfo("Plausicheck issue producer job started"); + + foreach ($this->_fehlerLibMappings as $fehler_kurzbz => $libName) + { + // get path of library for issue to be produced + $issuesLibPath = DOC_ROOT . 'application/libraries' . self::PLAUSI_ISSUES_FOLDER; + $issuesLibFilePath = $issuesLibPath . '/' . $libName . '.php'; + + // 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 library class + if (!is_callable(array($this->{$lowercaseLibName}, self::EXECUTE_PLAUSI_CHECK_METHOD_NAME))) + { + // log error and continue with next issue if not + $this->logError("Method " . self::EXECUTE_PLAUSI_CHECK_METHOD_NAME . " is not defined in library $lowercaseLibName"); + continue; + } + + // call the function for checking for issue production + $executePlausiRes = $this->{$lowercaseLibName}->{self::EXECUTE_PLAUSI_CHECK_METHOD_NAME}(); + + if (isError($executePlausiRes)) + { + $this->logError(getError($executePlausiRes)); + } + else + { + // get the data returned by Plausicheck + $executePlausiData = getData($executePlausiRes); + + if (is_array($executePlausiData)) + { + foreach ($executePlausiData 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); + + if (isError($addIssueRes)) + $this->logError(getError($behobenRes)); + else + $this->logInfo("Plausicheck issue " . $fehler_kurzbz . " successfully produced"); + } + } + } + } + + $this->logInfo("Plausicheck issue producer job stopped"); } } diff --git a/application/core/IIssueExistsChecker.php b/application/core/IIssueExistsChecker.php index 0aecaa796..7f5a6b6e5 100644 --- a/application/core/IIssueExistsChecker.php +++ b/application/core/IIssueExistsChecker.php @@ -17,5 +17,5 @@ interface IIssueExistsChecker * @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); + //public function produceIssue($person_id, $oe_kurzbz, $paramsForProducing); } diff --git a/application/core/IssueProducer_Controller.php b/application/core/IssueProducer_Controller.php index e0de28d88..6879bc7dd 100644 --- a/application/core/IssueProducer_Controller.php +++ b/application/core/IssueProducer_Controller.php @@ -23,49 +23,53 @@ abstract class IssueProducer_Controller extends JOB_Controller /** * Initializes issue production. */ - public function produceIssue($fehler_kurzbz, $person_id, $oe_kurzbz, $paramsForChecking, $paramsForProduction) - { - // get libname from fehler_kurzbz - $libName = $this->_fehlerLibMappings[$fehler_kurzbz]; + //public function produceIssue($fehler_kurzbz, $person_id, $oe_kurzbz, $paramsForChecking, $paramsForProduction) + //{ + //// 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'; + //// 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'; - // check if library file exists - if (!file_exists($issuesLibFilePath)) return error("Issue library file " . $issuesLibFilePath . " does not exist"); + //// 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); + //// load library connected to fehler_kurzbz + //$this->load->library($issuesLibPath . $libName); - $lowercaseLibName = mb_strtolower($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"); + //// 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); + //// call the function for checking for issue resolution + //$issueExistsRes = $this->{$lowercaseLibName}->{self::CHECK_ISSUE_EXISTS_METHOD_NAME}($paramsForChecking); - if (isError($issueExistsRes)) return $issueExistsRes; + //if (isError($issueExistsRes)) return $issueExistsRes; - $issueExistsData = getData($issueExistsRes); + //$issueExistsData = getData($issueExistsRes); - if ($issueExistsData === true) - { - // 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 ($issueExistsData === true) + //{ + //// 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 (isError($produceRes)) - return $produceRes; + ////if (isError($produceRes)) + ////return $produceRes; - return success("Issue " . $issue->issue_id . " successfully written"); - } - } + //$addIssueres = $this->IssuesLib->addFhcIssue($fehler_kurzbz, $person_id, $oe_kurzbz, $fehlertext_params, $resolution_params); + + //if (isError()) + + //return success("Issue " . $issue->issue_id . " successfully written"); + //} + //} } diff --git a/application/core/IssueResolver_Controller.php b/application/core/IssueResolver_Controller.php index ec47a060c..d6eda8afb 100755 --- a/application/core/IssueResolver_Controller.php +++ b/application/core/IssueResolver_Controller.php @@ -43,7 +43,6 @@ abstract class IssueResolver_Controller extends JOB_Controller } else { - $openIssues = getData($openIssuesRes); foreach ($openIssues as $issue) diff --git a/application/libraries/issues/PlausicheckLib.php b/application/libraries/issues/PlausicheckLib.php index 26b079c21..16c423aa3 100644 --- a/application/libraries/issues/PlausicheckLib.php +++ b/application/libraries/issues/PlausicheckLib.php @@ -2,7 +2,7 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); -class Lib +class PlausicheckLib { private $_ci; // Code igniter instance @@ -15,11 +15,4 @@ class Lib $this->_ci->load->model('', ''); } - - public function getStudents() - { - $qry = ' - - '; - } } diff --git a/application/libraries/issues/plausichecks/IPlausiChecker.php b/application/libraries/issues/plausichecks/IPlausiChecker.php new file mode 100644 index 000000000..415bc4735 --- /dev/null +++ b/application/libraries/issues/plausichecks/IPlausiChecker.php @@ -0,0 +1,14 @@ +