From c1df686edceee3b32cc1fe71faa82fd49db4a69b Mon Sep 17 00:00:00 2001 From: ma0068 Date: Thu, 22 Sep 2022 10:30:15 +0200 Subject: [PATCH] Zeiterfassung: Projektvalidierung in Klassen refactored --- cis/private/tools/zeitaufzeichnung.php | 11 --- include/zeitaufzeichnung_import.class.php | 70 +++++++++++++------ include/zeitaufzeichnung_import_csv.class.php | 3 +- .../zeitaufzeichnung_import_post.class.php | 2 + 4 files changed, 53 insertions(+), 33 deletions(-) diff --git a/cis/private/tools/zeitaufzeichnung.php b/cis/private/tools/zeitaufzeichnung.php index 003eea434..daa6bb72d 100644 --- a/cis/private/tools/zeitaufzeichnung.php +++ b/cis/private/tools/zeitaufzeichnung.php @@ -859,17 +859,6 @@ if(isset($_POST['save']) || isset($_POST['edit']) || isset($_POST['import'])) else if ($datum->formatDatum($von, $format='Y-m-d H:i:s') < $sperrdatum) echo '' .$p->t("global/fehlerBeimSpeichernDerDaten").': Eingabe nicht möglich da vor dem Sperrdatum'; - //check if Arbeitspaket ausgewählt werden muss - else if (!$projekt->zeitaufzeichnung && !$projektphase_id) - { - echo '' .$p->t("global/fehlerBeimSpeichernDerDaten").': Bitte ein Arbeitspaket wählen!'; - } - - //check if phase bebuchbar - else if ($phaseBebuchbar == 'f') - { - echo '' .$p->t("global/fehlerBeimSpeichernDerDaten").': Dieses Arbeitspaket darf nicht bebucht werden'; - } // NOTE(chris): Save else if (isset($_POST['save']) || isset($_POST['edit'])) { diff --git a/include/zeitaufzeichnung_import.class.php b/include/zeitaufzeichnung_import.class.php index e8e6a8b15..bd078a5ad 100644 --- a/include/zeitaufzeichnung_import.class.php +++ b/include/zeitaufzeichnung_import.class.php @@ -21,7 +21,7 @@ class zeitaufzeichnung_import { protected $project; protected $phase; protected $limitdate; - + protected $zeit; @@ -42,7 +42,7 @@ class zeitaufzeichnung_import { $this->zeit = new zeitaufzeichnung(); } - + /** * @return boolean @@ -64,7 +64,7 @@ class zeitaufzeichnung_import { public function hasInfos() { return !empty($this->infos); } - + /** * @return string */ @@ -96,15 +96,15 @@ class zeitaufzeichnung_import { $html .= '' . $msg . '
' . "\n"; } return $html; - } - + } + /** * @return string */ public function OutputToHTML() { return $this->InfosToHTML() . $this->WarningsToHTML() . $this->ErrorsToHTML(); - } - + } + /** * @param string $msg * @return void @@ -112,7 +112,7 @@ class zeitaufzeichnung_import { protected function addError($msg) { $this->errors[] = $msg; } - + /** * @param string $msg * @return void @@ -120,7 +120,7 @@ class zeitaufzeichnung_import { protected function addWarning($msg) { $this->warnings[] = $msg; } - + /** * @param string $msg * @return void @@ -134,7 +134,7 @@ class zeitaufzeichnung_import { * @param string $uid The user id * @param string $day "Y-m-d" formatted datestring * @return void - * + * * @throws Exception */ protected function checkZeitsperren($uid, $day) { @@ -150,25 +150,25 @@ class zeitaufzeichnung_import { throw new Exception($this->p->t("global/fehlerBeimSpeichernDerDaten") . ": " . $this->p->t("zeitaufzeichnung/zeitsperreVorhanden", [$zsdate, $zs->result[0]->zeitsperretyp_kurzbz])); } } - + /** * @param string $date datetimestring * @return void - * + * * @throws Exception */ protected function checkLimitdatum($date) { if ($this->datum->formatDatum($date, 'Y-m-d H:i:s') > $this->limitdate) { throw new Exception($this->p->t("global/fehlerBeimSpeichernDerDaten") . ': Eingabe nicht möglich da (' . $date . ') zu weit in der Zukunft liegt.'); - } + } } - + /** * @param string $start datestring * @param string $end datestring * @param string $aktivitaet_kurzbz * @return void - * + * * @throws Exception */ protected function checkDienstreise($start, $end, $aktivitaet_kurzbz) { @@ -179,11 +179,11 @@ class zeitaufzeichnung_import { .': Eingabe nicht möglich, da keine Zeitaufzeichnung über mehrere Tage erlaubt ist (ausgenommen Dienstreisen).'); } } - + /** * @param string $end timestring * @return void - * + * * @throws Exception */ protected function checkTagesgenau($end) { @@ -193,13 +193,13 @@ class zeitaufzeichnung_import { .': Bitte Arbeitszeiten gemäß Arbeitsaufzeichnung Leitfaden tagesgenau abgrenzen: Nur Eingaben von 00:00 bis 23:59 erlaubt!'); } } - + /** * @param string $projekt_kurzbz * @param string $start datestring * @param string $end datestring * @return void - * + * * @throws Exception */ protected function checkProjectInterval($projekt_kurzbz, $start, $end) { @@ -207,13 +207,13 @@ class zeitaufzeichnung_import { throw new Exception($this->p->t("global/fehlerBeimSpeichernDerDaten") . ': Eingabe nicht möglich, da angegebenes Anfangs und Enddatum nicht in den Projektzeitrahmen fällt: (' . $start . ') (' . $end . ')'); } } - + /** * @param string $phase The Projektphase ID * @param string $start datestring * @param string $end datestring * @return void - * + * * @throws Exception */ protected function checkPhaseInterval($phase, $start, $end) { @@ -222,4 +222,32 @@ class zeitaufzeichnung_import { } } + /** + * @param string $phase The Projektphase ID + * @return void + * + * @throws Exception + */ +protected function checkPhaseBebuchbar($phase) +{ + if ($this->phase->getPhasenZA($phase) == 'f') + { + throw new Exception($this->p->t("global/fehlerBeimSpeichernDerDaten") . ': Dieses Arbeitspaket darf nicht bebucht werden!'); + } +} + +/** +* @param string $phase The Projektphase ID +* @return void +* +* @throws Exception +*/ +protected function checkIfArbeitspaketZuWaehlen($projekt_kurzbz, $phase) +{ + if (!$this->project->zeitaufzeichnung && !$phase) + { + throw new Exception($this->p->t("global/fehlerBeimSpeichernDerDaten") . ': Bitte ein Arbeitspaket wählen!'); + } +} + } diff --git a/include/zeitaufzeichnung_import_csv.class.php b/include/zeitaufzeichnung_import_csv.class.php index 27a240e45..8a8e8bb2f 100644 --- a/include/zeitaufzeichnung_import_csv.class.php +++ b/include/zeitaufzeichnung_import_csv.class.php @@ -163,7 +163,8 @@ class zeitaufzeichnung_import_csv extends zeitaufzeichnung_import { $this->initData($data); $this->checkProject($data[self::PROJEKT], $data[self::PHASE]); $this->checkPhase($data[self::PHASE]); - + $this->checkPhaseBebuchbar($data[self::PHASE]); + $this->checkIfArbeitspaketZuWaehlen($data[self::PROJEKT], $data[self::PHASE]); $this->checkZeitsperren($this->user, $this->datum->formatDatum($data[self::STARTDT], 'Y-m-d')); $this->checkSperrdatum($data[self::STARTDT]); $this->checkLimitdatum($data[self::STARTDT]); diff --git a/include/zeitaufzeichnung_import_post.class.php b/include/zeitaufzeichnung_import_post.class.php index a6a59376e..ded9344fb 100644 --- a/include/zeitaufzeichnung_import_post.class.php +++ b/include/zeitaufzeichnung_import_post.class.php @@ -72,6 +72,8 @@ class zeitaufzeichnung_import_post extends zeitaufzeichnung_import { $this->checkDienstreise($this->data['von'], $this->data['bis'], $this->data['aktivitaet_kurzbz']); $this->checkTagesgenau($this->data['bis']); $this->processPause($this->data['von_pause'], $this->data['bis_pause']); + $this->checkPhaseBebuchbar($this->data['projektphase_id']); + $this->checkIfArbeitspaketZuWaehlen($this->data['projekt_kurzbz'], $this->data['projektphase_id']); $this->saveZeit(); } catch (Exception $ex) { $this->addError($ex->getMessage());