Skip to content

Commit

Permalink
enhance subevent usage in backend
Browse files Browse the repository at this point in the history
  • Loading branch information
koertho committed Feb 18, 2025
1 parent db63596 commit ce33d43
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Changelog
All notable changes to this project will be documented in this file.

## [2.6.0] - 2025-02-18
- Changed: make if visible if in subevent list
- Changed: adjust subevent button icon to indicate if event has subevents
- Changed: require at least php 7.4
- Fixed: missing showSubEvents action label

## [2.5.3] - 2024-12-11
- Fixed: php8 warning

Expand Down
36 changes: 36 additions & 0 deletions classes/EventListener/Hooks/ParseTemplateListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace HeimrichHannot\CalendarPlus\EventListener\Hooks;

use Contao\CalendarModel;
use Contao\Input;
use Contao\Template;
use HeimrichHannot\CalendarPlus\CalendarPlusEventsModel;

class ParseTemplateListener
{
public function __invoke(Template $template): void
{
if ($template->getName() === 'be_main') {
$archiveId = Input::get('pid');
$eventId = Input::get('epid');
if (!$eventId || !$archiveId) {
return;
}

$archiveModel = CalendarModel::class::findByPk($archiveId);
$eventModel = CalendarPlusEventsModel::findByPk($eventId);
if (!$eventModel) {
return;
}

$headlineParts = explode('> <', $template->headline);
unset($headlineParts[array_key_last($headlineParts)]);
$headlineParts[] = 'span>'.$eventModel->title.'</span';
$headlineParts[] = 'span>'.$GLOBALS['TL_LANG']['MSC']['subevents'].'</span>';

$template->headline = implode('> <', $headlineParts);

}
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"issues": "https://github.com/heimrichhannot/contao-calendar_plus/issues"
},
"require": {
"php": "^7.1 || ^8.0",
"php": "^7.4 || ^8.0",
"contao/core-bundle": "^4.4",
"contao-community-alliance/composer-plugin": "~2.4 || ~3.0",
"heimrichhannot/contao-formhybrid": "^3.0",
Expand Down
6 changes: 5 additions & 1 deletion config/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
/**
* Register the namespaces
*/

use HeimrichHannot\CalendarPlus\EventListener\Hooks\ParseTemplateListener;

ClassLoader::addNamespaces(
[
'HeimrichHannot',
Expand Down Expand Up @@ -55,7 +58,8 @@
'HeimrichHannot\CalendarPlus\Controller\PromoterController' => 'system/modules/calendar_plus/classes/Controller/PromoterController.php',
'HeimrichHannot\CalendarPlus\EventFilterForm' => 'system/modules/calendar_plus/classes/EventFilterForm.php',
'HeimrichHannot\CalendarPlus\EventModelHelper' => 'system/modules/calendar_plus/classes/EventModelHelper.php',
'HeimrichHannot\CalendarPlus\Hooks' => 'system/modules/calendar_plus/classes/Hooks.php'
'HeimrichHannot\CalendarPlus\Hooks' => 'system/modules/calendar_plus/classes/Hooks.php',
ParseTemplateListener::class => 'system/modules/calendar_plus/classes/EventListener/Hooks/ParseTemplateListener.php',
]
);

Expand Down
1 change: 1 addition & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
* Hooks
*/
$GLOBALS['TL_HOOKS']['addEventDetailsToTemplate'][] = array('HeimrichHannot\CalendarPlus\Hooks', 'addEventDetailsToTemplate');
$GLOBALS['TL_HOOKS']['parseTemplate'][] = [\HeimrichHannot\CalendarPlus\EventListener\Hooks\ParseTemplateListener::class, '__invoke'];


/**
Expand Down
17 changes: 15 additions & 2 deletions dca/tl_calendar_events.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use HeimrichHannot\CalendarPlus\CalendarPlusEventsModel;
use HeimrichHannot\CalendarPlus\CalendarPlusModel;

$arrDca = &$GLOBALS['TL_DCA']['tl_calendar_events'];
Expand Down Expand Up @@ -226,7 +227,14 @@ public static function filterSubEvents()
$intEpid = \Input::get('epid');

if ($intEpid) {
if (($objEvents = \HeimrichHannot\CalendarPlus\CalendarPlusEventsModel::findBy(['tl_calendar_events.parentEvent=?', 'tl_calendar_events.id!=tl_calendar_events.parentEvent'], [$intEpid], ['order' => 'title'])) !== null) {
$arrDca['list']['sorting']['mode'] = 1;
$arrDca['list']['label']['format'] = '%s <span style="color:#999;padding-left:3px">[%s]</span>';
$arrDca['list']['label']['fields'] = ['title', 'startDate', 'startTime'];
$arrDca['list']['label']['label_callback'] = static function (array $row, string $label) {
return \Contao\System::importStatic('tl_calendar_events')->listEvents($row);
};

if (($objEvents = CalendarPlusEventsModel::findBy(['tl_calendar_events.parentEvent=?', 'tl_calendar_events.id!=tl_calendar_events.parentEvent'], [$intEpid], ['order' => 'title'])) !== null) {
while ($objEvents->next()) {
$arrDca['list']['sorting']['root'][] = $objEvents->id;
}
Expand All @@ -246,7 +254,12 @@ public function editParentEvent(DataContainer $objDc)

public function showSubEvents($row, $href, $label, $title, $icon, $attributes)
{
return '<a href="contao/main.php?do=calendar&amp;table=tl_calendar_events&amp;id=' . $row['pid'] . '&amp;pid=' . $row['pid'].'&amp;epid=' . $row['id'] . '" title="' . specialchars($title) . '"' . $attributes . '>' . Image::getHtml($icon, $label) . '</a> ';
$hasSubEvents = (bool)CalendarPlusEventsModel::countBy('parentEvent', $row['id']);
if (!$hasSubEvents) {
$icon = '/system/modules/calendar_plus/assets/img/icons/show-sub-events_.png';
}

return '<a href="contao?do=calendar&amp;table=tl_calendar_events&amp;id=' . $row['pid'] . '&amp;pid=' . $row['pid'].'&amp;epid=' . $row['id'] . '" title="' . \Contao\StringUtil::specialchars($title) . '"' . $attributes . '>' . Image::getHtml($icon, $label) . '</a> ';
}

public function setDefaultParentEvent($objDc)
Expand Down
7 changes: 6 additions & 1 deletion languages/de/tl_calendar_events.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,9 @@
* Placeholders
*/
$arrLang['placeholders']['q'] = 'Stichwortsuche';
$arrLang['placeholders']['linkedMembers'] = 'Nachnamen eingeben';
$arrLang['placeholders']['linkedMembers'] = 'Nachnamen eingeben';

/**
* Buttons
*/
$arrLang['showSubEvents'] = ['Unterveranstaltungen anzeigen', 'Unterveranstaltungen von ID %s anzeigen'];
7 changes: 6 additions & 1 deletion languages/en/tl_calendar_events.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@
* Placeholders
*/
$arrLang['placeholders']['q'] = 'Keywords';
$arrLang['placeholders']['linkedMembers'] = 'Enter lastname';
$arrLang['placeholders']['linkedMembers'] = 'Enter lastname';

/**
* Buttons
*/
$arrLang['showSubEvents'] = ['Show subevents', 'Show subevents of this event.'];

0 comments on commit ce33d43

Please sign in to comment.