<?php
$forumMapper = $this->get('forumMapper');
$topicMapper = $this->get('topicMapper');
$groupIdsArray = $this->get('groupIdsArray');
$adminAccess = null;
if ($this->getUser()) {
$adminAccess = $this->getUser()->isAdmin();
}
?>
<?php if (!empty($this->get('topics'))): ?>
<ul class="list-unstyled">
<?php foreach ($this->get('topics') as $topic): ?>
<?php $forum = $forumMapper->getForumById($topic['forum_id']); ?>
<?php if (is_in_array($groupIdsArray, explode(',', $forum->getReadAccess())) || $adminAccess == true): ?>
<?php $lastPost = $topicMapper->getLastPostByTopicId($topic['topic_id']) ?>
<?php $date = new \Ilch\Date($lastPost->getDateCreated()); ?>
<li style="line-height: 25px;">
<?php if ($this->getUser()): ?>
<?php if (in_array($this->getUser()->getId(), explode(',', $lastPost->getRead()))): ?>
<img src="<?=$this->getStaticUrl('../application/modules/forum/static/img/topic_read.png') ?>" style="float: left; margin-top: 8px;">
<?php else: ?>
<img src="<?=$this->getStaticUrl('../application/modules/forum/static/img/topic_unread.png') ?>" style="float: left; margin-top: 8px;">
<?php endif; ?>
<?php else: ?>
<img src="<?=$this->getStaticUrl('../application/modules/forum/static/img/topic_read.png') ?>" style="float: left; margin-top: 8px;">
<?php endif; ?>
<a href="<?=$this->getUrl(['module' => 'forum', 'controller' => 'showposts', 'action' => 'index', 'topicid' => $topic['topic_id']]) ?>">
<?=$topic['topic_title'] ?>
</a>
<br />
<small><?=$date->format("d.m.y - H:i", true) ?> <?=$this->getTrans('clock') ?></small>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<?php else: ?>
<?=$this->getTrans('noPosts') ?>
<?php endif; ?>
<?php
/**
* @copyright Ilch 2.0
* @package ilch
*/
namespace Modules\Forum\Boxes;
use Modules\Forum\Mappers\Forum as ForumMapper;
use Modules\Forum\Mappers\Topic as TopicMapper;
use Modules\User\Mappers\User as UserMapper;
class Forum extends \Ilch\Box
{
public function render()
{
$forumMapper = new ForumMapper();
$topicMapper = new TopicMapper();
$userMapper = new UserMapper();
// Add group 'guest' by default
$groupIds = [3];
if ($this->getUser()) {
$userId = $this->getUser()->getId();
$user = $userMapper->getUserById($userId);
$groupIds = [];
foreach ($user->getGroups() as $groups) {
$groupIds[] = $groups->getId();
}
}
$this->getView()->set('forumMapper', $forumMapper);
$this->getView()->set('topicMapper', $topicMapper);
$this->getView()->set('topics', $topicMapper->getLastActiveTopics(5));
$this->getView()->set('groupIdsArray', $groupIds);
}
}