Skip to content

Commit

Permalink
Ticket 583: Add current events
Browse files Browse the repository at this point in the history
http://redmine.ilch2.de/issues/583

Further some more fixes like:
user limit was not shown on edit
  • Loading branch information
blackcoder87 committed Jan 21, 2019
1 parent b8bc657 commit 6ea9ebe
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 4 deletions.
1 change: 1 addition & 0 deletions application/modules/events/controllers/Index.php
Expand Up @@ -46,6 +46,7 @@ public function indexAction()
$this->getView()->set('entrantsMapper', $entrantsMapper)
->set('eventList', $eventMapper->getEntries())
->set('eventListUpcoming', $eventMapper->getEventListUpcoming($upcomingLimit))
->set('eventListCurrent', $eventMapper->getEventListCurrent($pastLimit))
->set('eventListPast', $eventMapper->getEventListPast($pastLimit))
->set('readAccess', $readAccess);
}
Expand Down
30 changes: 30 additions & 0 deletions application/modules/events/controllers/Show.php
Expand Up @@ -154,6 +154,36 @@ public function upcomingAction()
->set('readAccess', $readAccess);
}

public function CurrentAction()
{
$eventMapper = new EventMapper();
$entrantsMapper = new EntrantsMapper();
$userMapper = new UserMapper;

$this->getLayout()->getTitle()
->add($this->getTranslator()->trans('menuEvents'))
->add($this->getTranslator()->trans('naviEventsCurrent'));
$this->getLayout()->getHmenu()
->add($this->getTranslator()->trans('menuEvents'), ['controller' => 'index', 'action' => 'index'])
->add($this->getTranslator()->trans('naviEventsCurrent'), ['action' => 'current']);

$user = null;
if ($this->getUser()) {
$user = $userMapper->getUserById($this->getUser()->getId());
}

$readAccess = [3];
if ($user) {
foreach ($user->getGroups() as $us) {
$readAccess[] = $us->getId();
}
}

$this->getView()->set('entrantsMapper', $entrantsMapper)
->set('eventListCurrent', $eventMapper->getEventListCurrent())
->set('readAccess', $readAccess);
}

public function pastAction()
{
$eventMapper = new EventMapper();
Expand Down
28 changes: 26 additions & 2 deletions application/modules/events/mappers/Events.php
Expand Up @@ -127,7 +127,6 @@ public function getEventListUpcoming($limit = null)
}

/**
* @param $userId
* @return EventMapper[]|array
*/
public function getEventListParticipation($userId)
Expand Down Expand Up @@ -163,7 +162,32 @@ public function getEventListPast($limit = null)

$sql = 'SELECT *
FROM `[prefix]_events`
WHERE start < CURDATE()
WHERE end < CURDATE()
ORDER BY start DESC';

if ($limit !== null) { $sql .= ' LIMIT '.$limit; }

$rows = $this->db()->queryArray($sql);

if (empty($rows)) {
return null;
}

$events = [];
foreach ($rows as $row) {
$events[] = $eventMapper->getEventById($row['id']);
}

return $events;
}

public function getEventListCurrent($limit = null)
{
$eventMapper = new EventMapper();

$sql = 'SELECT *
FROM `[prefix]_events`
WHERE start < CURDATE() AND end > CURDATE()
ORDER BY start DESC';

if ($limit !== null) { $sql .= ' LIMIT '.$limit; }
Expand Down
2 changes: 2 additions & 0 deletions application/modules/events/translations/de.php
Expand Up @@ -24,6 +24,7 @@
'entry' => 'Eintritt',

'menuEventUpcoming' => 'Bevorstehende Veranstaltungen',
'menuEventCurrent' => 'Derzeitige Veranstaltungen',
'menuEventAll' => 'Alle Veranstaltungen',
'menuEventPast' => 'Vergangene Veranstaltungen',
'menuEventHost' => 'Meine Veranstaltungen',
Expand All @@ -46,6 +47,7 @@
'navigation' => 'Navigation',
'naviEventsAll' => 'Alle',
'naviEventsUpcoming' => 'Bevorstehende',
'naviEventsCurrent' => 'Derzeitige',
'naviEventsPast' => 'Vergangene',
'naviEventsAdd' => 'Erstellen',
'naviEventsParticipation' => 'Teilnahme',
Expand Down
2 changes: 2 additions & 0 deletions application/modules/events/translations/en.php
Expand Up @@ -24,6 +24,7 @@
'entry' => 'Entry',

'menuEventUpcoming' => 'Upcoming events',
'menuEventCurrent' => 'Current events',
'menuEventAll' => 'All events',
'menuEventPast' => 'Past events',
'menuEventHost' => 'My events',
Expand All @@ -46,6 +47,7 @@
'navigation' => 'Navigation',
'naviEventsAll' => 'All',
'naviEventsUpcoming' => 'Upcoming',
'naviEventsCurrent' => 'Current',
'naviEventsPast' => 'Past',
'naviEventsAdd' => 'Add',
'naviEventsParticipation' => 'Participation',
Expand Down
56 changes: 55 additions & 1 deletion application/modules/events/views/index/index.php
Expand Up @@ -4,7 +4,7 @@

<?php include APPLICATION_PATH.'/modules/events/views/index/navi.php'; ?>

<?php if ($this->get('eventListUpcoming') == '' AND $this->get('getEventList') == '' AND $this->get('eventListPast') == ''): ?>
<?php if ($this->get('eventListUpcoming') == '' AND $this->get('eventListCurrent') == '' AND $this->get('getEventList') == '' AND $this->get('eventListPast') == ''): ?>
<h1><?=$this->getTrans('menuEventAll') ?></h1>
<div class="row">
<div class="col-lg-12"><?=$this->getTrans('noEvent') ?></div>
Expand Down Expand Up @@ -69,6 +69,60 @@
</div>
<?php endif; ?>

<?php if ($this->get('eventListCurrent') != ''): ?>
<h1><?=$this->getTrans('menuEventCurrent') ?></h1>
<div class="row">
<div class="col-lg-12">
<ul class="event-list">
<?php foreach ($this->get('eventListCurrent') as $eventlist): ?>
<?php $eventEntrants = $entrantsMapper->getEventEntrantsById($eventlist->getId()) ?>
<?php $date = new \Ilch\Date($eventlist->getStart()); ?>
<?php $agree = 0; $maybe = 0; ?>
<?php if (is_in_array($this->get('readAccess'), explode(',', $eventlist->getReadAccess())) OR $this->getUser() AND $this->getUser()->hasAccess('module_events')): ?>
<li>
<time>
<span class="day"><?=$date->format("j", true) ?></span>
<span class="month"><?=$this->getTrans($date->format('M', true)) ?></span>
</time>
<div class="info">
<h2 class="title"><a href="<?=$this->getUrl('events/show/event/id/' . $eventlist->getId()) ?>"><?=$this->escape($eventlist->getTitle()) ?></a></h2>
<p class="desc">
<?php $place = explode(', ', $this->escape($eventlist->getPlace()), 2); ?>
<?=$place[0] ?>
<?php if (!empty($place[1])): ?>
<br /><span class="text-muted"><?=$place[1] ?></span>
<?php endif; ?>
</p>
<?php if ($eventEntrants != ''): ?>
<?php foreach ($eventEntrants as $eventEntrantsUser): ?>
<?php if ($eventEntrantsUser->getStatus() == 1): ?>
<?php $agree++; ?>
<?php elseif ($eventEntrantsUser->getStatus() == 2): ?>
<?php $maybe++; ?>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
<ul>
<?php if ($eventlist->getUserLimit() > 0): ?>
<li style="width:25%;"><?=$this->getTrans('guest') ?></li>
<li style="width:25%;"><?=$agree ?> <i class="fa fa-check"></i></li>
<li style="width:25%;"><?=$maybe ?> <i class="fa fa-question"></i></li>
<li style="width:25%;"><?=$eventlist->getUserLimit() ?> <i class="fa fa-users"></i></li>
<?php else: ?>
<li style="width:33%;"><?=$this->getTrans('guest') ?></li>
<li style="width:33%;"><?=$agree ?> <i class="fa fa-check"></i></li>
<li style="width:33%;"><?=$maybe ?> <i class="fa fa-question"></i></li>
<?php endif; ?>
</ul>
</div>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
</div>
</div>
<?php endif; ?>

<?php if ($this->get('eventListPast') != ''): ?>
<h1><?=$this->getTrans('menuEventPast') ?></h1>
<div class="row">
Expand Down
1 change: 1 addition & 0 deletions application/modules/events/views/index/navi.php
Expand Up @@ -21,6 +21,7 @@
<ul class="nav navbar-nav">
<li <?php if ($this->getRequest()->getActionName() == 'index') { echo 'class="active"'; } ?>><a href="<?=$this->getUrl(['controller' => 'index', 'action' => 'index']); ?>"><i class="fa fa-list"></i>&nbsp; <?=$this->getTrans('naviEventsAll') ?></a></li>
<li <?php if ($this->getRequest()->getActionName() == 'upcoming') { echo 'class="active"'; } ?>><a href="<?=$this->getUrl(['controller' => 'show', 'action' => 'upcoming']); ?>"><i class="fa fa-history fa-flip-horizontal"></i>&nbsp; <?=$this->getTrans('naviEventsUpcoming') ?></a></li>
<li <?php if ($this->getRequest()->getActionName() == 'current') { echo 'class="active"'; } ?>><a href="<?=$this->getUrl(['controller' => 'show', 'action' => 'current']); ?>"><i class="fa fa-history fa-flip-horizontal"></i>&nbsp; <?=$this->getTrans('naviEventsCurrent') ?></a></li>
<li <?php if ($this->getRequest()->getActionName() == 'past') { echo 'class="active"'; } ?>><a href="<?=$this->getUrl(['controller' => 'show', 'action' => 'past']); ?>"><i class="fa fa-history"></i>&nbsp; <?=$this->getTrans('naviEventsPast') ?></a></li>
<?php if ($this->getUser()): ?>
<li <?php if ($this->getRequest()->getActionName() == 'participation') { echo 'class="active"'; } ?>><a href="<?=$this->getUrl(['controller' => 'show', 'action' => 'participation']); ?>"><i class="fa fa-sign-in"></i>&nbsp; <?=$this->getTrans('naviEventsParticipation') ?></a></li>
Expand Down
2 changes: 1 addition & 1 deletion application/modules/events/views/index/treat.php
Expand Up @@ -197,7 +197,7 @@ class="form-control"
name="userLimit"
step="1"
min="0"
value="<?=($this->get('event') != '') ? $this->escape($this->get('event')->getUserLimit()) : $this->originalInput('userLimit') ?>" />
value="<?=($this->get('event') != '') ? $this->get('event')->getUserLimit() : $this->originalInput('userLimit') ?>" />
</div>
</div>
<div class="form-group">
Expand Down
61 changes: 61 additions & 0 deletions application/modules/events/views/show/current.php
@@ -0,0 +1,61 @@
<?php
$entrantsMapper = $this->get('entrantsMapper');
?>

<?php include APPLICATION_PATH.'/modules/events/views/index/navi.php'; ?>

<h1><?=$this->getTrans('menuEventCurrent') ?></h1>
<div class="row">
<div class="col-lg-12">
<ul class="event-list">
<?php if ($this->get('eventListCurrent') != ''): ?>
<?php foreach ($this->get('eventListCurrent') as $eventlist): ?>
<?php $eventEntrants = $entrantsMapper->getEventEntrantsById($eventlist->getId()) ?>
<?php $date = new \Ilch\Date($eventlist->getStart()); ?>
<?php $agree = 0; $maybe = 0; ?>
<?php if (is_in_array($this->get('readAccess'), explode(',', $eventlist->getReadAccess())) OR $this->getUser() AND $this->getUser()->hasAccess('module_events')): ?>
<li>
<time>
<span class="day"><?=$date->format("j") ?></span>
<span class="month"><?=$this->getTrans($date->format('M')) ?></span>
</time>
<div class="info">
<h2 class="title"><a href="<?=$this->getUrl('events/show/event/id/' . $eventlist->getId()) ?>"><?=$this->escape($eventlist->getTitle()) ?></a></h2>
<p class="desc">
<?php $place = explode(', ', $this->escape($eventlist->getPlace()), 2); ?>
<?=$place[0] ?>
<?php if (!empty($place[1])): ?>
<br /><span class="text-muted"><?=$place[1] ?></span>
<?php endif; ?>
</p>
<?php if ($eventEntrants != ''): ?>
<?php foreach ($eventEntrants as $eventEntrantsUser): ?>
<?php if ($eventEntrantsUser->getStatus() == 1): ?>
<?php $agree++; ?>
<?php elseif ($eventEntrantsUser->getStatus() == 2): ?>
<?php $maybe++; ?>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
<ul>
<?php if ($eventlist->getUserLimit() > 0): ?>
<li style="width:25%;"><?=$this->getTrans('guest') ?></li>
<li style="width:25%;"><?=$agree ?> <i class="fa fa-check"></i></li>
<li style="width:25%;"><?=$maybe ?> <i class="fa fa-question"></i></li>
<li style="width:25%;"><?=$eventlist->getUserLimit() ?> <i class="fa fa-users"></i></li>
<?php else: ?>
<li style="width:33%;"><?=$this->getTrans('guest') ?></li>
<li style="width:33%;"><?=$agree ?> <i class="fa fa-check"></i></li>
<li style="width:33%;"><?=$maybe ?> <i class="fa fa-question"></i></li>
<?php endif; ?>
</ul>
</div>
</li>
<?php endif; ?>
<?php endforeach; ?>
<?php else: ?>
<?=$this->getTrans('noEvent') ?>
<?php endif; ?>
</ul>
</div>
</div>

0 comments on commit 6ea9ebe

Please sign in to comment.