aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Benz <dennis.benz@uni-osnabrueck.de>2023-09-28 13:20:17 +0200
committerDennis Benz <dennis.benz@uni-osnabrueck.de>2023-09-28 13:31:54 +0200
commit3872927485cd6a60bac61a6e6700c17a0f28e78f (patch)
tree4a1b8230511e8a1840c4abede77a51503e7d0495
parent2bbcfb7bbda30fc0588c1093c9eef36f27d22a60 (diff)
Additional banner for mobile view, ref #3231tic-3231
-rw-r--r--app/controllers/admin/banner.php24
-rw-r--r--app/views/admin/banner/edit.php18
-rw-r--r--app/views/admin/banner/info.php17
-rw-r--r--db/migrations/5.3.22_add_banner_mobile_path.php32
-rw-r--r--lib/models/Banner.class.php19
-rw-r--r--resources/assets/stylesheets/scss/responsive.scss10
-rw-r--r--resources/assets/stylesheets/scss/start.scss4
7 files changed, 110 insertions, 14 deletions
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 @@
<fieldset>
<label>
+ <?= _('Banner:') ?><br>
+
<? if ($banner['banner_path']) : ?>
<?= $banner->toImg(['style' => 'max-width:500px']) ?>
<? else : ?>
@@ -32,6 +34,22 @@
</label>
<label>
+ <?= _('Mobiles Banner (optional):') ?><br>
+
+ <? if ($banner['banner_mobile_path']) : ?>
+ <?= $banner->toImg(['style' => 'max-width:500px'], true) ?>
+ <? else : ?>
+ <?= _('Noch kein Bild hochgeladen') ?>
+ <? endif; ?><br>
+
+ <label class="file-upload">
+ <?= _('Bilddatei auswählen') ?>
+ <input id="imgfile_mobile" name="imgfile_mobile" type="file" accept="image/*">
+ <input type="hidden" name="banner_mobile_path" value="<?= $banner['banner_mobile_path'] ?>">
+ </label>
+ </label>
+
+ <label>
<?= _('Beschreibung:') ?>
<input type="text" id="description" name="description" value="<?= htmlReady($banner['description']) ?>" size="40" maxlength="254">
</label>
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 @@
<table class="default">
<tbody>
<tr>
- <td rowspan="9" colspan="2" style="text-align: center;">
+ <td><?= _("Banner:") ?></td>
+ <td style="text-align: left;">
<? if ($banner['banner_path']): ?>
- <?= $banner->toImg() ?>
+ <?= $banner->toImg(['style' => 'max-width:100%']) ?>
<? else: ?>
<?= _('noch kein Bild hochgeladen') ?>
<? endif; ?>
</td>
</tr>
+ <? if ($banner['banner_mobile_path']) : ?>
+ <tr>
+ <td><?= _("Mobiles Banner:") ?></td>
+ <td style="text-align: left;">
+ <? if ($banner['banner_mobile_path']): ?>
+ <?= $banner->toImg(['style' => 'max-width:100%'], true) ?>
+ <? else: ?>
+ <?= _('noch kein Bild hochgeladen') ?>
+ <? endif; ?>
+ </td>
+ </tr>
+ <? endif; ?>
<tr>
<td><?= _("Beschreibung:") ?></td>
<td>
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 @@
+<?php
+
+
+class AddBannerMobilePath extends Migration
+{
+ public function description()
+ {
+ return 'Add field banner_mobile_path to table banner_ads';
+ }
+
+
+ public function up()
+ {
+ $db = DBManager::get();
+
+ $db->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 = '<a href="%s" target="_blank" rel="noopener noreferrer">%s</a>';
} elseif ($this->target_type === 'none') {
@@ -221,7 +232,7 @@ class Banner extends SimpleORMap
$template = '<a href="%s">%s</a>';
}
- $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;
+ }
}