aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Siegfried <david.siegfried@uni-vechta.de>2023-03-07 09:27:19 +0000
committerDavid Siegfried <david.siegfried@uni-vechta.de>2023-03-07 09:27:19 +0000
commit57746e90728633b47764f0e0a53773464d754292 (patch)
tree0295a5dd0ad4660d8a9f4a26d76b9971fe9cc88b
parent28ea07fbef7454a65ec0e0fda35e9e0844f23532 (diff)
prevent php-warnings, fixes #2276
Closes #2276 Merge request studip/studip!1501
-rw-r--r--app/views/oer/market/_material_short.php38
-rw-r--r--app/views/oer/market/details.php12
-rw-r--r--lib/models/OERHostOERSI.php8
-rw-r--r--lib/models/OERMaterial.php69
4 files changed, 85 insertions, 42 deletions
diff --git a/app/views/oer/market/_material_short.php b/app/views/oer/market/_material_short.php
index e8a9f11..227b8a1 100644
--- a/app/views/oer/market/_material_short.php
+++ b/app/views/oer/market/_material_short.php
@@ -1,37 +1,23 @@
+<?php
+/**
+ * @var Oer_MarketController $controller
+ * @var OERMaterial $material
+ */
+?>
<article class="contentbox">
- <a href="<?= $controller->url_for('oer/market/details/' . $material->getId()) ?>">
+ <a href="<?= $controller->link_for('oer/market/details', $material) ?>">
<header>
<h1>
- <?
- if ($material['category'] === "video") {
- $icon = "video";
- }
- if ($material['category'] === "audio") {
- $icon = "file-audio";
- }
- if ($material['category'] === "presentation") {
- $icon = "file-pdf";
- }
- if ($material['category'] === "elearning") {
- $icon = "learnmodule";
- }
- if ($material['content_type'] === "application/zip") {
- $icon = "archive3";
- }
- if (!$icon) {
- $icon = "file";
- }
- ?>
- <?= Icon::create($icon, Icon::ROLE_CLICKABLE)->asImg(20, ['class' => "text-bottom"]) ?>
+ <?= $material->getIcon()->asImg(['class' => 'text-bottom']) ?>
<div class="title">
- <? if (strlen($material['name']) > 50) : ?>
- <?= htmlReady(substr($material['name'], 0, 50)) . ' ...' ?>
+ <? if (strlen($material->name) > 50) : ?>
+ <?= htmlReady(substr($material->name, 0, 50)) . ' ...' ?>
<? else : ?>
- <?= htmlReady($material['name']) ?>
+ <?= htmlReady($material->name) ?>
<? endif ?>
</div>
</h1>
</header>
- <div class="image" style="background-image: url(<?= $material->getLogoURL() ?>);<?= (!$material['front_image_content_type']) ? " background-size: 60% auto;" : "" ?>"></div>
+ <div class="image" style="background-image: url(<?= htmlReady($material->getLogoURL()) ?>);<?= !$material->front_image_content_type ? ' background-size: 60% auto;' : '' ?>"></div>
</a>
</article>
diff --git a/app/views/oer/market/details.php b/app/views/oer/market/details.php
index 60468bb..7b6b3ec 100644
--- a/app/views/oer/market/details.php
+++ b/app/views/oer/market/details.php
@@ -158,19 +158,19 @@
<ul class="author_information clean">
<? foreach ($material->getAuthors() as $authordata) : ?>
<li>
- <div class="avatar" style="background-image: url('<?= htmlReady($authordata['avatar'] ?: Avatar::getNobody()->getURL(Avatar::MEDIUM)) ?>');"></div>
+ <div class="avatar" style="background-image: url('<?= htmlReady($authordata['avatar'] ?? Avatar::getNobody()->getURL(Avatar::MEDIUM)) ?>');"></div>
<div>
<div class="author_name">
- <? if ($authordata['link']) : ?>
+ <? if (isset($authordata['link'])) : ?>
<a href="<?= htmlReady($authordata['link']) ?>">
<? endif ?>
- <?= htmlReady($authordata['name']) ?>
- <? if ($authordata['link']) : ?>
+ <?= htmlReady($authordata['name'] ?? '') ?>
+ <? if (isset($authordata['link'])) : ?>
</a>
<? endif ?>
</div>
- <div class="author_host">(<?= htmlReady($authordata['hostname']) ?>)</div>
- <? if ($authordata['description']) : ?>
+ <div class="author_host">(<?= htmlReady($authordata['hostname'] ?? '') ?>)</div>
+ <? if (isset($authordata['description'])) : ?>
<div class="description"><?= formatReady($authordata['description']) ?></div>
<? endif ?>
</div>
diff --git a/lib/models/OERHostOERSI.php b/lib/models/OERHostOERSI.php
index 11a61fb..f4b0c60 100644
--- a/lib/models/OERHostOERSI.php
+++ b/lib/models/OERHostOERSI.php
@@ -98,13 +98,12 @@ class OERHostOERSI extends OERHost
$data['filename'] = '';
$data['short_description'] = '';
$data['description'] = $output['description'] ?: '';
- $data['difficulty_start'] = 0;
$data['difficulty_start'] = 12;
$data['uri'] = $output['encoding'][0]['contentUrl'] ?: '';
$data['source_url'] = $output['id'];
$data['content_type'] = $output['encoding'][0]['encodingFormat'] ?: '';
$data['license_identifier'] = $this->getLicenseID($output['license']['id']) ?: '';
- if (!$data['category']) {
+ if (empty($data['category'])) {
$data['category'] = $material->autoDetectCategory();
}
$data['front_image_content_type'] = $output['image'] ? 'image/jpg' : null;
@@ -113,11 +112,10 @@ class OERHostOERSI extends OERHost
$data['data']['front_image_url'] = $output['image'];
$data['data']['authors'] = $output['creator'];
$data['data']['organization'] = $output['sourceOrganization'][0]['name'] ?: $output['publisher'][0]['name'];
- $data = [
+ return [
'data' => $data,
- 'topics' => $output['keywords']
+ 'topics' => $output['keywords'] ?? []
];
- return $data;
}
} else {
return ['deleted' => 1];
diff --git a/lib/models/OERMaterial.php b/lib/models/OERMaterial.php
index b3430d4..668d822 100644
--- a/lib/models/OERMaterial.php
+++ b/lib/models/OERMaterial.php
@@ -1,5 +1,38 @@
<?php
+/**
+ * @property string $id
+ * @property string $material_id
+ * @property string|null $foreign_material_id
+ * @property string|null $host_id
+ * @property string $name
+ * @property string $category
+ * @property bool $draft
+ * @property string $filename
+ * @property string|null $short_description
+ * @property string $description
+ * @property int $difficulty_start
+ * @property int $difficulty_end
+ * @property string|null $player_url
+ * @property string|null $tool
+ * @property string $content_type
+ * @property string|null $front_image_content_type
+ * @property JSONArrayObject $structure
+ * @property float $rating
+ * @property string $license_identifier
+ * @property string $uri
+ * @property string $uri_hash
+ * @property string|null $published_id_on_twillo
+ * @property string|null $source_url
+ * @property JSONArrayObject $data
+ * @property int $chdate
+ * @property int $mkdate
+ *
+ * @property OERHost $host
+ * @property OERReview[]|SimpleORMapCollection $reviews
+ * @property OERMaterialUser[]|SimpleORMapCollection $users
+ * @property License $license
+ */
class OERMaterial extends SimpleORMap
{
protected static function configure($config = [])
@@ -297,6 +330,32 @@ class OERMaterial extends SimpleORMap
}
}
+ /**
+ * Returns an appropriate icon for the material.
+ *
+ * @param string $role
+ * @return Icon
+ */
+ public function getIcon(string $role = Icon::ROLE_CLICKABLE): Icon
+ {
+ $icon = 'file';
+ if ($this->category === 'video') {
+ $icon = 'video';
+ } elseif ($this->category === 'audio') {
+ $icon = 'file-audio';
+ } elseif ($this->category === 'presentation') {
+ $icon = 'file-pdf';
+ } elseif ($this->category === 'elearning') {
+ $icon = 'learnmodule';
+ }
+
+ if ($this->content_type === 'application/zip') {
+ $icon = 'archive3';
+ }
+
+ return Icon::create($icon, $role);
+ }
+
public function isFolder()
{
return (bool) $this['structure'];
@@ -436,7 +495,7 @@ class OERMaterial extends SimpleORMap
return false;
}
- if ($data['deleted']) {
+ if (!empty($data['deleted'])) {
return "deleted";
}
@@ -448,12 +507,12 @@ class OERMaterial extends SimpleORMap
$this->store();
//topics:
- $this->setTopics($data['topics']);
+ $this->setTopics($data['topics'] ?? []);
//user:
- $this->setUsers($data['users']);
-
- foreach ((array) $data['reviews'] as $review_data) {
+ $this->setUsers($data['users'] ?? []);
+ $reviews = $data['reviews'] ?? [];
+ foreach ($reviews as $review_data) {
$currenthost = OERHost::findOneByUrl(trim($review_data['host']['url']));
if (!$currenthost) {
$currenthost = new OERHost();