From 95d79f130e55a68649f603df38a2b895c59d23ab Mon Sep 17 00:00:00 2001 From: David Siegfried <david.siegfried@uni-vechta.de> Date: Tue, 7 May 2024 13:47:43 +0000 Subject: [PATCH] prevent php-warnings, closes #4124 Closes #4124 Merge request studip/studip!2969 --- app/controllers/admin/extern.php | 14 +++++++++----- .../extern/extern_config/persondetails.php | 2 +- app/views/institute/extern/index.php | 2 +- app/views/institute/extern/upload.php | 2 +- lib/classes/StudipTreeNodeCachableTrait.php | 2 +- lib/extern/ExternPage.php | 5 +++-- lib/extern/ExternPageTimetable.php | 3 ++- 7 files changed, 18 insertions(+), 12 deletions(-) diff --git a/app/controllers/admin/extern.php b/app/controllers/admin/extern.php index 41833b12dd9..559868e3351 100644 --- a/app/controllers/admin/extern.php +++ b/app/controllers/admin/extern.php @@ -66,8 +66,8 @@ class Admin_ExternController extends AuthenticatedController ExternPageConfig::findEachBySQL( function ($c) use (&$configs, &$count_not_migrated) { $configs[$c->type][] = $c; - if (isset($c->conf['not_fixed_after_migration'])) { - $count_not_migrated++; + if (isset($c->conf['not_fixed_after_migration'])) { + $count_not_migrated++; } }, "range_id = ?", [$this->range] @@ -165,7 +165,7 @@ class Admin_ExternController extends AuthenticatedController if ($this->page->page_config->isNew()) { PageLayout::postSuccess(sprintf( _('Eine neue externe Seite "%$1s" vom Typ %$2s wurde angelegt.'), - htmlReady($this->page->name), + htmlReady($this->page->name), htmlReady($this->page->type) )); } else { @@ -259,7 +259,11 @@ class Admin_ExternController extends AuthenticatedController */ public function info_action(string $config_id) { - $this->page = ExternPage::get(ExternPageConfig::find($config_id)); + $config = ExternPageConfig::find($config_id); + if (!$config) { + throw new Exception('ExternPageConfig object not found!'); + } + $this->page = ExternPage::get($config); if ($this->page->author) { $this->author = '<a href="' . URLHelper::getLink('dispatch.php/profile', ['username' => $this->page->author->username]) @@ -364,7 +368,7 @@ class Admin_ExternController extends AuthenticatedController $config->author_id = $config->editor_id = $GLOBALS['user']->id; $config->store(); PageLayout::postSuccess( - sprintf(_('Die Konfiguration "%s" wurde erfolgreich importiert.'), + sprintf(_('Die Konfiguration "%s" wurde erfolgreich importiert.'), htmlReady($config->name) )); } diff --git a/app/views/institute/extern/extern_config/persondetails.php b/app/views/institute/extern/extern_config/persondetails.php index 311551d53d8..897703db500 100644 --- a/app/views/institute/extern/extern_config/persondetails.php +++ b/app/views/institute/extern/extern_config/persondetails.php @@ -85,7 +85,7 @@ <select class="nested-select" name="semclass[]" multiple> <? foreach ($GLOBALS['SEM_CLASS'] as $key => $sem_class) : ?> <? if ($sem_class['show_browse']) : ?> - <option value="<?= $key ?>"<?= in_array($key, $page->semclass) ? ' selected' : '' ?>> + <option value="<?= $key ?>"<?= in_array($key, $page->semclass ?? []) ? ' selected' : '' ?>> <?= htmlReady($sem_class['name']) ?> </option> <? endif ?> diff --git a/app/views/institute/extern/index.php b/app/views/institute/extern/index.php index 2fdf31eaea3..a93d9692356 100644 --- a/app/views/institute/extern/index.php +++ b/app/views/institute/extern/index.php @@ -22,7 +22,7 @@ else : ?> </h1> </header> <? foreach ($config_types as $type_id => $config_type): ?> - <? if ($configs[$type_id]) : ?> + <? if (!empty($configs[$type_id])) : ?> <article id="<?= $type_id ?>" <? if (Request::option('open_type') === $type_id) echo 'class="open"'; ?>> <header> <h1> diff --git a/app/views/institute/extern/upload.php b/app/views/institute/extern/upload.php index 92b289419b4..675f31a58f6 100644 --- a/app/views/institute/extern/upload.php +++ b/app/views/institute/extern/upload.php @@ -16,7 +16,7 @@ <div style="font-size: smaller;"> (<?= _('Ohne Angabe wird der Name aus den importierten Daten genommen.') ?>) </div> - <input type="text" name="config_name" value="<?= htmlReady($config_name) ?>"> + <input type="text" name="config_name" value="<?= htmlReady($config_name ?? '') ?>"> </label> <label> <?= _('Konfigurationsdatei') ?> diff --git a/lib/classes/StudipTreeNodeCachableTrait.php b/lib/classes/StudipTreeNodeCachableTrait.php index 31823acee79..d40cf70b475 100644 --- a/lib/classes/StudipTreeNodeCachableTrait.php +++ b/lib/classes/StudipTreeNodeCachableTrait.php @@ -37,7 +37,7 @@ trait StudipTreeNodeCachableTrait return $config; } - protected function getDescendantIds(): array + public function getDescendantIds(): array { $cache = self::getDescendantsCacheArray(); diff --git a/lib/extern/ExternPage.php b/lib/extern/ExternPage.php index 8ed0e96509c..d775bc4ac59 100644 --- a/lib/extern/ExternPage.php +++ b/lib/extern/ExternPage.php @@ -138,7 +138,7 @@ abstract class ExternPage $extract[] = array_values(array_filter(array_map('trim', explode(' ', $one)))); } foreach ($extract as $one) { - $return[$one[0]] = $one[1]; + $return[$one[0]] = $one[1] ?? null; } return $return; } @@ -236,7 +236,7 @@ abstract class ExternPage $allowed_params = $this->getAllowedRequestParams(true); $config_fields = $this->getConfigFields(true); foreach ($allowed_params as $param_name) { - $method = $config_fields[$param_name] ?: 'get'; + $method = $config_fields[$param_name] ?? 'get'; $param_value = Request::$method($param_name); if ($param_value) { $this->setValue($param_name, $param_value); @@ -342,6 +342,7 @@ abstract class ExternPage ): string { if (count($scopes) > 0) { $study_areas = StudipStudyArea::findMany($scopes); + $scopes = []; if ($with_kids) { foreach ($study_areas as $study_area) { diff --git a/lib/extern/ExternPageTimetable.php b/lib/extern/ExternPageTimetable.php index d4276000fc3..5d8dfd992ae 100644 --- a/lib/extern/ExternPageTimetable.php +++ b/lib/extern/ExternPageTimetable.php @@ -162,7 +162,7 @@ class ExternPageTimetable extends ExternPage $time = new DateTime(); switch ($this->date_offset) { case 'start_date': - $time = DateTime::createFromFormat('d.m.Y', $this->date); + $time = $this->date ? DateTime::createFromFormat('d.m.Y', $this->date) : $time; break; case 'current_semester': $semester = Semester::findCurrent(); @@ -228,6 +228,7 @@ class ExternPageTimetable extends ExternPage protected function getContent() { $count = 0; + $date_content = []; foreach ($this->getDates() as $date) { $day = new DateTime(); $day->setTimestamp($date->date)->setTime(0, 0); -- GitLab