lochmueller / calendarize

📆 Best TYPO3 Calendar ever 📆
http://typo3.org/extensions/repository/view/calendarize
74 stars 84 forks source link

RouteEnhancer: Two events with same title and on same day #762

Closed DavidBruchmann closed 10 months ago

DavidBruchmann commented 12 months ago

How to map two events on the same day when the title is the same too? Imagine a cinema where a movie is shown 3 times a day.

I tried to add some more details like below, it's not working though


    routes:
      -
        routePath: '/{calendarize_event_label}/{index}/{hour}/{minute}'
        _controller: 'Calendar::detail'
...
    aspects:
   ...

      hour:
        type: StaticRangeMapper
        start: '0'
        end: '24'
      minute:
        type: StaticRangeMapper
        start: '0'
        end: '60'

    ....

      calendarize_hour_label:
        type: LocaleModifier
        default: hour
        localeMap:
          -
            locale: 'de_.*'
            value: stunde
      calendarize_minute_label:
        type: LocaleModifier
        default: minute
        localeMap:
          -
            locale: 'de_.*'
            value: minute
lochmueller commented 12 months ago

Hey @DavidBruchmann

Which EXT:calendarize version do you use? In the current version for TYPO3 v11 is already a handling, that the slug information is part of the index table and use collision detection. So this should not a problem anymore. Please check your DB. Could you confirm, that the tx_clanendarize_domain_model_index (not the event!!!) table has two entries with the same „slug“ value?

Related Issue: https://github.com/lochmueller/calendarize/issues/540

Regards, Tim

DavidBruchmann commented 12 months ago

Thanks for the response.

Concerning the entries in tx_calendarize_domain_model_index:
Yes, slugs of same events get a count appended in the form -n with n as integer.
Instead of this integer I'd like to have the date in form H:i, but the - as separator is good.
Adding : in the URL might be a bad idea, so that could be left away.

I've to add that technically it's working, just the format is not like intended.

my versions currently:
calendarize: 12.4.4
TYPO3 11.5.21

okmiim commented 11 months ago

Hi @DavidBruchmann,

in your SitePackage you could add a event listener to modify the slug during generation. The event listener could look something like this:

AddEventTimeSlugListener.php

<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\EventListener;

use HDNET\Calendarize\Event\SlugSuffixGenerationEvent;

final class AddEventTimeSlugListener
{
    public function __invoke(SlugSuffixGenerationEvent $event): void
    {
        // Optional: some additional checks, e.g. based on Model or page id (pid)
        // Get the start_time as seconds since day start
        $startTime = $event->getRecord()['start_time'];
        // Add to the existing slug (e.g. test-20201103) the current time (17-15) resulting in test-20201103-1715
        $newSlug = $event->getSlug() . '-' . date('Hi', $startTime);
        // Update the slug
        $event->setSlug($newSlug);
    }
}

Services.yaml

...
  MyVendor\MyExtension\EventListener\AddEventTimeSlugListener:
    tags:
      - name: event.listener
        identifier: 'addEventTimeSlug'
        event: HDNET\Calendarize\Event\SlugSuffixGenerationEvent

Note: if the slug is still not unique, the counting suffix will be added at later stage

See Listen to an event (TYPO3) for general implementation details.

lochmueller commented 10 months ago

Hey @okmiim thanks for the example and documentation add-on. I think we can close the issue, right?! Regards, Tim

DavidBruchmann commented 10 months ago

Sorry for not coming back yet, I didn't test it yet. Thanks for all the input!