From ee6f28c06dff664b56f44b4296b19af802e5c0d4 Mon Sep 17 00:00:00 2001 From: ma0068 Date: Thu, 9 Apr 2026 13:58:42 +0200 Subject: [PATCH] Refactor TagJob and TabLib: use dynamic approach with column taglib for creating Tags --- application/controllers/jobs/TagJob.php | 90 ++++++++++++++++++- application/libraries/TagLib.php | 70 +++++++++++++-- .../tags/CorePrewiederholerTagLib.php | 66 ++++++++++++++ .../libraries/tags/CoreWiederholerTagLib.php | 23 +++++ 4 files changed, 239 insertions(+), 10 deletions(-) create mode 100644 application/libraries/tags/CorePrewiederholerTagLib.php diff --git a/application/controllers/jobs/TagJob.php b/application/controllers/jobs/TagJob.php index c70063707..644f9b521 100644 --- a/application/controllers/jobs/TagJob.php +++ b/application/controllers/jobs/TagJob.php @@ -8,7 +8,7 @@ class TagJob extends JOB_Controller { const BATCHUSER = 'sftest'; - const SEMESTER = 'WS2025'; //docker + const SEMESTER = 'SS2026'; //docker //TODO semester /** @@ -49,7 +49,40 @@ class TagJob extends JOB_Controller $taglib = strtolower(basename($autoTag->taglib)); $this->load->library($autoTag->taglib); - $ids = $this->$taglib->getZuordnungIds(array('studiensemester_kurzbz' => 'SS2026')); + $ids = $this->$taglib->getZuordnungIds(array('studiensemester_kurzbz' => self::SEMESTER)); + print_r($ids); + } + } + + public function loadTagLibs() + { + $automatedTagsRes = $this->NotiztypModel->loadWhere(array('automatisiert' => true, 'taglib IS NOT NULL' => null)); + //echo $this->NotiztypModel->db->last_query(); + $automatedTags = hasData($automatedTagsRes) ? getData($automatedTagsRes) : []; + print_r($automatedTags); + + foreach($automatedTags as $autoTag) + { + // getPath: must not be lost + $filePath = APPPATH . 'libraries/' . $autoTag->taglib . '.php'; // APPPATH = application/ + + if(file_exists($filePath)) { + require_once($filePath); + } else { + echo "File not found: " . $filePath; + continue; + } + + // className without PATH (basename) + $className = basename($autoTag->taglib); + + $obj = new $className(); + $ids = $obj->getZuordnungIds(['studiensemester_kurzbz' => self::SEMESTER]); + + $kurz_bz = $autoTag->typ_kurzbz; + + echo PHP_EOL . $className . ": "; + echo PHP_EOL . $kurz_bz . ": "; print_r($ids); } } @@ -60,6 +93,59 @@ class TagJob extends JOB_Controller $automaticTags = $this->config->item('stv_automatic_tags'); print_r( implode( ", ", $automaticTags) . PHP_EOL); + $automatedTagsRes = $this->NotiztypModel->loadWhere(array('automatisiert' => true, 'taglib IS NOT NULL' => null)); + //echo $this->NotiztypModel->db->last_query(); + $automatedTags = hasData($automatedTagsRes) ? getData($automatedTagsRes) : []; + print_r($automatedTags); + + + foreach($automatedTags as $autoTag) + { + // getPath: must not be lost + $filePath = APPPATH . 'libraries/' . $autoTag->taglib . '.php'; // APPPATH = application/ + + if(file_exists($filePath)) { + require_once($filePath); + } else { + echo "File not found: " . $filePath . PHP_EOL; + continue; + } + + $kurz_bz = $autoTag->typ_kurzbz; + // className without PATH (basename) + $className = basename($autoTag->taglib); + + $obj = new $className(); + $ids = $obj->getZuordnungIds(['studiensemester_kurzbz' => self::SEMESTER]); + + $idsArray = $ids->prestudent_id; + + $result = $this->taglib->updateAutomatedTags($kurz_bz, $idsArray); + $data = $result->retval; + if (isError($result)) + return error ('Error occurred during updateAutomatedTags'); + + print_r(PHP_EOL ."ALL TAGS " . $kurz_bz . " " . count($data[0]) . " TO ADD " . count($data[1]) . " TO RECYLE: " . count($data[2]) . " TO DELETE: " . count($data[3])); + + + print_r( PHP_EOL . "Count Recycled: "); + print_r($data[4]); + print_r( PHP_EOL . "Count Added: "); + print_r($data[6]); + print_r( PHP_EOL . "Count Deleted: "); + print_r($data[8] . PHP_EOL . PHP_EOL); + + } + print_r( PHP_EOL . "End Job rebuild" . PHP_EOL); + + } + + public function rebuildAutomatedTags_DEPR() + { + print_r( PHP_EOL . "Start Job rebuild" . PHP_EOL); + $automaticTags = $this->config->item('stv_automatic_tags'); + print_r( implode( ", ", $automaticTags) . PHP_EOL); + //TODO(Manu) use a loop in library? if(in_array('wh_auto', $automaticTags)) { diff --git a/application/libraries/TagLib.php b/application/libraries/TagLib.php index e64f9819e..aa9fb640e 100644 --- a/application/libraries/TagLib.php +++ b/application/libraries/TagLib.php @@ -18,7 +18,7 @@ class TagLib { const BATCHUSER = 'sftest'; const TYP_ZUORDNUNG = 'prestudent_id'; - const SEMESTER = 'WS2025'; + const SEMESTER = 'SS2026'; /** * Object initialization @@ -233,11 +233,67 @@ class TagLib } -/* - * main function for rebuild Tags for single prestudent - * manually triggered - * */ + /* + * main function for rebuild Tags for single prestudent + * manually triggered + * */ public function rebuildTagsForPrestudent($prestudent_id) + { + $automatedTagsRes = $this->_ci->NotiztypModel->loadWhere(array('automatisiert' => true, 'taglib IS NOT NULL' => null)); + //echo $this->NotiztypModel->db->last_query(); + $automatedTags = hasData($automatedTagsRes) ? getData($automatedTagsRes) : []; + print_r($automatedTags); + + $return = []; + + foreach($automatedTags as $autoTag) + { + // getPath: must not be lost + $filePath = APPPATH . 'libraries/' . $autoTag->taglib . '.php'; // APPPATH = application/ + + if (file_exists($filePath)) { + require_once($filePath); + } else { + echo "File not found: " . $filePath; + continue; + } + + // className without PATH (basename) + $className = basename($autoTag->taglib); + + $obj = new $className(); + $criteriaIsSet = $obj->isCriteriaSetFor([ + 'prestudent_id' => $prestudent_id, + 'studiensemester_kurzbz' => self::SEMESTER + ]); + //$return = $this->_ci->PrestudentstatusModel->db->last_query(); + $kurz_bz = $autoTag->typ_kurzbz; + + // $return[$kurz_bz] = $criteriaIsSet; + + if($criteriaIsSet) + { + $result = $this->updateAutomatedTagsForPrestudent($kurz_bz, $prestudent_id); + if (isError($result)) + return error ('Error occurred during updateAutomatedTags' . $kurz_bz); + + else + $return[$kurz_bz] = $result; + } + else { + $result = $this->checkForDelete($kurz_bz, $prestudent_id); + if($result != null) + $return[$kurz_bz] = $result; + } + + } + + + return success($return); + + } + + public function rebuildTagsForPrestudentDEPR($prestudent_id) { $automaticTags = $this->_ci->config->item('stv_automatic_tags'); $return = []; @@ -259,8 +315,6 @@ class TagLib $return[$tag] = $result; } } - - return success($return); } @@ -304,7 +358,7 @@ class TagLib return $return; } - public function isCriteriaSetFor($tag, $prestudent_id) + public function isCriteriaSetFor_DEPR($tag, $prestudent_id) { //TODO(finish list) if($tag == 'wh_auto') diff --git a/application/libraries/tags/CorePrewiederholerTagLib.php b/application/libraries/tags/CorePrewiederholerTagLib.php new file mode 100644 index 000000000..ac6d152c6 --- /dev/null +++ b/application/libraries/tags/CorePrewiederholerTagLib.php @@ -0,0 +1,66 @@ +ci = get_instance(); + $this->ci->load->model('crm/Prestudentstatus_model', 'PrestudentstatusModel'); + } + + public function getZuordnungIds(array $params) + { + if(!isset($params['studiensemester_kurzbz'])) + { + return (object) array( + 'prestudent_id' => [] + ); + } + + $semester = $params['studiensemester_kurzbz']; + $result = $this->ci->PrestudentstatusModel-> loadWhere(array( + 'statusgrund_id' => 15, + 'studiensemester_kurzbz' => $semester + )); + $data = $result->retval; + $ids = array_map(function($item) { + return $item->prestudent_id; + }, $data); + + return (object) array( + 'prestudent_id' => $ids + ); + } + + public function isCriteriaSetFor(array $params) + { + if(!isset($params['prestudent_id']) || !isset($params['studiensemester_kurzbz'])) + { + return (object) array( + 'isSet' => false + ); + } + + $semester = $params['studiensemester_kurzbz']; + $prestudent_id = $params['prestudent_id']; + + $result = $this->ci->PrestudentstatusModel->loadWhere(array( + 'statusgrund_id' => 15, + 'studiensemester_kurzbz' => $semester, + 'prestudent_id' => $prestudent_id + )); + if(hasData($result)) + { + return true; + } + else + return false; + } + +} diff --git a/application/libraries/tags/CoreWiederholerTagLib.php b/application/libraries/tags/CoreWiederholerTagLib.php index f25a0e02c..9f0dc3720 100644 --- a/application/libraries/tags/CoreWiederholerTagLib.php +++ b/application/libraries/tags/CoreWiederholerTagLib.php @@ -38,5 +38,28 @@ class CoreWiederholerTagLib ); } + public function isCriteriaSetFor(array $params) + { + if(!isset($params['prestudent_id']) || !isset($params['studiensemester_kurzbz'])) + { + return (object) array( + 'isSet' => false + ); + } + $semester = $params['studiensemester_kurzbz']; + $prestudent_id = $params['prestudent_id']; + + $result = $this->ci->PrestudentstatusModel->loadWhere(array( + 'statusgrund_id' => 16, + 'studiensemester_kurzbz' => $semester, + 'prestudent_id' => $prestudent_id + )); + if(hasData($result)) + { + return true; + } + else + return false; + } }