Skip to content
Snippets Groups Projects
Commit 57746e90 authored by David Siegfried's avatar David Siegfried
Browse files

prevent php-warnings, fixes #2276

Closes #2276

Merge request studip/studip!1501
parent 28ea07fb
No related branches found
No related tags found
1 merge request!4Draft: Icon creation
<?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>
......@@ -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>
......
......@@ -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];
......
<?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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment