diff --git a/app/views/oer/market/_material_short.php b/app/views/oer/market/_material_short.php index e8a9f119243cfc4fd56fad825a2314add1342fe5..227b8a1233a575a7d39c8c5ddeadb808a6c688e5 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 60468bbfcb7624986e62c732006112b76366fb9c..7b6b3ec7de292f4dbb1297755872b6d3c9cefbcc 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 11a61fbd29f96d14a1fcc2338bb823ff34984983..f4b0c60a81783a33a82e8f0de1d874d0cbd0dd5e 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 b3430d4e97f6c96bfb3e20cebf7dd230420356c0..668d8223e449234320ac9e159928e56ce5bec69a 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();