From ef1347c7d59236738adc2bf79a7705a1c2391837 Mon Sep 17 00:00:00 2001 From: ma0068 Date: Tue, 5 May 2026 15:20:02 +0200 Subject: [PATCH] - use function getAktOrNextSemester - restructure single libs to isolate typeId of data - refactor Job: use params, details output - use functions insert, update, delete - use timeperiode for getAllTags and checkIfExistingTag - controller: rebuild function: change to POST - updated insertVon Batchuser --- application/controllers/jobs/TagJob.php | 69 +++- application/core/Tag_Controller.php | 6 +- application/libraries/TagLib.php | 369 +++++++++--------- .../libraries/tags/CoreDoubleDegreeTagLib.php | 4 +- .../libraries/tags/CoreFiftyFiveTagLib.php | 21 +- application/libraries/tags/CoreJgvTagLib.php | 4 +- .../libraries/tags/CoreMissingZgvTagLib.php | 2 +- .../libraries/tags/CoreOutgoingTagLib.php | 4 +- .../tags/CorePrewiederholerTagLib.php | 4 +- .../libraries/tags/CoreStbErhoehtTagLib.php | 4 +- .../libraries/tags/CoreUnterbrecherTagLib.php | 4 +- .../libraries/tags/CoreWiederholerTagLib.php | 2 +- application/models/person/Notiz_model.php | 55 +++ public/js/api/factory/stv/tag.js | 2 +- 14 files changed, 329 insertions(+), 221 deletions(-) diff --git a/application/controllers/jobs/TagJob.php b/application/controllers/jobs/TagJob.php index 68bc35fe8..65e4b052e 100644 --- a/application/controllers/jobs/TagJob.php +++ b/application/controllers/jobs/TagJob.php @@ -39,13 +39,16 @@ class TagJob extends JOB_Controller $automatedTagsRes = $this->NotiztypModel->loadWhere(array('automatisiert' => true, 'taglib IS NOT NULL' => null)); $automatedTags = hasData($automatedTagsRes) ? getData($automatedTagsRes) : []; - $result = $this->StudiensemesterModel->getLastOrAktSemester(); + $result = $this->StudiensemesterModel->getAktOrNextSemester(); if (isError($result)) return error ('Error occurred during retrieving studiensemester'); if (empty($result->retval) || !isset($result->retval[0])) { return error('No studiensemester found'); } $studiensemester_kurzbz = $result->retval[0]->studiensemester_kurzbz ?? null; + $params = array( + 'studiensemester_kurzbz' => $studiensemester_kurzbz + ); foreach($automatedTags as $autoTag) { @@ -56,7 +59,7 @@ class TagJob extends JOB_Controller require_once($filePath); } else { echo "File not found: " . $filePath . PHP_EOL; - continue; + continue; } $kurz_bz = $autoTag->typ_kurzbz; @@ -65,25 +68,69 @@ class TagJob extends JOB_Controller $obj = new $className(); - $outputArray = $obj->getZuordnungIds(['studiensemester_kurzbz' => $studiensemester_kurzbz]); - $data = $outputArray->data; + $outputArray = $obj->getZuordnungIds($params); + $typeId = $outputArray->typeId; - print_r($kurz_bz . " " . $autoTag->taglib); + $paramsTag = array( + 'studiensemester_kurzbz' => $studiensemester_kurzbz, + 'kurzbz' => $kurz_bz, + 'data' => $outputArray->data, + 'typeId' => $typeId + ); - $result = $this->taglib->updateAutomatedTags($kurz_bz, $data); + $result = $this->taglib->updateAutomatedTags($paramsTag); - $data = $result->retval; - if (isError($result)) - return error ('Error occurred during updateAutomatedTags'); + if (isError($result)) { + return error('Error occurred during updateAutomatedTags'); + } + + $data = is_array($result) ? $result['retval'] : $result->retval; + + //PRINT OUTPUT CONSOLE + //SUMMARY + print_r(PHP_EOL . "-- TAG " . $result->retval['input']['tag'] . " | TYPE_ID " . $typeId . " --"); - //Output with Summary and Details - print_r(PHP_EOL . "-- TAG " . $result->retval['input']['tag'] . " --"); print_r( PHP_EOL . "Count Recycled: " . $result->retval['summary']['recycled']); print_r(PHP_EOL . "Count Added: ". $result->retval['summary']['added']); print_r(PHP_EOL . "Count Deleted: ". $result->retval['summary']['deleted']); + + //DETAILS + //print_r(PHP_EOL . "New tag(s) [". $typeId . "]: " . implode(', ', $result->retval['results']['newTags'])); + //print_r(PHP_EOL . "Deleted tags(s) [". $typeId . "]: " . implode(', ', $result->retval['results']['deletedTagsIds'])); + //print_r(PHP_EOL . "Recycled tag(s) [". $typeId . "]: " . implode(', ', $result->retval['results']['retaggedIds'])); print_r(PHP_EOL); } print_r( PHP_EOL . "End Job rebuild" . PHP_EOL); } + + public function deleteAllAutomatedTags() + { + print_r( PHP_EOL . "Start Job delete ALL Automated Tags" . PHP_EOL); + + $resultToDelete = $this->NotizModel->loadWhere(array('insertvon' => 'BatchJobTagAdd')); + + $data = $resultToDelete->retval; + $notiz_ids = array_map(function($item) { + return $item->notiz_id; + }, $data); + + print_r($notiz_ids); + + foreach ($notiz_ids as $notiz_id) + { + $result = $this->NotizzuordnungModel->delete([ + 'notiz_id' => $notiz_id + ]); + if (isError($result)) + return error ('Error occurred delete Notizzuordnung' . $notiz_id); + + $result = $this->NotizModel->delete([ + 'notiz_id' => $notiz_id + ]); + if (isError($result)) + return error ('Error occurred delete Notiz' . $notiz_id); + } + print_r( PHP_EOL . "End Job delete Automated Tags" . PHP_EOL); + } } diff --git a/application/core/Tag_Controller.php b/application/core/Tag_Controller.php index a631639e5..082cb9ac4 100644 --- a/application/core/Tag_Controller.php +++ b/application/core/Tag_Controller.php @@ -339,10 +339,12 @@ class Tag_Controller extends FHCAPI_Controller public function rebuildTagsForTypeId() { - $id = $this->input->get('id'); - $typeId = $this->input->get('typeId'); + $id = $this->input->post('id'); + $typeId = $this->input->post('typeId'); $result = $this->taglib->rebuildTagsForTypeId($typeId, $id); + //TODO (refactor; um semester, studiengang_kz) + //$result = $this->taglib->rebuildTagsForTypeId($params); if (isError($result)) return error ('Error occurred during updateAutomatedTags'); diff --git a/application/libraries/TagLib.php b/application/libraries/TagLib.php index d49843ad9..2442b2fab 100644 --- a/application/libraries/TagLib.php +++ b/application/libraries/TagLib.php @@ -40,60 +40,63 @@ class TagLib $this->_ci->load->library('PrestudentLib'); } - public function updateAutomatedTags($tag, $inputData) + public function updateAutomatedTags($paramsTag) { - /* - $params array expected pattern - [ - [ - 'id' => 123456, - 'typeId' => 123456, - 'von' => '2026-04-01', - 'bis' => '2026-06-30' - ], - ... - ] - */ + // --------------------------------- + // check params + // --------------------------------- + $required = ['kurzbz', 'data', 'typeId']; + + foreach ($required as $key) { + if (!isset($paramsTag[$key])) { + return error('Missing Parameter: ' . $key); + } + } + + $studiensemester_kurzbz = (isset ($paramsTag['studiensemester_kurzbz']) ? $paramsTag['studiensemester_kurzbz'] : null); + $tag = $paramsTag['kurzbz']; + $inputData = $paramsTag['data']; + $typeId = $paramsTag['typeId']; // --------------------------------- // prepare input // --------------------------------- $zeitraum = []; - $prestudentIds = []; + $arrayIds = []; - //TODO(Manu) check minimal input: + foreach ($inputData as $item) { + $id = $item['id']; + $arrayIds[] = $id; - foreach ($inputData as $row) { - $pid = $row['id']; - $typeId = $row['typeId']; - - $prestudentIds[] = $pid; - - $zeitraum[$pid] = [ - 'von' => $row['von'] ?? null, - 'bis' => $row['bis'] ?? null + $zeitraum[$id] = [ + 'von' => $item['von'] ?? null, + 'bis' => $item['bis'] ?? null ]; } - $prestudentIds = array_unique($prestudentIds); + $arrayIds = array_unique($arrayIds); + + $result = $this->_ci->StudiensemesterModel->load($studiensemester_kurzbz); + if (isError($result)) { + return $result; + } + $data = $result->retval[0] ?? null; + + $von = $data->start ?? null; + $bis = $data->ende ?? null; // --------------------------------- // load existing tags // --------------------------------- $allTags = []; - - $this->_ci->NotizModel->addSelect('nz.notiz_id'); - $this->_ci->NotizModel->addSelect($typeId); - $this->_ci->NotizModel->addJoin('public.tbl_notizzuordnung nz', 'notiz_id'); - - $resultAllTags = $this->_ci->NotizModel->loadWhere([ - 'typ' => $tag - ]); - + $resultAllTags = $this->_ci->NotizModel->getAllTags($tag, $von, $bis); + if (isError($resultAllTags)) { + return $resultAllTags; + } $allTagsData = getData($resultAllTags); if (!empty($allTagsData)) { - foreach ($allTagsData as $row) { - $allTags[$row->$typeId] = $row->notiz_id; + foreach ($allTagsData as $item) { + $allTags[$item->$typeId] = $item->notiz_id; } } @@ -104,17 +107,18 @@ class TagLib $toAdd = []; $toDelete = []; - foreach ($prestudentIds as $pid) { - if (isset($allTags[$pid])) { - $toRecycle[$pid] = $allTags[$pid]; + foreach ($arrayIds as $id) { + if (isset($allTags[$id])) { + $toRecycle[$id] = $allTags[$id]; } else { - $toAdd[] = $pid; + $toAdd[] = $id; } } - foreach ($allTags as $pid => $notizId) { - if (!in_array($pid, $prestudentIds)) { - $toDelete[$pid] = $notizId; + foreach ($allTags as $id => $notizId) { + if (!in_array($id, $arrayIds)) { + $toDelete[$id] = $notizId; + } } @@ -124,24 +128,13 @@ class TagLib $countRecycled = 0; $retagged = []; - foreach ($toRecycle as $pid => $notizId) { - - $result = $this->_ci->NotizModel->update( - ['notiz_id' => $notizId], - [ - 'updateamum' => date('Y-m-d H:i:s'), - 'updatevon' => 'BatchJobTagUpdate', - 'start' => $zeitraum[$pid]['von'], - 'ende' => $zeitraum[$pid]['bis'] - ] - ); - - if (isError($result)) { - return error('Error updating tag ' . $notizId); - } + foreach ($toRecycle as $id => $notizId) + { + $this->_updateTag($notizId, $zeitraum[$id]['von'], $zeitraum[$id]['bis']); $countRecycled++; - $retagged[] = $notizId; + $retagged[] = $id; + //$retagged[] = $notizId; //notiz_id } // --------------------------------- @@ -150,37 +143,15 @@ class TagLib $countAdded = 0; $tagged = []; - foreach ($toAdd as $pid) { - - $resultInsert = $this->_ci->NotizModel->insert([ - 'titel' => 'TAG', - 'text' => 'AUTOMATED TAG', - 'verfasser_uid' => self::BATCHUSER, - 'erledigt' => false, - 'insertamum' => date('Y-m-d H:i:s'), - 'insertvon' => 'BatchJobTagAdd', - 'typ' => $tag, - 'start' => $zeitraum[$pid]['von'], - 'ende' => $zeitraum[$pid]['bis'] - ]); - - if (isError($resultInsert)) { - return error('Error inserting tag for prestudent ' . $pid); + foreach ($toAdd as $id) + { + $result = $this->_insertTag($typeId, $id, $tag, $zeitraum[$id]['von'], $zeitraum[$id]['bis']); + if (isError($result)) { + return $result; } - - $notizId = $resultInsert->retval; - - $resultZuordnung = $this->_ci->NotizzuordnungModel->insert([ - 'notiz_id' => $notizId, - $typeId => $pid - ]); - - if (isError($resultZuordnung)) { - return error('Error inserting relation for prestudent ' . $pid); - } - $countAdded++; - $tagged[$notizId] = $pid; + //$tagged[] = $result->retval[0]->notiz_id; //notiz_id + $tagged[] = $id; } // --------------------------------- @@ -189,26 +160,17 @@ class TagLib $countDeleted = 0; $deleted = []; - foreach ($toDelete as $pid => $notizId) { - - $result = $this->_ci->NotizzuordnungModel->delete([ - 'notiz_id' => $notizId - ]); + foreach ($toDelete as $id => $notizId) + { + $result = $this->_deleteTag($notizId); if (isError($result)) { - return error('Error deleting relation ' . $notizId); - } - - $result = $this->_ci->NotizModel->delete([ - 'notiz_id' => $notizId - ]); - - if (isError($result)) { - return error('Error deleting note ' . $notizId); + return $result; } $countDeleted++; - $deleted[] = $notizId; + //$deleted[] = $result->retval['deleted']; //notizId + $deleted[] = $id; } // --------------------------------- @@ -217,7 +179,7 @@ class TagLib return success([ 'input' => [ 'tag' => $tag, - 'prestudentIds' => $prestudentIds + 'arrayIds' => $arrayIds ], 'summary' => [ 'recycled' => $countRecycled, @@ -231,9 +193,9 @@ class TagLib 'toDelete' => $toDelete ], 'results' => [ - 'retaggedNotizIds' => $retagged, + 'retaggedIds' => $retagged, 'newTags' => $tagged, - 'deletedNotizIds' => $deleted + 'deletedTagsIds' => $deleted ] ]); } @@ -264,46 +226,14 @@ class TagLib //RECYCLE if ($notiz_id !== null) { - $resultUpdateNotiz = $this->_ci->NotizModel->update( - [ - 'notiz_id' => $notiz_id - ], - array( - 'updateamum' => date('Y-m-d H:i:s'), - 'updatevon' => getAuthUID(), - )); - - if (isError($resultUpdateNotiz)) - return error ('Error occurred update Result ' . $notiz_id); - - $return = ['recycled' => $notiz_id]; + $resultUpdateNotiz = $this->_updateTag($notiz_id, $von, $bis); + $return = ['recycled' => $resultUpdateNotiz]; } else - + //ADD { - $resultInsertNotiz = $this->_ci->NotizModel->insert(array( - 'titel' => 'TAG', - 'text' => 'AUTOMATED TAG', - 'verfasser_uid' => getAuthUID(), - 'erledigt' => false, - 'insertamum' => date('Y-m-d H:i:s'), - 'insertvon' => getAuthUID(), - 'typ' => $tag, - 'start' => $von, - 'ende' => $bis - )); - - if (isError($resultInsertNotiz)) - return error ('Error occurred insert Result ' . $prestudent_id); - - $resultInsertZuordnung = $this->_ci->NotizzuordnungModel->insert(array( - 'notiz_id' => $resultInsertNotiz->retval, - $typeId => $id - )); - - if (isError($resultInsertZuordnung)) - return error ('Error occurred insert Zuordnung ' . $id); - $return = ['added' => $resultInsertNotiz->retval]; + $resultInsertNotiz = $this->_insertTag($typeId, $id, $tag, $von, $bis); + $return = ['added' => $resultInsertNotiz]; } return success($return); } @@ -311,20 +241,23 @@ class TagLib /* * main function for rebuild Tags for typeId * */ - public function rebuildTagsForTypeId($typeId, $id) + public function rebuildTagsForTypeId($typeId, $id) //TODO aktSem of frontend { $automatedTagsRes = $this->_ci->NotiztypModel->loadWhere(array('automatisiert' => true, 'taglib IS NOT NULL' => null)); $automatedTags = hasData($automatedTagsRes) ? getData($automatedTagsRes) : []; - $_ci = get_instance(); - - $result = $this->_ci->StudiensemesterModel->getLastOrAktSemester(); + //TODO change to chosen Studiensemester in frontend + $result = $this->_ci->StudiensemesterModel->getAktOrNextSemester(); if (isError($result)) return error('Error occurred during retrieving studiensemester'); if (empty($result->retval) || !isset($result->retval[0])) { return error('No studiensemester found'); } $studiensemester_kurzbz = $result->retval[0]->studiensemester_kurzbz ?? null; + + //for checkDelete + $startSem = $result->retval[0]->start ?? null; + $endeSem = $result->retval[0]->ende ?? null; $return = []; foreach ($automatedTags as $autoTag) @@ -339,7 +272,6 @@ class TagLib continue; } - // className without PATH (basename) $className = basename($autoTag->taglib); $kurz_bz = $autoTag->typ_kurzbz; @@ -368,58 +300,141 @@ class TagLib if (isError($result)) return error('Error occurred during updateAutomatedTags' . $kurz_bz); - return $result; + $return[$kurz_bz] = $result; } else { - $result = $this->checkForDelete($kurz_bz, $typeId, $id); - - if ($result != null) - $return[$kurz_bz] = $result; + //CHECK FOR DELETE + $params = [ + 'von' => $startSem, + 'bis' => $endeSem, + 'kurzbz' => $autoTag->typ_kurzbz, + 'typeId' => $typeId, + 'id' => $id, + ]; + $result = $this->_ci->NotizModel->checkIfExistingTag($kurz_bz, $typeId, $id, $startSem, $endeSem); + if (hasData($result)) + { + $notizId = $result->retval[0]->notiz_id; + $this->_deleteTag($notizId); + $return[$kurz_bz] = ['deleted' => $notizId]; + } } } return success($return); } - public function checkForDelete($tag, $typeId, $id) + public function checkForDeleteDEPR($tag, $typeId, $id, $start, $ende) { + //TODO Zeitbezug $return = null; $notiz_id = null; + $_ci = get_instance(); + $_ci->addMeta( + 'in checkForDelete', $tag + ); + if (!is_numeric($id)) return error ("id " . $id . "not numeric"); - $this->_ci->NotizModel->addSelect('nz.notiz_id'); - $this->_ci->NotizModel->addSelect($typeId); - $this->_ci->NotizModel->addJoin('public.tbl_notizzuordnung nz', 'notiz_id'); - $resultAllTags = $this->_ci->NotizModel->loadWhere([ - 'typ' => $tag, - $typeId => $id - ]); - if(hasData($resultAllTags)) + $result = $this->_ci->NotizModel->checkIfValidTag($tag, $typeId, $id, $start, $ende); + if (isError($result)) { + return error('Error checking valid tag for ' . $typeId . ': ' . $id); + } + + if(hasData($result)) { - $notiz_id = $resultAllTags->retval[0]->notiz_id; + $notiz_id = $result->retval[0]->notiz_id; + $_ci = get_instance(); + $_ci->addMeta( + 'checkDeleteHas DAta', $notiz_id + ); } else return null; if($notiz_id) { - $result = $this->_ci->NotizzuordnungModel->delete([ - 'notiz_id' => $notiz_id - ]); - if (isError($result)) - return error ('Error occurred during delete Notizzuordnung' . $notiz_id); - - $result = $this->_ci->NotizModel->delete([ - 'notiz_id' => $notiz_id - ]); - if (isError($result)) - return error ('Error occurred during delete Notiz' . $notiz_id); - - $return = ['deleted' => $notiz_id]; + $_ci->addMeta( + 'TO DELETE', $notiz_id + ); + $result = $this->_deleteTag($notiz_id); } - return $return; + return ['deleted' => $result]; + } + + private function _insertTag($typeId, $id, $tag, $von, $bis) + { + $resultInsert = $this->_ci->NotizModel->insert([ + 'titel' => 'TAG', + 'text' => 'AUTOMATED TAG', + 'verfasser_uid' => self::BATCHUSER, + 'erledigt' => false, + 'insertamum' => date('Y-m-d H:i:s'), + 'insertvon' => 'BatchJobTagAdd', + 'typ' => $tag, + 'start' => $von, + 'ende' => $bis + ]); + + if (isError($resultInsert)) { + return error('Error inserting tag for ' . $typeId . ': ' . $id); + } + + $notizId = $resultInsert->retval; + + $resultZuordnung = $this->_ci->NotizzuordnungModel->insert([ + 'notiz_id' => $notizId, + $typeId => $id + ]); + + if (isError($resultZuordnung)) { + return error('Error inserting relation for ' . $typeId . ': ' . $id); + } + + return $notizId; + } + + private function _updateTag($notiz_id, $von, $bis) + { + $resultUpdateNotiz = $this->_ci->NotizModel->update( + [ + 'notiz_id' => $notiz_id + ], + array( + 'updateamum' => date('Y-m-d H:i:s'), + 'updatevon' => 'BatchJobTagUpdate', + 'start' => $von, + 'ende' => $bis + )); + + + if (isError($resultUpdateNotiz)) + return error ('Error occurred during Update ' . $notiz_id); + + return $notiz_id; + } + + private function _deleteTag($notiz_id) + { + $result = $this->_ci->NotizzuordnungModel->delete([ + 'notiz_id' => $notiz_id + ]); + if (isError($result)) { + return error('Error occurred during delete Notizzuordnung ' . $notiz_id); + } + + $result = $this->_ci->NotizModel->delete([ + 'notiz_id' => $notiz_id + ]); + if (isError($result)) { + return error('Error occurred during delete Notiz ' . $notiz_id); + } + + return success([ + 'deleted' => $notiz_id + ]); } } diff --git a/application/libraries/tags/CoreDoubleDegreeTagLib.php b/application/libraries/tags/CoreDoubleDegreeTagLib.php index 264891c3d..fa9670843 100644 --- a/application/libraries/tags/CoreDoubleDegreeTagLib.php +++ b/application/libraries/tags/CoreDoubleDegreeTagLib.php @@ -36,7 +36,6 @@ class CoreDoubleDegreeTagLib $doubledegree_data = array_map(function($item) { return [ - 'typeId' => 'prestudent_id', 'id' => $item->prestudent_id, 'von' => $item->start, 'bis' => $item->ende @@ -44,7 +43,8 @@ class CoreDoubleDegreeTagLib }, $data); return (object) array( - 'data' => $doubledegree_data + 'data' => $doubledegree_data, + 'typeId' => 'prestudent_id' ); } diff --git a/application/libraries/tags/CoreFiftyFiveTagLib.php b/application/libraries/tags/CoreFiftyFiveTagLib.php index 5d4990e5d..4e2738e8b 100644 --- a/application/libraries/tags/CoreFiftyFiveTagLib.php +++ b/application/libraries/tags/CoreFiftyFiveTagLib.php @@ -39,28 +39,25 @@ class CoreFiftyFiveTagLib $data = $result->retval; $fiftyFiveData = array_map(function($item) { return [ - 'id' => $item->person_id, - 'typeId' => 'person_id', + 'id' => $item->person_id ]; }, $data); return (object) array( - 'data' => $fiftyFiveData + 'data' => $fiftyFiveData, + 'typeId' => 'person_id' ); } public function isCriteriaSetFor(array $params) { - if(!isset($params['person_id']) || !isset($params['studiensemester_kurzbz'])) - { + if ( !isset($params['id'], $params['studiensemester_kurzbz'], $params['typeId']) || $params['typeId'] !== 'person_id') return false; - } + $semester = $params['studiensemester_kurzbz']; $person_id = $params['id']; $typeId = $params['typeId']; - if($typeId != 'person_id') - return null; $result = $this->ci->StudiensemesterModel->loadWhere(array( 'studiensemester_kurzbz' => $semester @@ -71,17 +68,9 @@ class CoreFiftyFiveTagLib $semBis = $data->ende; $result = $this->ci->PersonModel->isFiftyFive($semVon, $semBis, $person_id); - $data = $result->retval; - $fiftyFiveData = array_map(function($item) { - return [ - 'id' => $item->person_id, - 'typeId' => 'person_id', - ]; - }, $data); if(hasData($result)) { - //array mit prestudent_id, von und bis return $result; } else diff --git a/application/libraries/tags/CoreJgvTagLib.php b/application/libraries/tags/CoreJgvTagLib.php index 479da7da0..15e77dc98 100644 --- a/application/libraries/tags/CoreJgvTagLib.php +++ b/application/libraries/tags/CoreJgvTagLib.php @@ -31,7 +31,6 @@ class CoreJgvTagLib $jgv_data = array_map(function($item) { return [ - 'typeId' => 'prestudent_id', 'id' => $item->prestudent_id, 'von' => $item->datum_von, 'bis' => $item->datum_bis @@ -39,7 +38,8 @@ class CoreJgvTagLib }, $data); return (object) array( - 'data' => $jgv_data + 'data' => $jgv_data, + 'typeId' => 'prestudent_id' ); } diff --git a/application/libraries/tags/CoreMissingZgvTagLib.php b/application/libraries/tags/CoreMissingZgvTagLib.php index 73fa9021f..e25aed4cc 100644 --- a/application/libraries/tags/CoreMissingZgvTagLib.php +++ b/application/libraries/tags/CoreMissingZgvTagLib.php @@ -39,7 +39,6 @@ class CoreMissingZgvTagLib $zgvmissing_data = array_map(function($item) { return [ - 'typeId' => 'prestudent_id', 'id' => $item->prestudent_id, 'von' => null, 'bis' => null @@ -47,6 +46,7 @@ class CoreMissingZgvTagLib }, $data); return (object) array( + 'typeId' => 'prestudent_id', 'data' => $zgvmissing_data ); diff --git a/application/libraries/tags/CoreOutgoingTagLib.php b/application/libraries/tags/CoreOutgoingTagLib.php index e076d0adf..904839dee 100644 --- a/application/libraries/tags/CoreOutgoingTagLib.php +++ b/application/libraries/tags/CoreOutgoingTagLib.php @@ -31,7 +31,6 @@ class CoreOutgoingTagLib $outgoing_data = array_map(function($item) { return [ - 'typeId' => 'prestudent_id', 'id' => $item->prestudent_id, 'von' => $item->von, 'bis' => $item->bis @@ -39,7 +38,8 @@ class CoreOutgoingTagLib }, $data); return (object) array( - 'data' => $outgoing_data + 'data' => $outgoing_data, + 'typeId' => 'prestudent_id', ); } diff --git a/application/libraries/tags/CorePrewiederholerTagLib.php b/application/libraries/tags/CorePrewiederholerTagLib.php index cb2f0a77a..8b7037b07 100644 --- a/application/libraries/tags/CorePrewiederholerTagLib.php +++ b/application/libraries/tags/CorePrewiederholerTagLib.php @@ -34,7 +34,6 @@ class CorePrewiederholerTagLib $prewiederholer_data = array_map(function($item) { return [ - 'typeId' => 'prestudent_id', 'id' => $item->prestudent_id, 'von' => $item->start, 'bis' => $item->ende @@ -42,7 +41,8 @@ class CorePrewiederholerTagLib }, $data); return (object) array( - 'data' => $prewiederholer_data + 'data' => $prewiederholer_data, + 'typeId' => 'prestudent_id', ); } diff --git a/application/libraries/tags/CoreStbErhoehtTagLib.php b/application/libraries/tags/CoreStbErhoehtTagLib.php index 5795f8348..886aff468 100644 --- a/application/libraries/tags/CoreStbErhoehtTagLib.php +++ b/application/libraries/tags/CoreStbErhoehtTagLib.php @@ -36,7 +36,6 @@ class CoreStbErhoehtTagLib $konto_data = array_map(function($item) { return [ - 'typeId' => 'prestudent_id', 'id' => $item->prestudent_id, 'von' => $item->start, 'bis' => $item->ende @@ -44,7 +43,8 @@ class CoreStbErhoehtTagLib }, $data); return (object) array( - 'data' => $konto_data + 'data' => $konto_data, + 'typeId' => 'prestudent_id' ); } diff --git a/application/libraries/tags/CoreUnterbrecherTagLib.php b/application/libraries/tags/CoreUnterbrecherTagLib.php index c205c746c..ddf8f33cd 100644 --- a/application/libraries/tags/CoreUnterbrecherTagLib.php +++ b/application/libraries/tags/CoreUnterbrecherTagLib.php @@ -34,7 +34,6 @@ class CoreUnterbrecherTagLib $unterbrecher_data = array_map(function($item) { return [ - 'typeId' => 'prestudent_id', 'id' => $item->prestudent_id, 'von' => $item->start, 'bis' => $item->ende @@ -42,7 +41,8 @@ class CoreUnterbrecherTagLib }, $data); return (object) array( - 'data' => $unterbrecher_data + 'data' => $unterbrecher_data, + 'typeId' => 'prestudent_id' ); } diff --git a/application/libraries/tags/CoreWiederholerTagLib.php b/application/libraries/tags/CoreWiederholerTagLib.php index 3d75e562e..8f4eb1dd7 100644 --- a/application/libraries/tags/CoreWiederholerTagLib.php +++ b/application/libraries/tags/CoreWiederholerTagLib.php @@ -34,7 +34,6 @@ class CoreWiederholerTagLib $wiederholer_data = array_map(function($item) { return [ - 'typeId' => 'prestudent_id', 'id' => $item->prestudent_id, 'von' => $item->start, 'bis' => $item->ende @@ -42,6 +41,7 @@ class CoreWiederholerTagLib }, $data); return (object) array( + 'typeId' => 'prestudent_id', 'data' => $wiederholer_data ); } diff --git a/application/models/person/Notiz_model.php b/application/models/person/Notiz_model.php index 64fce8944..1dc09caaf 100644 --- a/application/models/person/Notiz_model.php +++ b/application/models/person/Notiz_model.php @@ -296,4 +296,59 @@ class Notiz_model extends DB_Model return $this->loadWhere(array('anrechnung_id' => $anrechnung_id)); } + + /** + * check if a given Tag for a certain notizzuordnung id is valid + * + * @param $tag typ_kurzbz to check + * @param $typeId typeId to check + * @param $id id to check + * @param $von start of time period or NULL + * @param $bis end of time period or NULL + * + * @return array + */ + public function checkIfExistingTag($tag, $typeId, $id, $von=null, $bis=null) + { + $query = " + SELECT * + FROM public.tbl_notiz + JOIN public.tbl_notizzuordnung nz USING (notiz_id) + WHERE typ = ? + AND {$typeId} = ? + AND ( + start IS NULL + OR ende IS NULL + OR (start <= ? AND ende >= ?) + ) + "; + + return $this->execQuery($query, [$tag, $id, $bis, $von]); + } + + /** + * returns all existing tags of a certain tag within a time period + * + * @param $tag typ_kurzbz of tag + * @param $von start of time period or NULL + * @param $bis end of time period or NULL + * + * @return array + */ + public function getAllTags($tag, $von=null, $bis=null) + { + $query = " + SELECT * + FROM public.tbl_notiz + JOIN public.tbl_notizzuordnung nz USING (notiz_id) + WHERE typ = ? + AND ( + start IS NULL + OR ende IS NULL + OR (start <= ? AND ende >= ?) + ); + "; + + return $this->execQuery($query, array($tag, $bis, $von)); + } } diff --git a/public/js/api/factory/stv/tag.js b/public/js/api/factory/stv/tag.js index b0c416e2d..26aacca69 100644 --- a/public/js/api/factory/stv/tag.js +++ b/public/js/api/factory/stv/tag.js @@ -63,7 +63,7 @@ export default { rebuildTagsforTypeId(data){ return { - method: 'get', + method: 'post', url: 'api/frontend/v1/stv/Tags/rebuildTagsForTypeId/', params: data };