Skip to content

Commit

Permalink
Veranstaltungen-Modul (1.23.1): PSR fixes (#1035)
Browse files Browse the repository at this point in the history
* PSR fixes
* Replace Inline Styling with Bootstrap 5 classes
  • Loading branch information
hhunderter authored Aug 24, 2024
1 parent 07b9331 commit a77afef
Show file tree
Hide file tree
Showing 30 changed files with 779 additions and 620 deletions.
3 changes: 2 additions & 1 deletion application/modules/events/boxes/Events.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @copyright Ilch 2
* @package ilch
Expand All @@ -14,7 +15,7 @@ class Events extends \Ilch\Box
public function render()
{
$eventMapper = new EventMapper();
$userMapper = new UserMapper;
$userMapper = new UserMapper();

$config = \Ilch\Registry::get('config');

Expand Down
21 changes: 14 additions & 7 deletions application/modules/events/boxes/views/events.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php if ($this->get('eventList') != ''): ?>
<?php

/** @var \Ilch\View $this */
?>

<?php if ($this->get('eventList') != '') : ?>
<style>
.eventbox-title-ellipsis {
text-overflow:ellipsis;
Expand All @@ -9,22 +14,24 @@
}
</style>
<ul class="list-unstyled">
<?php foreach ($this->get('eventList') as $eventlist): ?>
<?php $date = new \Ilch\Date($eventlist->getStart()); ?>
<?php if (($this->getUser() && $this->getUser()->hasAccess('module_events')) || is_in_array($this->get('readAccess'), explode(',', $eventlist->getReadAccess()))): ?>
<?php
/** @var \Modules\Events\Models\Events $event */
foreach ($this->get('eventList') as $event) : ?>
<?php $date = new \Ilch\Date($event->getStart()); ?>
<?php if (($this->getUser() && $this->getUser()->hasAccess('module_events')) || is_in_array($this->get('readAccess'), explode(',', $event->getReadAccess()))) : ?>
<li>
<span class="eventbox-title-ellipsis">
<i class="fa-regular fa-calendar"></i>
<a href="<?=$this->getUrl('events/show/event/id/' . $eventlist->getId()) ?>">
<?=$this->escape($eventlist->getTitle()) ?>
<a href="<?=$this->getUrl('events/show/event/id/' . $event->getId()) ?>">
<?=$this->escape($event->getTitle()) ?>
</a>
</span>
<span class="small float-end"><?=$date->format('d.m.y', true) ?></span>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<?php else: ?>
<?php else : ?>
<?=$this->getTrans('noEvent') ?>
<?php endif; ?>
<div align="center"><a href="<?=$this->getUrl('events/show/upcoming/') ?>"><?=$this->getTrans('otherEvents') ?></a></div>
52 changes: 30 additions & 22 deletions application/modules/events/config/config.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @copyright Ilch 2
* @package ilch
Expand Down Expand Up @@ -64,23 +65,27 @@ public function install()

public function uninstall()
{
$this->db()->queryMulti('DROP TABLE `[prefix]_events`;
DROP TABLE `[prefix]_events_entrants`;
DROP TABLE `[prefix]_events_currencies`');
$this->db()->queryMulti("DELETE FROM `[prefix]_config` WHERE `key` = 'event_add_entries_accesses';
DELETE FROM `[prefix]_config` WHERE `key` = 'event_show_members_accesses';
DELETE FROM `[prefix]_config` WHERE `key` = 'event_box_event_limit';
DELETE FROM `[prefix]_config` WHERE `key` = 'event_upcoming_event_limit';
DELETE FROM `[prefix]_config` WHERE `key` = 'event_current_event_limit';
DELETE FROM `[prefix]_config` WHERE `key` = 'event_past_event_limit';
DELETE FROM `[prefix]_config` WHERE `key` = 'event_uploadpath';
DELETE FROM `[prefix]_config` WHERE `key` = 'event_height';
DELETE FROM `[prefix]_config` WHERE `key` = 'event_width';
DELETE FROM `[prefix]_config` WHERE `key` = 'event_size';
DELETE FROM `[prefix]_config` WHERE `key` = 'event_filetypes';
DELETE FROM `[prefix]_config` WHERE `key` = 'event_google_maps_api_key';
DELETE FROM `[prefix]_config` WHERE `key` = 'event_google_maps_map_typ';
DELETE FROM `[prefix]_config` WHERE `key` = 'event_google_maps_zoom';
$this->db()->drop('events', true);
$this->db()->drop('events_entrants', true);
$this->db()->drop('events_currencies', true);

$databaseConfig = new IlchDatabase($this->db());
$databaseConfig->delete('event_add_entries_accesses');
$databaseConfig->delete('event_show_members_accesses');
$databaseConfig->delete('event_box_event_limit');
$databaseConfig->delete('event_upcoming_event_limit');
$databaseConfig->delete('event_current_event_limit');
$databaseConfig->delete('event_past_event_limit');
$databaseConfig->delete('event_uploadpath');
$databaseConfig->delete('event_height');
$databaseConfig->delete('event_width');
$databaseConfig->delete('event_size');
$databaseConfig->delete('event_filetypes');
$databaseConfig->delete('event_google_maps_api_key');
$databaseConfig->delete('event_google_maps_map_typ');
$databaseConfig->delete('event_google_maps_zoom');

$this->db()->queryMulti("
DELETE FROM `[prefix]_modules_folderrights` WHERE `key` = 'events';
DELETE FROM `[prefix]_comments` WHERE `key` LIKE 'events/%';");

Expand All @@ -89,7 +94,7 @@ public function uninstall()
}
}

public function getInstallSql()
public function getInstallSql(): string
{
$installSql =
'CREATE TABLE IF NOT EXISTS `[prefix]_events` (
Expand Down Expand Up @@ -135,18 +140,18 @@ public function getInstallSql()
INSERT INTO `[prefix]_modules_folderrights` (`key`, `folder`) VALUES ("events", "static/upload/image");';

if ($this->db()->ifTableExists('[prefix]_calendar_events')) {
$installSql.='INSERT INTO `[prefix]_calendar_events` (`url`) VALUES ("events/events/index/");';
$installSql .= 'INSERT INTO `[prefix]_calendar_events` (`url`) VALUES ("events/events/index/");';
}
return $installSql;
}

public function getUpdate($installedVersion)
public function getUpdate(string $installedVersion): string
{
switch ($installedVersion) {
case "1.0":
$this->db()->query('ALTER TABLE `[prefix]_events` ADD `website` VARCHAR(255) NOT NULL AFTER `place`;');
$this->db()->query('ALTER TABLE `[prefix]_events` ADD `read_access` VARCHAR(255) NOT NULL DEFAULT \'2,3\' AFTER `show`;');
unlink(APPLICATION_PATH.'/modules/events/views/show/my.php');
unlink(APPLICATION_PATH . '/modules/events/views/show/my.php');
// no break
case "1.1":
case "1.2":
Expand Down Expand Up @@ -196,7 +201,7 @@ public function getUpdate($installedVersion)
case "1.21.0":
case "1.21.1":
// Update description
foreach($this->config['languages'] as $key => $value) {
foreach ($this->config['languages'] as $key => $value) {
$this->db()->query(sprintf("UPDATE `[prefix]_modules_content` SET `description` = '%s' WHERE `key` = 'events' AND `locale` = '%s';", $value['description'], $key));
}
// no break
Expand All @@ -206,7 +211,10 @@ public function getUpdate($installedVersion)
case "1.22.0":
case "1.22.1":
case "1.22.2":
case "1.23.0":
// no break
}

return '"' . $this->config['key'] . '" Update-function executed.';
}
}
3 changes: 2 additions & 1 deletion application/modules/events/controllers/Events.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @copyright Ilch 2
* @package ilch
Expand Down Expand Up @@ -30,7 +31,7 @@ public function indexAction()
}
}

$this->getView()->set('eventList', $eventsMapper->getEntriesForJson($this->getRequest()->getQuery('start'), $this->getRequest()->getQuery('end')))
$this->getView()->set('eventList', $eventsMapper->getEntriesForJson($this->getRequest()->getQuery('start') ?? '', $this->getRequest()->getQuery('end') ?? ''))
->set('readAccess', $readAccess);
}
}
70 changes: 32 additions & 38 deletions application/modules/events/controllers/Index.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @copyright Ilch 2
* @package ilch
Expand All @@ -21,7 +22,7 @@ public function indexAction()
{
$eventMapper = new EventMapper();
$entrantsMapper = new EntrantsMapper();
$userMapper = new UserMapper;
$userMapper = new UserMapper();

$this->getLayout()->getTitle()
->add($this->getTranslator()->trans('menuEvents'));
Expand All @@ -45,10 +46,9 @@ public function indexAction()
}

$this->getView()->set('entrantsMapper', $entrantsMapper)
->set('eventList', $eventMapper->getEntries())
->set('eventListUpcoming', $eventMapper->getEventListUpcoming($upcomingLimit))
->set('eventListCurrent', $eventMapper->getEventListCurrent($currentLimit))
->set('eventListPast', $eventMapper->getEventListPast($pastLimit))
->set('eventListUpcomings', $eventMapper->getEventListUpcoming($upcomingLimit))
->set('eventListCurrents', $eventMapper->getEventListCurrent($currentLimit))
->set('eventListPasts', $eventMapper->getEventListPast($pastLimit))
->set('readAccess', $readAccess);
}

Expand All @@ -61,18 +61,24 @@ public function treatAction()
$userMapper = new UserMapper();
$groupMapper = new GroupMapper();

$event = $eventMapper->getEventById($this->getRequest()->getParam('id'));
if ($this->getRequest()->getParam('id')) {
$eventModel = $eventMapper->getEventById($this->getRequest()->getParam('id'));

if (!$eventModel) {
$this->redirect()
->withMessage('entryNotFound')
->to(['controller' => 'index', 'action' => 'index']);
}

if ($event !== null && $this->getRequest()->getParam('id')) {
$this->getLayout()->getTitle()
->add($this->getTranslator()->trans('menuEvents'))
->add($event->getTitle())
->add($eventModel->getTitle())
->add($this->getTranslator()->trans('edit'));
$this->getLayout()->getHmenu()->add($this->getTranslator()->trans('menuEvents'), ['action' => 'index'])
->add($event->getTitle(), ['controller' => 'show', 'action' => 'event', 'id' => $event->getId()])
->add($this->getTranslator()->trans('edit'), ['action' => 'treat', 'id' => $event->getId()]);
->add($eventModel->getTitle(), ['controller' => 'show', 'action' => 'event', 'id' => $eventModel->getId()])
->add($this->getTranslator()->trans('edit'), ['action' => 'treat', 'id' => $eventModel->getId()]);

$this->getView()->set('event', $eventMapper->getEventById($this->getRequest()->getParam('id')));
$this->getView()->set('event', $eventModel);
} else {
$this->getLayout()->getTitle()
->add($this->getTranslator()->trans('menuEvents'))
Expand All @@ -87,10 +93,7 @@ public function treatAction()
$imageSize = $this->getConfig()->get('event_size');

if ($this->getRequest()->isPost()) {
if ($this->getRequest()->getParam('id')) {
$eventModel->setId($this->getRequest()->getParam('id'));
$event = $eventMapper->getEventById($this->getRequest()->getParam('id'));
}
$image = '';

Validation::setCustomFieldAliases([
'start' => 'startTime',
Expand Down Expand Up @@ -123,10 +126,10 @@ public function treatAction()
$height = $size[1];

if ($file_size <= $imageSize) {
$image = $path.time().'.'.$endung;
$image = $path . time() . '.' . $endung;

if ($this->getRequest()->getParam('id') && $event->getImage() != '') {
$eventMapper->delImageById($this->getRequest()->getParam('id'));
if ($eventModel->getImage() != '') {
$eventMapper->delImageById($eventModel->getId());
}

$eventModel->setImage($image);
Expand Down Expand Up @@ -160,9 +163,6 @@ public function treatAction()
}

if (!$imageError) {
if (!empty($_FILES['image']['name'])) {
$eventModel->setImage($image);
}
if ($this->getConfig()->get('event_google_maps_api_key') != '') {
$eventModel->setLatLong($eventMapper->getLatLongFromAddress($this->getRequest()->getPost('place'), $this->getConfig()->get('event_google_maps_api_key')));
}
Expand All @@ -183,28 +183,22 @@ public function treatAction()
->setCurrency($this->getRequest()->getPost('currency'))
->setPrice($this->getRequest()->getPost('price'))
->setPriceArt($this->getRequest()->getPost('priceArt'))
->setShow($this->getRequest()->getPost('calendarShow'))
->setUserLimit($this->getRequest()->getPost('userLimit'))
->setShow((int)$this->getRequest()->getPost('calendarShow', 0))
->setUserLimit((int)$this->getRequest()->getPost('userLimit', 0))
->setReadAccess($groups);
$eventMapper->save($eventModel);

if ($this->getRequest()->getPost('image_delete') != '') {
$eventMapper->delImageById($this->getRequest()->getParam('id'));
if ($this->getRequest()->getPost('image_delete') != '' && $eventModel->getId()) {
$eventMapper->delImageById($eventModel->getId());

$this->redirect()
->withMessage('saveSuccess')
->to(['action' => 'treat', 'id' => $this->getRequest()->getParam('id')]);
->to(['action' => 'treat', 'id' => $eventModel->getId()]);
}

if ($this->getRequest()->getParam('id')) {
$this->redirect()
->withMessage('saveSuccess')
->to(['controller' => 'show', 'action' => 'event', 'id' => $this->getRequest()->getParam('id')]);
} else {
$this->redirect()
->withMessage('saveSuccess')
->to(['controller' => 'index', 'action' => 'index']);
}
$this->redirect()
->withMessage('saveSuccess')
->to(array_merge(['controller' => 'index', 'action' => 'index'], $eventModel->getId() ? ['id' => $eventModel->getId()] : []));
}
}
$this->addMessage($validation->getErrorBag()->getErrorMessages(), 'danger', true);
Expand All @@ -218,8 +212,8 @@ public function treatAction()
$this->getView()->set('calendarShow', 1);
}

if ($this->getRequest()->getParam('id')) {
$groups = explode(',', $eventMapper->getEventById($this->getRequest()->getParam('id'))->getReadAccess());
if ($eventModel->getId()) {
$groups = explode(',', $eventModel->getReadAccess());
} else {
$groups = [2,3];
}
Expand All @@ -239,7 +233,7 @@ public function treatAction()

public function delAction()
{
if ($this->getRequest()->isSecure()) {
if ($this->getRequest()->isSecure() && $this->getRequest()->getParam('id')) {
$eventMapper = new EventMapper();

$eventMapper->delete($this->getRequest()->getParam('id'));
Expand Down
Loading

0 comments on commit a77afef

Please sign in to comment.