Skip to content
Snippets Groups Projects
Commit 28be9e0d authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

ensure forum likes and options are posted, fixes #4692

Closes #4692

Merge request studip/studip!3489
parent 74b6877e
No related branches found
No related tags found
No related merge requests found
...@@ -58,7 +58,7 @@ class Calendar_ScheduleController extends AuthenticatedController ...@@ -58,7 +58,7 @@ class Calendar_ScheduleController extends AuthenticatedController
_('Ausgeblendete Veranstaltungen verstecken'), _('Ausgeblendete Veranstaltungen verstecken'),
$this->indexURL(['semester_id' => Request::get('semester_id')]), $this->indexURL(['semester_id' => Request::get('semester_id')]),
Icon::create('visibility-invisible') Icon::create('visibility-invisible')
); )->asButton();
} else { } else {
$actions->addLink( $actions->addLink(
_('Ausgeblendete Veranstaltungen anzeigen'), _('Ausgeblendete Veranstaltungen anzeigen'),
...@@ -67,7 +67,7 @@ class Calendar_ScheduleController extends AuthenticatedController ...@@ -67,7 +67,7 @@ class Calendar_ScheduleController extends AuthenticatedController
'semester_id' => Request::get('semester_id'), 'semester_id' => Request::get('semester_id'),
]), ]),
Icon::create('visibility-visible') Icon::create('visibility-visible')
); )->asButton();
} }
$actions->addLink( $actions->addLink(
......
...@@ -561,6 +561,10 @@ class Course_Forum_IndexController extends ForumController ...@@ -561,6 +561,10 @@ class Course_Forum_IndexController extends ForumController
*/ */
function like_action($topic_id) function like_action($topic_id)
{ {
if (!Request::isPost()) {
throw new MethodNotAllowedException();
}
ForumPerm::check('like_entry', $this->getId(), $topic_id); ForumPerm::check('like_entry', $this->getId(), $topic_id);
ForumLike::like($topic_id); ForumLike::like($topic_id);
...@@ -580,6 +584,10 @@ class Course_Forum_IndexController extends ForumController ...@@ -580,6 +584,10 @@ class Course_Forum_IndexController extends ForumController
*/ */
function dislike_action($topic_id) function dislike_action($topic_id)
{ {
if (!Request::isPost()) {
throw new MethodNotAllowedException();
}
ForumPerm::check('like_entry', $this->getId(), $topic_id); ForumPerm::check('like_entry', $this->getId(), $topic_id);
ForumLike::dislike($topic_id); ForumLike::dislike($topic_id);
......
...@@ -36,12 +36,13 @@ shuffle($likes); ...@@ -36,12 +36,13 @@ shuffle($likes);
endif ?> endif ?>
<!-- like/dislike links --> <!-- like/dislike links -->
<? if (!in_array($GLOBALS['user']->id, $likes)) : ?> <?php $has_liked = in_array($GLOBALS['user']->id, $likes); ?>
<a href="<?= $controller->link_for('course/forum/index/like/'. $topic_id) ?>" onClick="jQuery('#like_<?= $topic_id ?>').load('<?= $controller->link_for('course/forum/index/like/'. $topic_id) ?>'); return false;"> <button class="as-link"
<?= _('Gefällt mir!'); ?> onclick="$.post('<?= $controller->action_link($has_liked ? 'dislike' : 'like', $topic_id) ?>').done(response => $('#like_<?= htmlReady($topic_id) ?>').html(response));return false;"
</a> >
<? else : ?> <? if ($has_liked) : ?>
<a href="<?= $controller->link_for('course/forum/index/dislike/'. $topic_id) ?>" onClick="jQuery('#like_<?= $topic_id ?>').load('<?= $controller->link_for('course/forum/index/dislike/'. $topic_id) ?>'); return false;"> <?= _('Gefällt mir nicht mehr!'); ?>
<?= _('Gefällt mir nicht mehr!'); ?> <? else: ?>
</a> <?= _('Gefällt mir!'); ?>
<? endif ?> <? endif; ?>
</button>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment