From 1cfbd1ec39497811b12cfac69c27e44e8bd0ef4d Mon Sep 17 00:00:00 2001 From: Elmar Ludwig <elmar.ludwig@uni-osnabrueck.de> Date: Tue, 25 Jul 2023 15:09:09 +0200 Subject: [PATCH] update coding style --- Stundenzettel.class.php | 20 ++--- controllers/index.php | 46 +++++------ controllers/timesheet.php | 78 +++++++++---------- cronjobs/ReminderEmail.php | 4 +- migrations/001_stumi_stundenzettel_tables.php | 4 +- models/StundenzettelContract.class.php | 42 +++++----- .../StundenzettelInstituteSetting.class.php | 2 +- models/StundenzettelRecord.class.php | 18 ++--- models/StundenzettelTimesheet.class.php | 46 +++++------ views/timesheet/timesheet.php | 26 +++---- 10 files changed, 143 insertions(+), 143 deletions(-) diff --git a/Stundenzettel.class.php b/Stundenzettel.class.php index c6fbb92..3c22610 100644 --- a/Stundenzettel.class.php +++ b/Stundenzettel.class.php @@ -63,7 +63,7 @@ class Stundenzettel extends StudipPlugin implements SystemPlugin Navigation::addItem('contents/stundenzettelverwaltung', $navigation); } - public function getCommentOptions () + public function getCommentOptions() { return array( 'Krank' => $this->_('Krank'), @@ -72,25 +72,25 @@ class Stundenzettel extends StudipPlugin implements SystemPlugin ); } - public function getMonths () + public function getMonths() { return array('01', '02','03','04','05','06','07','08','09','10','11','12'); } - public function getYears () + public function getYears() { return array( '2020', '2021','2022','2023','2024','2025','2026','2027'); } - public function hasStumiAdminrole () + public function hasStumiAdminrole() { return RolePersistence::isAssignedRole($GLOBALS['user']->user_id, 'Stundenzettelverwaltung'); } - public function getAdminInstIds () + public function getAdminInstIds() { $roles = RolePersistence::getAllRoles(); - foreach($roles as $role) { + foreach ($roles as $role) { if ($role->getRolename() == 'Stundenzettelverwaltung') { $role_id = $role->getRoleid(); } @@ -102,15 +102,15 @@ class Stundenzettel extends StudipPlugin implements SystemPlugin public function isInstAdmin($inst_id) { - return in_array($inst_id, self::getAdminInstIds () ); + return in_array($inst_id, self::getAdminInstIds() ); } - public function hasStumiContract () + public function hasStumiContract() { return StundenzettelContract::findByUser_id($GLOBALS['user']->user_id); } - public function isStumiSupervisor () + public function isStumiSupervisor() { return StundenzettelContract::findBySupervisor($GLOBALS['user']->user_id); } @@ -161,7 +161,7 @@ class Stundenzettel extends StudipPlugin implements SystemPlugin //$contracts = get_user_inst_contracts_in_year($user_id, $inst_id, $year); $remaining_vacation = 0; - foreach($contracts as $contract) { + foreach ($contracts as $contract) { $claimed_vacation = $contract->getClaimedVacation($year); //Urlaub der mit Resturlaub aus dem Vorjahr verrechnet werden kann wird in diesem Jahr nicht abgezogen diff --git a/controllers/index.php b/controllers/index.php index b26c877..4699d72 100644 --- a/controllers/index.php +++ b/controllers/index.php @@ -8,17 +8,17 @@ class IndexController extends PluginController { PageLayout::setTitle($this->_("Studentische MitarbeiterInnen - Übersicht")); // Check permissions to be on this site - if ( !($this->plugin->hasStumiAdminrole() || $this->plugin->hasStumiContract () || $this->plugin->isStumiSupervisor()) ) { + if (!($this->plugin->hasStumiAdminrole() || $this->plugin->hasStumiContract() || $this->plugin->isStumiSupervisor()) ) { throw new AccessDeniedException($this->_("Sie haben keine Zugriffsberechtigung")); } - if ($this->plugin->hasStumiAdminrole ()) { + if ($this->plugin->hasStumiAdminrole()) { $this->adminrole = true; } - if ($this->plugin->hasStumiContract ()) { + if ($this->plugin->hasStumiContract()) { $this->stumirole = true; } - if ($this->plugin->isStumiSupervisor ()) { + if ($this->plugin->isStumiSupervisor()) { $this->supervisorrole = true; } @@ -88,7 +88,7 @@ class IndexController extends PluginController { $user_ids[] = $former_stumi->user_id; } } - if (sizeof($this->inst_data[$inst_id][0]['stumis']) > 0){ + if (sizeof($this->inst_data[$inst_id][0]['stumis']) > 0) { array_push($this->groups[$inst_id], 0); } } @@ -99,8 +99,8 @@ class IndexController extends PluginController { //get stumis for this user $stumi_contracts = StundenzettelContract::findBySupervisor(User::findCurrent()->user_id); $this->user_ids = []; - foreach($stumi_contracts as $contract){ - if(!in_array($contract->user_id, $this->user_ids)){ + foreach ($stumi_contracts as $contract) { + if (!in_array($contract->user_id, $this->user_ids)) { $this->user_ids[] = $contract->user_id; $this->stumis[] = User::find($contract->user_id); $this->stumi_contracts[$contract->user_id] = StundenzettelContract::findBySQL('`user_id` = ? AND `supervisor` = ?', [$contract->user_id, User::findCurrent()->user_id]); @@ -113,8 +113,8 @@ class IndexController extends PluginController { $this->stumi = User::find($GLOBALS['user']->user_id); $this->stumi_contracts = StundenzettelContract::findByUser_id($this->stumi->user_id); - foreach($this->stumi_contracts as $contract){ - if(!in_array($inst_id, $this->inst_id)){ + foreach ($this->stumi_contracts as $contract) { + if (!in_array($inst_id, $this->inst_id)) { $this->inst_id[] = $inst_id; } } @@ -125,7 +125,7 @@ class IndexController extends PluginController { public function new_action($inst_id, $user_id) { - if ( !$this->adminrole ) { + if (!$this->adminrole ) { throw new AccessDeniedException($this->_("Sie haben keine Zugriffsberechtigung")); } @@ -140,7 +140,7 @@ class IndexController extends PluginController { public function edit_action($contract_id, $following_contract = NULL) { - if ( !$this->adminrole ) { + if (!$this->adminrole ) { throw new AccessDeniedException($this->_("Sie haben keine Zugriffsberechtigung")); } @@ -160,7 +160,7 @@ class IndexController extends PluginController { public function add_contract_begin_data_action($contract_id) { - if ( !$this->adminrole ) { + if (!$this->adminrole ) { throw new AccessDeniedException($this->_("Sie haben keine Zugriffsberechtigung")); } @@ -170,14 +170,14 @@ class IndexController extends PluginController { public function save_action($inst_id, $user_id, $contract_id = NULL) { - if ( !$this->adminrole ) { + if (!$this->adminrole ) { throw new AccessDeniedException($this->_("Sie haben keine Zugriffsberechtigung")); } $contract = StundenzettelContract::find($contract_id); $message = $this->_("Änderungen gespeichert."); - if (!$contract || Request::get('following_contract')){ + if (!$contract || Request::get('following_contract')) { $contract = new StundenzettelContract(); $message = $this->_("Vertrag angelegt."); } @@ -202,13 +202,13 @@ class IndexController extends PluginController { public function delete_action($contract_id) { - if ( !$this->adminrole ) { + if (!$this->adminrole ) { throw new AccessDeniedException($this->_("Sie haben keine Zugriffsberechtigung")); } $contract = StundenzettelContract::find($contract_id); - if($contract->delete()){ + if ($contract->delete()) { PageLayout::postMessage(MessageBox::success($this->_("Vertrag gelöscht"))); } else { @@ -221,7 +221,7 @@ class IndexController extends PluginController { public function save_contract_begin_data_action($contract_id) { - if ( !$this->adminrole ) { + if (!$this->adminrole ) { throw new AccessDeniedException($this->_("Sie haben keine Zugriffsberechtigung")); } @@ -233,7 +233,7 @@ class IndexController extends PluginController { $contract->begin_balance = StundenzettelTimesheet::stundenzettel_strtotimespan(Request::get('balance')); $contract->last_year_vacation_remaining = StundenzettelTimesheet::stundenzettel_strtotimespan(Request::get('begin_last_year_vacation_remainig')); - if($contract->store()){ + if ($contract->store()) { PageLayout::postMessage(MessageBox::success($this->_("Vertragsdaten gespeichert"))); } else { PageLayout::postMessage(MessageBox::error($this->_("Daten konnten nicht gespeichert werden"))); @@ -245,7 +245,7 @@ class IndexController extends PluginController { public function edit_institute_settings_action($inst_id) { - if ( !$this->plugin->isInstAdmin($inst_id) ) { + if (!$this->plugin->isInstAdmin($inst_id) ) { throw new AccessDeniedException($this->_("Sie haben keine Zugriffsberechtigung")); } $this->groups = Statusgruppen::findByRange_ID($inst_id); @@ -262,19 +262,19 @@ class IndexController extends PluginController { public function save_institute_settings_action($inst_id) { - if ( !$this->plugin->isInstAdmin($inst_id)) { + if (!$this->plugin->isInstAdmin($inst_id)) { throw new AccessDeniedException($this->_("Sie haben keine Zugriffsberechtigung")); } $settings = StundenzettelInstituteSetting::find($inst_id); - if (!$settings ){ + if (!$settings) { $settings = new StundenzettelInstituteSetting($inst_id); } $settings->inst_mail = Request::get('email'); $settings->hilfskraft_statusgruppen = implode(',', Request::getArray('statusgruppen')); - if($settings->store()){ + if ($settings->store()) { PageLayout::postMessage(MessageBox::success($this->_("Konfiguration gespeichert"))); } else { PageLayout::postMessage(MessageBox::error($this->_("Daten konnten nicht gespeichert werden"))); @@ -310,7 +310,7 @@ class IndexController extends PluginController { foreach ($group->members as $member) { $stumi = User::find($member->user_id); $stumi_contracts = StundenzettelContract::findBySQL('`user_id` = ? AND `inst_id` = ?', [$member->user_id, $inst_id]); - foreach ($stumi_contracts as $contract){ + foreach ($stumi_contracts as $contract) { $contract = StundenzettelContract::find($contract->id); $export_data[] = [ $stumi->nachname, diff --git a/controllers/timesheet.php b/controllers/timesheet.php index ccd33ed..4a0c8f9 100644 --- a/controllers/timesheet.php +++ b/controllers/timesheet.php @@ -8,17 +8,17 @@ class TimesheetController extends PluginController { PageLayout::setTitle($this->_("Stundenzettel verwalten")); // Check permissions to be on this site - if ( !($this->plugin->hasStumiAdminrole() || $this->plugin->hasStumiContract () || $this->plugin->isStumiSupervisor()) ) { + if (!($this->plugin->hasStumiAdminrole() || $this->plugin->hasStumiContract() || $this->plugin->isStumiSupervisor()) ) { throw new AccessDeniedException($this->_("Sie haben keine Zugriffsberechtigung.")); } - if ($this->plugin->hasStumiAdminrole ()) { + if ($this->plugin->hasStumiAdminrole()) { $this->adminrole = true; } - if ($this->plugin->hasStumiContract ()) { + if ($this->plugin->hasStumiContract()) { $this->stumirole = true; } - if ($this->plugin->isStumiSupervisor ()) { + if ($this->plugin->isStumiSupervisor()) { $this->supervisorrole = true; } @@ -31,7 +31,7 @@ class TimesheetController extends PluginController { { Navigation::activateItem('contents/stundenzettelverwaltung/timesheets'); - if (Request::get('contract_select')){ + if (Request::get('contract_select')) { $contract_id = Request::get('contract_select'); } @@ -46,15 +46,15 @@ class TimesheetController extends PluginController { $this->inst_id = []; $this->stumi_contracts = StundenzettelContract::findByUser_id($GLOBALS['user']->user_id); - foreach($this->stumi_contracts as $contract){ - if(!in_array($inst_id, $this->inst_id)){ + foreach ($this->stumi_contracts as $contract) { + if (!in_array($inst_id, $this->inst_id)) { $this->inst_id[] = $inst_id; } } - if (!$this->contract){ + if (!$this->contract) { throw new AccessDeniedException($this->_("Kein aktiver Vertrag gefunden.")); - } else if (!$this->contract->can_read(User::findCurrent())){ + } else if (!$this->contract->can_read(User::findCurrent())) { throw new AccessDeniedException($this->_("Sie haben keine Zugriffsberechtigung.")); } $this->timesheets = StundenzettelTimesheet::findByContract_id($contract_id, 'ORDER by `year` ASC, `month` ASC'); @@ -67,7 +67,7 @@ class TimesheetController extends PluginController { } public function admin_index_action() { - if (!($this->adminrole || $this->supervisorrole)){ + if (!($this->adminrole || $this->supervisorrole)) { throw new AccessDeniedException($this->_("Sie haben keine Zugriffsberechtigung.")); } Navigation::activateItem('contents/stundenzettelverwaltung/timesheets'); @@ -102,7 +102,7 @@ class TimesheetController extends PluginController { public function select_action($contract_id, $month = '', $year = '') { - if ( !($this->adminrole || $this->plugin->can_access_contract_timesheets($contract_id))) { + if (!($this->adminrole || $this->plugin->can_access_contract_timesheets($contract_id))) { throw new AccessDeniedException($this->_("Sie haben keine Zugriffsberechtigung")); } @@ -115,7 +115,7 @@ class TimesheetController extends PluginController { $this->timesheet = StundenzettelTimesheet::getContractTimesheet($contract_id, $month, $year); if (!$this->timesheet && $this->stumirole) { if ($contract->monthPartOfContract($month, $year) && $contract->monthWithinRecordingTime($month, $year)) { - //if ( (intval($contract->contract_begin) < strtotime($year . '-' . $month . '-28')) && (strtotime($year . '-' . $month . '-01') < intval($contract->contract_end)) ) { + //if ((intval($contract->contract_begin) < strtotime($year . '-' . $month . '-28')) && (strtotime($year . '-' . $month . '-01') < intval($contract->contract_end)) ) { $timesheet = new StundenzettelTimesheet(); $timesheet->month = $month; $timesheet->year = $year; @@ -130,7 +130,7 @@ class TimesheetController extends PluginController { $this->contract = $contract; $this->render_action('timesheet'); } - } else if (!$this->timesheet && $this->adminrole){ + } else if (!$this->timesheet && $this->adminrole) { PageLayout::postMessage(MessageBox::error($this->_("Für diesen Monat liegt kein Stundenzettel vor."))); $this->render_action('timesheet'); } else { @@ -146,7 +146,7 @@ class TimesheetController extends PluginController { throw new AccessDeniedException($this->_("Sie haben keine Zugriffsberechtigung")); } - if ($this->stumirole){ + if ($this->stumirole) { Navigation::activateItem('contents/stundenzettelverwaltung/timetracking'); } else { Navigation::activateItem('contents/stundenzettelverwaltung/timesheets'); @@ -155,11 +155,11 @@ class TimesheetController extends PluginController { $sidebar = Sidebar::Get(); //Sidebar::Get()->setTitle($this->_('Stundenzettel von ') . $GLOBALS['user']->username); - if(!$timesheet_id && $this->stumirole){ + if (!$timesheet_id && $this->stumirole) { $contract_id = StundenzettelContract::getCurrentContractId($GLOBALS['user']->user_id); //$timesheet = StundenzettelTimesheet::getContractTimesheet($contract_id, date('m'), date('Y')); //$timesheet_id = $timesheet->id; - if (!$contract_id){ + if (!$contract_id) { $contract_id = StundenzettelContract::getSomeContractId($GLOBALS['user']->user_id); } $this->redirect('timesheet/select/' . $contract_id . '/' . date('m') . '/' . date('Y')); @@ -171,11 +171,11 @@ class TimesheetController extends PluginController { $this->user_id = $this->timesheet->contract->user_id; $this->records = StundenzettelRecord::findByTimesheet_Id($timesheet_id, 'ORDER BY day ASC'); - if($this->timesheet->locked && $this->stumirole) { + if ($this->timesheet->locked && $this->stumirole) { PageLayout::postMessage(MessageBox::info($this->_("Der Stundenzettel wurde bereits eingereicht und kann nicht mehr bearbeitet werden. Sollten Änderungen nötig sein, kontaktiere deine/n zuständigen Ansprechpartner/in."))); - } else if(($this->supervisorrole || $this->adminrole) && !$this->timesheet->finished) { + } else if (($this->supervisorrole || $this->adminrole) && !$this->timesheet->finished) { PageLayout::postMessage(MessageBox::info($this->_("Digitaler Stundenzettel wurde noch nicht eingereicht."))); - } else if ($this->timesheet->finished && !$this->adminrole){ + } else if ($this->timesheet->finished && !$this->adminrole) { PageLayout::postMessage(MessageBox::info($this->_("Bearbeitung gesperrt. Sie sind nicht berechtigt Änderungen vorzunehmen"))); } @@ -225,7 +225,7 @@ class TimesheetController extends PluginController { { $timesheet = StundenzettelTimesheet::find($timesheet_id); - if ( !($timesheet->can_edit(User::findCurrent())) && !$this->adminrole ) { + if (!($timesheet->can_edit(User::findCurrent())) && !$this->adminrole ) { throw new AccessDeniedException($this->_("Sie haben keine Zugriffsberechtigung")); } @@ -253,32 +253,32 @@ class TimesheetController extends PluginController { } if ($begin_array[$i]) { $record->begin = strtotime($record->getDate() . ' ' . $begin_array[$i]); - if ($record->begin < strtotime($record->getDate() . ' 06:00') ){ + if ($record->begin < strtotime($record->getDate() . ' 06:00')) { PageLayout::postMessage(MessageBox::error(sprintf($this->_("Arbeitszeit kann frühestens ab 6 Uhr erfasst werden: %s.%s"), $record->day, $timesheet->month ))); $errors = true; } - } else if ($record->begin){ + } else if ($record->begin) { $record->begin = NULL; } if ($end_array[$i]) { $record->end = strtotime($record->getDate() . ' ' . $end_array[$i]); - if ($record->end > strtotime($record->getDate() . ' 23:00') ){ + if ($record->end > strtotime($record->getDate() . ' 23:00')) { PageLayout::postMessage(MessageBox::error(sprintf($this->_("Arbeitszeit kann bis maximal 23 Uhr erfasst werden: %s.%s"), $record->day, $timesheet->month ))); $errors = true; } - } else if ($record->end){ + } else if ($record->end) { $record->end = NULL; } if ($break_array[$i]) { $record->break = StundenzettelTimesheet::stundenzettel_strtotimespan($break_array[$i]); - } else if ($record->break){ + } else if ($record->break) { $record->break = NULL; } $record->entry_mktime = $mktime_array[$i]; $record->defined_comment = ($record->isHoliday()) ? 'Feiertag' : $defined_comment_array[$i]; $record->comment = ($record->isUniClosed()) ? '' : $comment_array[$i]; - if ($record->defined_comment == 'Urlaub'){ - $record->sum = StundenzettelTimesheet::stundenzettel_strtotimespan($sum_array[$i]); + if ($record->defined_comment == 'Urlaub') { + $record->sum = StundenzettelTimesheet::stundenzettel_strtotimespan($sum_array[$i]); } else { $record->calculate_sum(); } @@ -288,10 +288,10 @@ class TimesheetController extends PluginController { } else if ($record->sum > (10*3600)) { PageLayout::postMessage(MessageBox::error(sprintf($this->_("Die tägliche Arbeitszeit darf 10 Stunden nicht überschreiten: %s.%s"), $record->day, $timesheet->month ))); $errors = true; - } else if ($record->sum && ($record->sum > (9*3600)) && ($record->break < 2700)){ + } else if ($record->sum && ($record->sum > (9*3600)) && ($record->break < 2700)) { PageLayout::postMessage(MessageBox::error(sprintf($this->_("Bei einer Arbeitszeit von mehr als neun Stunden ist eine Pause von mindestens 45 Minuten gesetzlich vorgeschrieben: %s.%s"), $record->day, $timesheet->month ))); $errors = true; - } else if ($record->sum && ($record->sum > (6*3600)) && ($record->break < 1800)){ + } else if ($record->sum && ($record->sum > (6*3600)) && ($record->break < 1800)) { PageLayout::postMessage(MessageBox::error(sprintf($this->_("Bei einer Arbeitszeit von mehr als sechs Stunden ist eine Pause von mindestens 30 Minuten gesetzlich vorgeschrieben: %s.%s"), $record->day, $timesheet->month ))); $errors = true; } @@ -300,7 +300,7 @@ class TimesheetController extends PluginController { $errors = true; } - if (!$errors){ + if (!$errors) { $record->store(); } @@ -329,7 +329,7 @@ class TimesheetController extends PluginController { throw new AccessDeniedException($this->_("Stundenzettel wurde noch nicht eingereicht!")); } - if($timesheet){ + if ($timesheet) { // create new PDF document $pdf = new ExportPDF(); $pdf->setPrintHeader(false); @@ -345,7 +345,7 @@ class TimesheetController extends PluginController { public function download_all_action($year, $month) { - if (!($this->adminrole || $this->supervisorrole)){ + if (!($this->adminrole || $this->supervisorrole)) { throw new AccessDeniedException($this->_("Sie haben keine Zugriffsberechtigung.")); } @@ -374,7 +374,7 @@ class TimesheetController extends PluginController { public function send_action($timesheet_id) { $timesheet = StundenzettelTimesheet::find($timesheet_id); - if ( !($timesheet->contract->user_id == User::findCurrent()->user_id)) { + if (!($timesheet->contract->user_id == User::findCurrent()->user_id)) { throw new AccessDeniedException($this->_("Sie haben keine Zugriffsberechtigung")); } @@ -394,12 +394,12 @@ class TimesheetController extends PluginController { public function unlock_action($timesheet_id) { $timesheet = StundenzettelTimesheet::find($timesheet_id); - if ( !$this->adminrole ) { + if (!$this->adminrole ) { throw new AccessDeniedException($this->_("Sie haben keine Zugriffsberechtigung")); } //sämtliche Bestätigungsvorgänge verlieren Gültgkeit, wenn der Stundenzettel zur Veränderung durch Hilfskraft freigegeben wird - if($timesheet){ + if ($timesheet) { $timesheet->finished = false; $timesheet->approved = false; $timesheet->complete = false; @@ -419,11 +419,11 @@ class TimesheetController extends PluginController { { $timesheet = StundenzettelTimesheet::find($timesheet_id); - if ( !($timesheet->contract->supervisor == User::findCurrent()->user_id)) { + if (!($timesheet->contract->supervisor == User::findCurrent()->user_id)) { throw new AccessDeniedException($this->_("Sie haben keine Zugriffsberechtigung")); } - if($timesheet && User::findCurrent()->user_id == $timesheet->contract->supervisor){ + if ($timesheet && User::findCurrent()->user_id == $timesheet->contract->supervisor) { $timesheet->approved = true; $timesheet->approved_at = date('Y-m-d'); $timesheet->approver_id = $GLOBALS['user']->id; @@ -438,12 +438,12 @@ class TimesheetController extends PluginController { public function complete_action($timesheet_id) { - if ( !$this->adminrole ) { + if (!$this->adminrole ) { throw new AccessDeniedException($this->_("Sie haben keine Zugriffsberechtigung")); } $timesheet = StundenzettelTimesheet::find($timesheet_id); - if($timesheet && $this->adminrole){ + if ($timesheet && $this->adminrole) { //toggle status $timesheet->complete = (($timesheet->getCurrentState('complete', 'admin') == 'true') ? false : true); $timesheet->store(); diff --git a/cronjobs/ReminderEmail.php b/cronjobs/ReminderEmail.php index b8cf061..5d789d9 100644 --- a/cronjobs/ReminderEmail.php +++ b/cronjobs/ReminderEmail.php @@ -35,12 +35,12 @@ class ReminderEmail extends CronJob $no_recording_required = ($contract->begin_digital_recording_year == $year) && ($month < $contract->begin_digital_recording_month); - if (!$no_recording_required){ + if (!$no_recording_required) { $timesheet = StundenzettelTimesheet::getContractTimesheet($contract->id, $month, $year); if (!$timesheet) { self::sendMissingTimesheetMail($contract->id, $month, $year); //echo 'Erinnerung -anlegen- versendet an ' . User::find($contract->user_id)->username . ' für Zeitraum ' . $month . ' ' . $year; - } elseif ($timesheet->overdue && !$timesheet->finished) { + } else if ($timesheet->overdue && !$timesheet->finished) { //echo 'Erinnerung -einreichen- versendet an ' . User::find($contract->user_id)->username . ' für Zeitraum ' . $month . ' ' . $year; self::sendOverdueMail($contract->id, $month, $year); } diff --git a/migrations/001_stumi_stundenzettel_tables.php b/migrations/001_stumi_stundenzettel_tables.php index 32f9ecb..0c87c99 100644 --- a/migrations/001_stumi_stundenzettel_tables.php +++ b/migrations/001_stumi_stundenzettel_tables.php @@ -73,8 +73,8 @@ class StumiStundenzettelTables extends Migration $db->exec("DROP TABLE stundenzettel_records"); $roles = RolePersistence::getAllRoles(); - foreach($roles as $role) { - if($role->getRolename() == 'Stundenzettelverwaltung') { + foreach ($roles as $role) { + if ($role->getRolename() == 'Stundenzettelverwaltung') { RolePersistence::deleteRole($role); } } diff --git a/models/StundenzettelContract.class.php b/models/StundenzettelContract.class.php index f737036..0c479ac 100644 --- a/models/StundenzettelContract.class.php +++ b/models/StundenzettelContract.class.php @@ -114,18 +114,18 @@ class StundenzettelContract extends \SimpleORMap protected function before_store() { $contracts = self::findBySQL('user_id = ? AND inst_id = ?', [$this->user_id, $this->inst_id]); - foreach ($contracts as $contract){ - if ($contract->id != $this->id){ - if ( (($this->contract_begin < $contract->contract_begin) && ($contract->contract_begin < $this->contract_end)) || - (($this->contract_begin < $contract->contract_end) && ($contract->contract_end < $this->contract_end)) || - (($contract->contract_begin < $this->contract_begin) && ($contract->contract_end > $this->contract_end)) ) { + foreach ($contracts as $contract) { + if ($contract->id != $this->id) { + if ((($this->contract_begin < $contract->contract_begin) && ($contract->contract_begin < $this->contract_end)) || + (($this->contract_begin < $contract->contract_end) && ($contract->contract_end < $this->contract_end)) || + (($contract->contract_begin < $this->contract_begin) && ($contract->contract_end > $this->contract_end)) ) { throw new Exception(dgettext('stundenzettel', 'Laufzeitüberschneidung mit bestehendem Vertrag')); } } } } - function can_read($user){ + function can_read($user) { if ($this->user_id == $user->user_id || $this->supervisor == $user->user_id || Stundenzettel::isInstAdmin($this->inst_id)) { return true; } @@ -159,13 +159,13 @@ class StundenzettelContract extends \SimpleORMap $all_contracts = self::findBySQL('contract_begin < ? AND contract_end > ?', [$month_end, $month_begin]); $contracts = []; - if ( $GLOBALS['perm']->have_perm('admin')){ + if ($GLOBALS['perm']->have_perm('admin')) { return $all_contracts; } else { - foreach ($all_contracts as $contract){ + foreach ($all_contracts as $contract) { if ($contract->user_id == User::findCurrent()->user_id || $contract->supervisor == User::findCurrent()->user_id || - Stundenzettel::isInstAdmin($contract->inst_id) ){ + Stundenzettel::isInstAdmin($contract->inst_id)) { $contracts[] = $contract; } } @@ -240,7 +240,7 @@ class StundenzettelContract extends \SimpleORMap $interval = date_diff($begin_date, $end_date); $month = $interval->y * 12 + $interval->m; - if ($interval->d >15){ + if ($interval->d >15) { $month++; //php date_diff tut sich hier leider schwer //1.10.2020 bis 31.10.2020 ist ein Monat //aber 1.11.2020-30.11.2020 is 0 Monate und 29 tage @@ -257,7 +257,7 @@ class StundenzettelContract extends \SimpleORMap { $contract_month_in_year = 12; for ($i = 1; $i<= 12; $i++) { - if (!$this->monthPartOfContract($i, $year)){ + if (!$this->monthPartOfContract($i, $year)) { $contract_month_in_year --; } } @@ -270,7 +270,7 @@ class StundenzettelContract extends \SimpleORMap if ($this->contract_begin < strtotime($year . '-' . $month . '-28')) { if ($this->begin_digital_recording_month && $this->begin_digital_recording_year) { if (($year == $this->begin_digital_recording_year && $month < $this->begin_digital_recording_month) || - $year < $this->begin_digital_recording_year ){ + $year < $this->begin_digital_recording_year) { return false; //im Vertragszeitraum und vor konfiguriertem Aufzeichnungbeginn } else return true; //im Vertragszeitraum und nach konfiguriertem Aufzeichnungbeginn } else return true; //im Vertragszeitraum und kein späterer Aufzeichnungbeginn konfiguriert @@ -304,7 +304,7 @@ class StundenzettelContract extends \SimpleORMap } else { - if ($year-1 >= date('Y', $this->contract_begin) && $this->getRemainingVacation($year-1) ) { + if ($year-1 >= date('Y', $this->contract_begin) && $this->getRemainingVacation($year-1) ) { $remaining_claimed_vacation = $this->getRemainingVacation($year-1) - $this->getClaimedVacation($year, $month = 3); //falls Resturlaub nicht reicht, übrigen Urlaub vom Anspruch in diesem Jahr abziehen //positiver Rest verfällt ab April @@ -396,14 +396,14 @@ class StundenzettelContract extends \SimpleORMap $contracts = self::findBySQL('`user_id` = ? AND `inst_id` = ?', [$this->user_id, $this->inst_id]); //durchlaufe alle Monate seit Vertragsbeginn bis Vertragsende - while ($month->getTimestamp() < $this->contract_end){ + while ($month->getTimestamp() < $this->contract_end) { - foreach ($contracts as $contract){ + foreach ($contracts as $contract) { $timesheet = StundenzettelTimesheet::findOneBySQL('`contract_id` = ? AND `month` = ? AND `year` = ?', [$contract->id, $month->format('n'), $month->format('Y')]); //falls zu dem Vertrag ein timesheet für den aktuellen Monat gehört //und timesheet außerhalb des eigentlichen Vertragszeitraumes //dem neuen Vertrag zuordnen - if ($timesheet && !$contract->monthPartOfContract($month->format('n'), $month->format('Y'))){ + if ($timesheet && !$contract->monthPartOfContract($month->format('n'), $month->format('Y'))) { $timesheet->contract_id = $this->id; $timesheet->store(); } @@ -413,12 +413,12 @@ class StundenzettelContract extends \SimpleORMap } } -// function reassign_timesheets(){ +// function reassign_timesheets() { // $timesheets = StundenzettelTimesheet::findByContract_Id($this->id); -// foreach ($timesheets as $timesheet){ -// if (!$this->monthPartOfContract($timesheet->month, $timesheet->year)){ +// foreach ($timesheets as $timesheet) { +// if (!$this->monthPartOfContract($timesheet->month, $timesheet->year)) { // $matching_contract = $this->getUserContractsByMonth($this->user_id, $timesheet->month, $timesheet->year); -// if($matching_contract){ +// if ($matching_contract) { // $timesheet->contract_id = $matching_contract->id; // $timesheet->store(); // } @@ -430,7 +430,7 @@ class StundenzettelContract extends \SimpleORMap { $timesheet = StundenzettelTimesheet::getContractTimesheet($this->id, $month, $year); if (!$timesheet) { - if ( (intval($this->contract_begin) < strtotime($year . '-' . $month . '-28')) && (strtotime($year . '-' . $month . '-01') < intval($this->contract_end)) ) { + if ((intval($this->contract_begin) < strtotime($year . '-' . $month . '-28')) && (strtotime($year . '-' . $month . '-01') < intval($this->contract_end)) ) { $timesheet = new StundenzettelTimesheet(); $timesheet->month = $month; $timesheet->year = $year; diff --git a/models/StundenzettelInstituteSetting.class.php b/models/StundenzettelInstituteSetting.class.php index 0e3ca03..c893ac3 100644 --- a/models/StundenzettelInstituteSetting.class.php +++ b/models/StundenzettelInstituteSetting.class.php @@ -24,7 +24,7 @@ class StundenzettelInstituteSetting extends \SimpleORMap 'foreign_key' => 'institute_id',]; $config['additional_fields']['stumi_statusgroups']['get'] = function ($item) { - foreach (explode(',', $item->hilfskraft_statusgruppen) as $statusgruppen_id){ + foreach (explode(',', $item->hilfskraft_statusgruppen) as $statusgruppen_id) { $groups[] = Statusgruppen::find($statusgruppen_id); } return $groups; diff --git a/models/StundenzettelRecord.class.php b/models/StundenzettelRecord.class.php index 8ed1a82..cac54eb 100644 --- a/models/StundenzettelRecord.class.php +++ b/models/StundenzettelRecord.class.php @@ -36,28 +36,28 @@ class StundenzettelRecord extends \SimpleORMap //formale Vorgaben zum Ausfüllen der Stundenzettel prüfen protected function before_store() { - if ($this->sum < 0){ + if ($this->sum < 0) { throw new Exception(sprintf(dgettext('stundenzettel', 'Gesamtsumme der Arbeitszeit pro Tag muss positiv sein.'))); } - if ($this->sum && ($this->sum > (10*3600))){ + if ($this->sum && ($this->sum > (10*3600))) { throw new Exception(sprintf(dgettext('stundenzettel', 'Die tägliche Arbeitszeit darf 10 Stunden nicht überschreiten.'))); - } else if ($this->sum && ($this->sum > (9*3600)) && ($this->break < 2700)){ + } else if ($this->sum && ($this->sum > (9*3600)) && ($this->break < 2700)) { throw new Exception(sprintf(dgettext('stundenzettel', 'Bei einer Arbeitszeit von mehr als neun Stunden ist eine Pause von mindestens 45 Minuten gesetzlich vorgeschrieben.'))); - } else if ($this->sum && ($this->sum > (6*3600)) && ($this->break < 1800)){ + } else if ($this->sum && ($this->sum > (6*3600)) && ($this->break < 1800)) { throw new Exception(sprintf(dgettext('stundenzettel', 'Bei einer Arbeitszeit von mehr als sechs Stunden ist eine Pause von mindestens 30 Minuten gesetzlich vorgeschrieben.'))); } - if ($this->begin && ($this->begin < strtotime($this->getDate() . ' 06:00'))){ + if ($this->begin && ($this->begin < strtotime($this->getDate() . ' 06:00'))) { throw new Exception(sprintf(dgettext('stundenzettel', 'Arbeitszeit kann frühestens ab 6 Uhr erfasst werden.'))); } - if ($this->end && ($this->end > strtotime($this->getDate() . ' 23:00'))){ + if ($this->end && ($this->end > strtotime($this->getDate() . ' 23:00'))) { throw new Exception(sprintf(dgettext('stundenzettel', 'Arbeitszeit kann bis maximal 23 Uhr erfasst werden'))); } } - function calculate_sum(){ - if(in_array($this->defined_comment, ['Urlaub', 'Krank', 'Feiertag']) && !$this->isWeekend() ) { + function calculate_sum() { + if (in_array($this->defined_comment, ['Urlaub', 'Krank', 'Feiertag']) && !$this->isWeekend() ) { $this->sum = StundenzettelTimesheet::stundenzettel_strtotimespan($this->timesheet->contract->default_workday_time); - } else {//if( $this->begin > 0 && $this->end > $this->begin ) { + } else {//if ($this->begin > 0 && $this->end > $this->begin ) { $this->sum = $this->end - $this->begin - $this->break; } //else { // $this->sum = ''; diff --git a/models/StundenzettelTimesheet.class.php b/models/StundenzettelTimesheet.class.php index 262e11e..391380f 100644 --- a/models/StundenzettelTimesheet.class.php +++ b/models/StundenzettelTimesheet.class.php @@ -30,7 +30,7 @@ class StundenzettelTimesheet extends \SimpleORMap ]; $config['additional_fields']['timesheet_balance']['get'] = function ($item) { - if ($item->month_completed){ + if ($item->month_completed) { return $item->sum - ($item->contract->contract_hours * 3600); } else { return ''; @@ -68,14 +68,14 @@ class StundenzettelTimesheet extends \SimpleORMap parent::configure($config); } - static function getContractTimesheet($contract_id, $month, $year){ + static function getContractTimesheet($contract_id, $month, $year) { $timesheet = StundenzettelTimesheet::findOneBySQL('`contract_id` = ? AND `month` = ? AND `year` = ?', [$contract_id, $month, $year]); return $timesheet; } - function getCurrentState($status, $user_status){ - if ($user_status == 'stumi'){ - switch ($status){ + function getCurrentState($status, $user_status) { + if ($user_status == 'stumi') { + switch ($status) { case 'finished': if ($this->finished) return 'true'; if (!$this->finished && $this->overdue) return 'overdue'; @@ -90,8 +90,8 @@ class StundenzettelTimesheet extends \SimpleORMap } } - if ($user_status == 'supervisor'){ - switch ($status){ + if ($user_status == 'supervisor') { + switch ($status) { case 'finished': if ($this->finished) return 'true'; if (!$this->finished && $this->overdue) return 'overdue'; @@ -107,8 +107,8 @@ class StundenzettelTimesheet extends \SimpleORMap } } - if ($user_status == 'admin'){ - switch ($status){ + if ($user_status == 'admin') { + switch ($status) { case 'finished': if ($this->finished) return 'true'; if (!$this->finished && $this->overdue) return 'overdue'; @@ -157,7 +157,7 @@ class StundenzettelTimesheet extends \SimpleORMap $pdf->Ln(19); //$this->Cell(0, 0, $content, 0, 1, 'L', 0, '', 0, false, 'C', 'C'); - foreach ($records as $record){ + foreach ($records as $record) { //$record->calculate_sum(); $content = $record->begin . ' ' . $record->break . ' ' . $record->end . ' ' . $record->sum . ' ' . $record->defined_comment . ' ' . $record->comment . ' ' . $record->entry_mktime ; @@ -239,19 +239,19 @@ class StundenzettelTimesheet extends \SimpleORMap function is_supervisor($user) { - if ($this->contract->supervisor == $user->user_id){ + if ($this->contract->supervisor == $user->user_id) { return true; } else return false; } - function can_edit($user){ - if (($this->contract->user_id == $user->user_id) && !$this->locked){ + function can_edit($user) { + if (($this->contract->user_id == $user->user_id) && !$this->locked) { return true; } else return false; } //TODO InstAdmin identifizieren und Zugriff erlauben - function can_read($user){ + function can_read($user) { if ($this->contract->can_read($user)) { if ($this->contract->user_id == $user->user_id || (($this->contract->supervisor == $user->user_id) && $this->finished)) { @@ -260,11 +260,11 @@ class StundenzettelTimesheet extends \SimpleORMap } } - function calculate_sum(){ - //if (!$this->locked){ + function calculate_sum() { + //if (!$this->locked) { $records = StundenzettelRecord::findByTimesheet_Id($this->id); $sum = 0; - foreach ($records as $record){ + foreach ($records as $record) { $sum += $record->sum; } $this->sum = $sum; @@ -273,7 +273,7 @@ class StundenzettelTimesheet extends \SimpleORMap } //wird für vacation Berechnung noch benutzt - static function subtractTimes($timea, $timeb){ + static function subtractTimes($timea, $timeb) { $timea_pts = explode(':', $timea); $timeb_pts = explode(':', $timeb); @@ -292,7 +292,7 @@ class StundenzettelTimesheet extends \SimpleORMap return (sprintf("%02s", $hours) . ':' . sprintf("%02s", abs($minutes))); } - static function stundenzettel_strtotimespan($string){ + static function stundenzettel_strtotimespan($string) { $negative = strpos($string, '-'); $pts = explode(':', $string); $minutes = intval($pts[1]); @@ -306,7 +306,7 @@ class StundenzettelTimesheet extends \SimpleORMap } } - static function stundenzettel_strftimespan($timespan){ + static function stundenzettel_strftimespan($timespan) { $hours = floor(abs($timespan) / 3600); $minutes = ($timespan % 3600) / 60; $str = (sprintf("%02s", $hours) . ':' . sprintf("%02s", abs($minutes))); @@ -315,7 +315,7 @@ class StundenzettelTimesheet extends \SimpleORMap } else return $str; } - static function stundenzettel_strtotime($string){ + static function stundenzettel_strtotime($string) { $hours = intval(explode(':', $string)[0]); $time = strtotime($string); if ($hours < 0) { @@ -325,9 +325,9 @@ class StundenzettelTimesheet extends \SimpleORMap } } - static function stundenzettel_strftime($format, $time){ + static function stundenzettel_strftime($format, $time) { $str = strftime($format, $time); - if ($time < 0){ + if ($time < 0) { return '-' . $str; } else { return $str; diff --git a/views/timesheet/timesheet.php b/views/timesheet/timesheet.php index 8ef7546..2de4bae 100644 --- a/views/timesheet/timesheet.php +++ b/views/timesheet/timesheet.php @@ -299,9 +299,9 @@ use Studip\Button, Studip\LinkButton; } var form = document.getElementById('timesheet_form'); - if (form.classList.contains('admin') || form.classList.contains('locked') ){ + if (form.classList.contains('admin') || form.classList.contains('locked')) { var inputs = form.querySelectorAll("input, select"); - for(var i = 0; i < inputs.length; i++){ + for (var i = 0; i < inputs.length; i++) { inputs[i].setAttribute("disabled", true);; } var submit_button = document.getElementById('timesheet_submit'); @@ -331,9 +331,9 @@ use Studip\Button, Studip\LinkButton; document.getElementsByName('entry_mktime' + row_index)[0].value = ''; } - function calculate_sum(begin, end, brk){ + function calculate_sum(begin, end, brk) { - if (begin && end){ + if (begin && end) { if (!brk || brk == '0') { brk = '00:00'; } @@ -374,7 +374,7 @@ use Studip\Button, Studip\LinkButton; } - function autofill_row(row_index){ + function autofill_row(row_index) { var begin = document.getElementsByName('begin' + row_index)[0].value; var end = document.getElementsByName('end' + row_index)[0].value; var brk = document.getElementsByName('break' + row_index)[0].value; @@ -390,12 +390,12 @@ use Studip\Button, Studip\LinkButton; } } - function set_mktime(row_index){ + function set_mktime(row_index) { var today = new Date().toISOString().slice(0, 10); document.getElementsByName('entry_mktime' + row_index)[0].value = today; } - function getDateofRow(row_index){ + function getDateofRow(row_index) { var month = <?= htmlready($timesheet->month) ?>; var year = <?= htmlready($timesheet->year) ?>; var day = row_index; @@ -403,13 +403,13 @@ use Studip\Button, Studip\LinkButton; return row_date; } - function set_time_inputs_in_row_required(row_index){ + function set_time_inputs_in_row_required(row_index) { document.getElementsByName('begin' + row_index)[0].setAttribute("required", ""); document.getElementsByName('end' + row_index)[0].setAttribute("required", ""); document.getElementsByName('entry_mktime' + row_index)[0].setAttribute("required", ""); } - function disable_timetracking(row_index){ + function disable_timetracking(row_index) { document.getElementsByName('begin' + row_index)[0].value = ''; document.getElementsByName('begin' + row_index)[0].style.display = 'none'; document.getElementsByName('begin' + row_index)[0].removeAttribute('required'); @@ -420,13 +420,13 @@ use Studip\Button, Studip\LinkButton; document.getElementsByName('break' + row_index)[0].style.display = 'none'; } - function enable_timetracking(row_index){ + function enable_timetracking(row_index) { document.getElementsByName('begin' + row_index)[0].style.removeProperty("display"); document.getElementsByName('end' + row_index)[0].style.removeProperty("display"); document.getElementsByName('break' + row_index)[0].style.removeProperty("display"); } - function autocalc_sum(row_index){ + function autocalc_sum(row_index) { var default_workday_time = '<?= htmlready($timesheet->contract->default_workday_time) ?>'; document.getElementsByName('sum' + row_index)[0].value = default_workday_time; } @@ -459,13 +459,13 @@ use Studip\Button, Studip\LinkButton; $('.defined_comment').change(function() { var name = this.getAttribute("name"); var rec_index = name.substring(15, 19); - if(this.value == '') { //keine Auswahl + if (this.value == '') { //keine Auswahl enable_timetracking(rec_index); document.getElementsByName('sum' + rec_index)[0].readOnly = true; document.getElementsByName('sum' + rec_index)[0].value = ''; document.getElementsByName('entry_mktime' + rec_index)[0].value = ''; document.getElementsByName('sum' + rec_index)[0].removeAttribute("required"); - } else if(this.value == 'Urlaub') { + } else if (this.value == 'Urlaub') { disable_timetracking(rec_index); document.getElementsByName('sum' + rec_index)[0].readOnly = false; document.getElementsByName('sum' + rec_index)[0].value = ''; -- GitLab