Skip to content
Snippets Groups Projects
Commit b0e3d82e authored by David Siegfried's avatar David Siegfried Committed by Jan-Hendrik Willms
Browse files

move code to controller, closes #806

Closes #806

Merge request !1243
parent 9ee941ec
No related branches found
No related tags found
No related merge requests found
...@@ -25,7 +25,13 @@ class Oer_MarketController extends StudipController ...@@ -25,7 +25,13 @@ class Oer_MarketController extends StudipController
} }
$tag_matrix_entries_number = 9; $tag_matrix_entries_number = 9;
$this->best_nine_tags = OERTag::findBest($tag_matrix_entries_number); $this->best_nine_tags = OERTag::findBest($tag_matrix_entries_number);
$this->tags = [];
foreach ($this->best_nine_tags as $tag) {
$this->tags[] = [
'tag_hash' => $tag->tag_hash,
'name' => $tag->name,
];
}
if (Request::get("tag")) { if (Request::get("tag")) {
$this->materialien = OERMaterial::findByTag(Request::get("tag")); $this->materialien = OERMaterial::findByTag(Request::get("tag"));
} }
...@@ -35,6 +41,22 @@ class Oer_MarketController extends StudipController ...@@ -35,6 +41,22 @@ class Oer_MarketController extends StudipController
if (Request::get("get") === "all") { if (Request::get("get") === "all") {
$this->materialien = OERMaterial::findBySQL("1 ORDER BY oer_material.mkdate DESC"); $this->materialien = OERMaterial::findBySQL("1 ORDER BY oer_material.mkdate DESC");
} }
$this->material_data = false;
if (!empty($this->materialien)) {
$this->material_data = [];
foreach ($this->materialien as $material) {
$data = $material->toRawArray();
$data['tags'] = array_map(function($tag) {
return $tag['name'];
}, $material->getTopics());
$data['logo_url'] = $material->getLogoURL();
$data['download_url'] = $material->getDownloadUrl();
$this->material_data[] = $data;
}
}
$this->new_ones = OERMaterial::findBySQL("LEFT JOIN oer_hosts ON (oer_hosts.host_id = oer_material.host_id) $this->new_ones = OERMaterial::findBySQL("LEFT JOIN oer_hosts ON (oer_hosts.host_id = oer_material.host_id)
WHERE draft = '0' WHERE draft = '0'
AND (oer_material.host_id IS NULL OR oer_hosts.`active` = '1') AND (oer_material.host_id IS NULL OR oer_hosts.`active` = '1')
...@@ -48,6 +70,23 @@ class Oer_MarketController extends StudipController ...@@ -48,6 +70,23 @@ class Oer_MarketController extends StudipController
"); ");
$statement->execute([$GLOBALS['user']->id]); $statement->execute([$GLOBALS['user']->id]);
$this->abo = (bool) $statement->fetch(PDO::FETCH_COLUMN, 0); $this->abo = (bool) $statement->fetch(PDO::FETCH_COLUMN, 0);
if ($GLOBALS['perm']->have_perm('autor')) {
$actions = new ActionsWidget();
$actions->addLink(
_('Neues Lernmaterial hochladen'),
$this->url_for('oer/mymaterial/edit'),
Icon::create('add'),
['data-dialog' => 'size=auto']
);
$actions->addLink(
$this->abo ? _('Neuigkeiten abbestellen') : _('Neuigkeiten abonnieren'),
$this->aboURL(),
Icon::create($this->abo ? 'decline' : 'rss'),
['data-dialog' => 'size=auto']
);
Sidebar::Get()->addWidget($actions);
}
} }
public function get_tags_action() public function get_tags_action()
......
<? <?php
$tags = []; /**
if ($best_nine_tags && count($best_nine_tags) > 0) { * @var Oer_MarketController $controller
foreach ($best_nine_tags as $tag) { * @var array $material_data
$tags[] = [ * @var array $tags
'tag_hash' => $tag['tag_hash'], * @var OERMaterial[] $new_ones
'name' => $tag['name'] */
];
}
}
$material_data = false;
if (!empty($materialien)) {
$material_data = [];
foreach ($materialien as $material) {
$data = $material->toRawArray();
$data['tags'] = array_map(function($tag) {
return $tag['name'];
}, $material->getTopics());
$data['logo_url'] = $material->getLogoURL();
$data['download_url'] = $material->getDownloadUrl();
$material_data[] = $data;
}
}
?> ?>
<form class="oer_search" <form class="oer_search"
action="<?= $controller->link_for("oer/market/search") ?>" action="<?= $controller->search() ?>"
method="GET" aria-live="polite" method="GET" aria-live="polite"
data-searchresults="<?= htmlReady(json_encode($material_data)) ?>" data-searchresults="<?= htmlReady(json_encode($material_data)) ?>"
data-filteredtag="<?= htmlReady(Request::get("tag")) ?>" data-filteredtag="<?= htmlReady(Request::get('tag')) ?>"
data-filteredcategory="<?= htmlReady(Request::get("category")) ?>" data-filteredcategory="<?= htmlReady(Request::get('category')) ?>"
data-tags="<?= htmlReady(json_encode($tags)) ?>" data-tags="<?= htmlReady(json_encode($tags)) ?>"
data-material_select_url_template="<?= htmlReady($controller->url_for('oer/market/details/__material_id__')) ?>"> data-material_select_url_template="<?= htmlReady($controller->detailsURL('__material_id__')) ?>">
<?= $this->render_partial("oer/market/_searchform") ?> <?= $this->render_partial('oer/market/_searchform') ?>
</form> </form>
...@@ -51,19 +33,3 @@ if (!empty($materialien)) { ...@@ -51,19 +33,3 @@ if (!empty($materialien)) {
<? <?
if ($GLOBALS['perm']->have_perm("autor")) {
$actions = new ActionsWidget();
$actions->addLink(
_('Neues Lernmaterial hochladen'),
$controller->url_for("oer/mymaterial/edit"),
Icon::create("add", Icon::ROLE_CLICKABLE),
['data-dialog' => "1"]
);
$actions->addLink(
$abo ? _('Neuigkeiten abbestellen') : _('Neuigkeiten abonnieren'),
$controller->url_for("oer/market/abo"),
$abo ? Icon::create("decline", Icon::ROLE_CLICKABLE) : Icon::create("rss", Icon::ROLE_CLICKABLE),
['data-dialog' => "size=small"]
);
Sidebar::Get()->addWidget($actions);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment