Skip to content

Commit

Permalink
fix various languageMain and DCA issues
Browse files Browse the repository at this point in the history
  • Loading branch information
fritzmg committed Sep 16, 2021
1 parent 6417a1b commit fe35ecd
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/ContaoManager/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function getBundles(ParserInterface $parser)
BundleConfig::create(ContaoEventRegistrationBundle::class)
->setLoadAfter([
ContaoCalendarBundle::class,
'notification_center'
'notification_center',
]),
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Contao\CoreBundle\DataContainer\PaletteManipulator;
use Contao\CoreBundle\ServiceAnnotation\Callback;
use Contao\DataContainer;
use InspiredMinds\ContaoEventRegistration\EventRegistration;

/**
* Removes some fields if the event is not the main record.
Expand All @@ -24,11 +25,24 @@
*/
class ConfigOnLoadCallbackListener
{
private $eventRegistration;

public function __construct(EventRegistration $eventRegistration)
{
$this->eventRegistration = $eventRegistration;
}

public function __invoke(DataContainer $dc): void
{
$event = CalendarEventsModel::findById($dc->id);

if (null === $event || empty($event->languageMain)) {
if (null === $event) {
return;
}

$mainEvent = $this->eventRegistration->getMainEvent($event);
dump($GLOBALS['TL_DCA']['tl_calendar_events']['fields']['languageMain']);
if ((int) $mainEvent->id === (int) $event->id) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __invoke(): array
return [];
}

$forms = $this->db->executeQuery("SELECT id, title FROM tl_form ORDER BY title")->fetchAll();
$forms = $this->db->executeQuery('SELECT id, title FROM tl_form ORDER BY title')->fetchAll();

if (false === $forms) {
return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
namespace InspiredMinds\ContaoEventRegistration\EventListener\DataContainer\CalendarEvents;

use Contao\Backend;
use Contao\CalendarEventsModel;
use Contao\CoreBundle\ServiceAnnotation\Callback;
use Contao\Image;
use Contao\Input;
use Contao\StringUtil;
use InspiredMinds\ContaoEventRegistration\EventRegistration;
use InspiredMinds\ContaoEventRegistration\Model\EventRegistrationModel;

/**
Expand All @@ -26,11 +28,20 @@
*/
class RegistrationsButtonCallbackListener
{
private $eventRegistration;

public function __construct(EventRegistration $eventRegistration)
{
$this->eventRegistration = $eventRegistration;
}

public function __invoke(array $row, ?string $href, string $label, string $title, ?string $icon, string $attributes): string
{
$href = Backend::addToUrl($href.'&id='.($row['languageMain'] ?: $row['id']).(Input::get('nb') ? '&nc=1' : ''));
$mainEvent = $this->eventRegistration->getMainEvent(CalendarEventsModel::findById($row['id']));

$href = Backend::addToUrl($href.'&id='.$mainEvent->id.(Input::get('nb') ? '&nc=1' : ''));

if (0 === EventRegistrationModel::countByPid((int) ($row['languageMain'] ?: $row['id']))) {
if (0 === EventRegistrationModel::countByPid((int) $mainEvent->id)) {
$icon = 'mgroup_.svg';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ public function __invoke(array $row): string

if ($row['cancelled']) {
$icon = 'unpublished.svg';
}
elseif ($row['confirmed']) {
} elseif ($row['confirmed']) {
$icon = 'visible.svg';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ class FormDataLoadCallbackListener
{
public function __invoke($value): string
{
return json_encode(json_decode($value ?? '') ?: [], JSON_PRETTY_PRINT);
return json_encode(json_decode($value ?? '') ?: [], \JSON_PRETTY_PRINT);
}
}
19 changes: 13 additions & 6 deletions src/EventRegistration.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,13 @@ public function addTemplateData(Template $template, CalendarEventsModel $event):
return $this->getRegistrationCount($event);
};

if (!empty($event->languageMain)) {
$event = $this->getMainEvent($event);
$template->reg_min = $event->reg_min;
$template->reg_max = $event->reg_max;
$template->reg_regEnd = $event->reg_regEnd;
$template->reg_cancelEnd = $event->reg_cancelEnd;
$mainEvent = $this->getMainEvent($event);

if ((int) $mainEvent->id !== (int) $event->id) {
$template->reg_min = $mainEvent->reg_min;
$template->reg_max = $mainEvent->reg_max;
$template->reg_regEnd = $mainEvent->reg_regEnd;
$template->reg_cancelEnd = $mainEvent->reg_cancelEnd;
}
}

Expand Down Expand Up @@ -220,6 +221,12 @@ public function getMainEvent(CalendarEventsModel $event): CalendarEventsModel
return $event;
}

$calendar = CalendarModel::findByPk((int) $event->pid);

if (null === $calendar || empty($calendar->master)) {
return $event;
}

$mainEvent = CalendarEventsModel::findById((int) $event->languageMain);

if (null !== $mainEvent) {
Expand Down
1 change: 1 addition & 0 deletions src/Resources/contao/dca/tl_event_registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
'dataContainer' => 'Table',
'ptable' => 'tl_calendar_events',
'closed' => true,
'doNotCopyRecords' => true,
'sql' => [
'keys' => [
'id' => 'primary',
Expand Down

0 comments on commit fe35ecd

Please sign in to comment.