From 3872927485cd6a60bac61a6e6700c17a0f28e78f Mon Sep 17 00:00:00 2001 From: Dennis Benz Date: Thu, 28 Sep 2023 13:20:17 +0200 Subject: Additional banner for mobile view, ref #3231 --- app/controllers/admin/banner.php | 24 +++++++++++------ app/views/admin/banner/edit.php | 18 +++++++++++++ app/views/admin/banner/info.php | 17 ++++++++++-- db/migrations/5.3.22_add_banner_mobile_path.php | 32 +++++++++++++++++++++++ lib/models/Banner.class.php | 19 +++++++++++--- resources/assets/stylesheets/scss/responsive.scss | 10 +++++++ resources/assets/stylesheets/scss/start.scss | 4 +++ 7 files changed, 110 insertions(+), 14 deletions(-) create mode 100644 db/migrations/5.3.22_add_banner_mobile_path.php diff --git a/app/controllers/admin/banner.php b/app/controllers/admin/banner.php index 5199bbc..ee11787 100644 --- a/app/controllers/admin/banner.php +++ b/app/controllers/admin/banner.php @@ -102,6 +102,7 @@ class Admin_BannerController extends AuthenticatedController // edit banner input if (Request::submitted('speichern')) { $banner_path = Request::get('banner_path'); + $banner_mobile_path = Request::get('banner_mobile_path'); $description = Request::get('description'); $alttext = Request::get('alttext'); $target_type = Request::get('target_type'); @@ -132,6 +133,12 @@ class Admin_BannerController extends AuthenticatedController $errors[] = _('Es wurde kein Bild ausgewählt.'); } + // upload mobile banner file + $upload = $_FILES['imgfile_mobile']; + if (!empty($upload['name'])) { + $banner_mobile_path = $this->bannerupload($upload['tmp_name'], $upload['size'], $upload['name'], $errors); + } + $startdate = strtotime(Request::get('start_date', 0)); $enddate = strtotime(Request::get('end_date', 0)); @@ -173,14 +180,15 @@ class Admin_BannerController extends AuthenticatedController PageLayout::postError(_('Es sind folgende Fehler aufgetreten:'), $errors); $this->redirect('admin/banner'); } else { - $banner->banner_path = $banner_path; - $banner->description = $description; - $banner->alttext = $alttext; - $banner->target_type = $target_type; - $banner->target = $target; - $banner->startdate = $startdate; - $banner->enddate = $enddate; - $banner->priority = $priority; + $banner->banner_path = $banner_path; + $banner->banner_mobile_path = $banner_mobile_path; + $banner->description = $description; + $banner->alttext = $alttext; + $banner->target_type = $target_type; + $banner->target = $target; + $banner->startdate = $startdate; + $banner->enddate = $enddate; + $banner->priority = $priority; $banner->store(); $assignedroles = Request::intArray('assignedroles'); diff --git a/app/views/admin/banner/edit.php b/app/views/admin/banner/edit.php index 9bf48f5..b99e108 100644 --- a/app/views/admin/banner/edit.php +++ b/app/views/admin/banner/edit.php @@ -18,6 +18,8 @@
+ + diff --git a/app/views/admin/banner/info.php b/app/views/admin/banner/info.php index be5df97..8fa4cbe 100644 --- a/app/views/admin/banner/info.php +++ b/app/views/admin/banner/info.php @@ -10,14 +10,27 @@ - + + + + + + +
+ - toImg() ?> + toImg(['style' => 'max-width:100%']) ?>
+ + toImg(['style' => 'max-width:100%'], true) ?> + + + +
diff --git a/db/migrations/5.3.22_add_banner_mobile_path.php b/db/migrations/5.3.22_add_banner_mobile_path.php new file mode 100644 index 0000000..8b13b5b --- /dev/null +++ b/db/migrations/5.3.22_add_banner_mobile_path.php @@ -0,0 +1,32 @@ +exec( + "ALTER TABLE `banner_ads` + ADD `banner_mobile_path` varchar(255) COLLATE utf8mb4_unicode_ci NULL AFTER `banner_path`" + ); + } + + + public function down() + { + $db = DBManager::get(); + + $db->exec( + "ALTER TABLE `banner_ads` DROP `banner_mobile_path`" + ); + + } +} diff --git a/lib/models/Banner.class.php b/lib/models/Banner.class.php index 7f3309b..7f0ca25 100644 --- a/lib/models/Banner.class.php +++ b/lib/models/Banner.class.php @@ -17,6 +17,7 @@ * @property string ad_id database column * @property string id alias column for ad_id * @property string banner_path database column + * @property string banner_mobile_path database column * @property string description database column * @property string alttext database column * @property string target_type database column @@ -115,8 +116,11 @@ class Banner extends SimpleORMap public function delete() { if (!$this->isNew()) { - // Remove banner file + // Remove banner files unlink($GLOBALS['DYNAMIC_CONTENT_PATH'] . '/banner/' . $this->banner_path); + if (!empty($this->banner_mobile_path)) { + unlink($GLOBALS['DYNAMIC_CONTENT_PATH'] . '/banner/' . $this->banner_mobile_path); + } } return parent::delete(); } @@ -183,10 +187,15 @@ class Banner extends SimpleORMap * * @return string */ - public function toImg($attributes = []) + public function toImg($attributes = [], $mobile = false) { + $src = $this->banner_path; + if ($mobile && !empty($this->banner_mobile_path)) { + $src = $this->banner_mobile_path; + } + $attr = [ - 'src' => $GLOBALS['DYNAMIC_CONTENT_URL'] . '/banner/' . $this->banner_path, + 'src' => $GLOBALS['DYNAMIC_CONTENT_URL'] . '/banner/' . $src, 'border' => '0', ]; if ($this->alttext) { @@ -213,6 +222,8 @@ class Banner extends SimpleORMap return ''; } + $banner_images = $this->toImg(['class' => 'studip-banner-image']) . $this->toImg(['class' => 'studip-mobile-banner-image'], true); + if ($this->target_type === 'url') { $template = '%s'; } elseif ($this->target_type === 'none') { @@ -221,7 +232,7 @@ class Banner extends SimpleORMap $template = '%s'; } - $link = sprintf($template, $this->getLink($internal), $this->toImg()); + $link = sprintf($template, $this->getLink($internal), $banner_images); $this->views += 1; $this->store(); diff --git a/resources/assets/stylesheets/scss/responsive.scss b/resources/assets/stylesheets/scss/responsive.scss index a1f2a67..5a19bd7 100644 --- a/resources/assets/stylesheets/scss/responsive.scss +++ b/resources/assets/stylesheets/scss/responsive.scss @@ -959,4 +959,14 @@ html:not(.responsive-display):not(.fullscreen-mode) { min-width: 20vw; max-width: 100vw; } + + .studip-banner { + .studip-banner-image { + display: none; + } + + .studip-mobile-banner-image { + display: unset; + } + } } diff --git a/resources/assets/stylesheets/scss/start.scss b/resources/assets/stylesheets/scss/start.scss index 29f2162..fc1e102 100644 --- a/resources/assets/stylesheets/scss/start.scss +++ b/resources/assets/stylesheets/scss/start.scss @@ -220,4 +220,8 @@ div.available-widgets { img { max-width: 100%; } + + .studip-mobile-banner-image { + display: none; + } } -- cgit v1.0