Skip to content

Commit

Permalink
Fixed wrong imports
Browse files Browse the repository at this point in the history
Correctly wired listeners and services
  • Loading branch information
hschottm committed Nov 20, 2024
1 parent b8dffb2 commit 5d03cca
Show file tree
Hide file tree
Showing 38 changed files with 504 additions and 698 deletions.
4 changes: 2 additions & 2 deletions src/DependencyInjection/TagsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function load(array $mergedConfig, ContainerBuilder $container)
new FileLocator(__DIR__.'/../Resources/config')
);

//$loader->load('listener.yml');
//$loader->load('services.yml');
$loader->load('listener.yml');
$loader->load('services.yml');
}
}
53 changes: 53 additions & 0 deletions src/EventListener/DataContainer/ArticleCallbackListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Hschottm\TagsBundle\EventListener\DataContainer;

use Contao\CoreBundle\DependencyInjection\Attribute\AsCallback;
use Contao\DataContainer;
use Doctrine\DBAL\Connection;
use Symfony\Contracts\Translation\TranslatorInterface;


class ArticleCallbackListener
{
public function __construct(
private readonly TranslatorInterface $translator,
private readonly Connection $db,
)
{
}

#[AsCallback(table: 'tl_article', target: 'config.oncopy')]
public function onCopyArticle(int $insertId, DataContainer $dc): void
{
if (!$dc->id) {
return;
}

$objTags = $this->db->prepare("SELECT * FROM tl_tag WHERE tid = ? AND from_table = ?")->executeQuery(array($dc->id, $dc->table));
$tags = array();
while (($row = $objTags->fetchAssociative()) !== false) {
\array_push($tags, array("table" => $dc->table, "tag" => $row['tag']));
}
foreach ($tags as $entry) {
$this->db->prepare("INSERT INTO tl_tag (tid, tag, from_table) VALUES (?, ?, ?)")->executeQuery(array($insertId, $entry['tag'], $entry['table']));
}
}

#[AsCallback(table: 'tl_article', target: 'config.ondelete')]
public function onDeleteArticle(DataContainer $dc, int $undoId): void
{
if (!$dc->id) {
return;
}

$this->db->prepare("DELETE FROM tl_tag WHERE from_table = ? AND tid = ?")
->executeQuery(array($dc->table, $dc->id));
$arrContentElements = $this->db->prepare("SELECT DISTINCT id FROM tl_content WHERE pid = ?")
->executeQuery(array($dc->id));
while (($row = $arrContentElements->fetchAssociative()) !== false) {
$this->db->prepare("DELETE FROM tl_tag WHERE from_table = ? AND tid = ?")
->executeQuery(array('tl_content', $row['id']));
}
}
}
34 changes: 0 additions & 34 deletions src/EventListener/DataContainer/ArticleCopyCallbackListener.php

This file was deleted.

35 changes: 0 additions & 35 deletions src/EventListener/DataContainer/ArticleDeleteCallbackListener.php

This file was deleted.

47 changes: 47 additions & 0 deletions src/EventListener/DataContainer/CalendarCallbackListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Hschottm\TagsBundle\EventListener\DataContainer;

use Contao\CoreBundle\DependencyInjection\Attribute\AsCallback;
use Contao\DataContainer;
use Doctrine\DBAL\Connection;
use Symfony\Contracts\Translation\TranslatorInterface;


class CalendarCallbackListener
{
public function __construct(
private readonly TranslatorInterface $translator,
private readonly Connection $db,
)
{
}

#[AsCallback(table: 'tl_calendar_events', target: 'config.oncopy')]
public function onCopyCalendar(int $insertId, DataContainer $dc): void
{
if (!$dc->id) {
return;
}

$objTags = $this->db->prepare("SELECT * FROM tl_tag WHERE tid = ? AND from_table = ?")->executeQuery(array($dc->id, $dc->table));
$tags = array();
while (($row = $objTags->fetchAssociative()) !== false) {
\array_push($tags, array("table" => $dc->table, "tag" => $row['tag']));
}
foreach ($tags as $entry) {
$this->db->prepare("INSERT INTO tl_tag (tid, tag, from_table) VALUES (?, ?, ?)")->executeQuery(array($insertId, $entry['tag'], $entry['table']));
}
}

#[AsCallback(table: 'tl_calendar_events', target: 'config.ondelete')]
public function onDeleteCalendar(DataContainer $dc, int $undoId): void
{
if (!$dc->id) {
return;
}

$this->db->prepare("DELETE FROM tl_tag WHERE from_table = ? AND tid = ?")
->executeQuery(array($dc->table, $dc->id));
}
}

This file was deleted.

This file was deleted.

47 changes: 47 additions & 0 deletions src/EventListener/DataContainer/ContentCallbackListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Hschottm\TagsBundle\EventListener\DataContainer;

use Contao\CoreBundle\DependencyInjection\Attribute\AsCallback;
use Contao\DataContainer;
use Doctrine\DBAL\Connection;
use Symfony\Contracts\Translation\TranslatorInterface;


class ContentCallbackListener
{
public function __construct(
private readonly TranslatorInterface $translator,
private readonly Connection $db,
)
{
}

#[AsCallback(table: 'tl_content', target: 'config.oncopy')]
public function onCopyContent(int $insertId, DataContainer $dc): void
{
if (!$dc->id) {
return;
}

$objTags = $this->db->prepare("SELECT * FROM tl_tag WHERE tid = ? AND from_table = ?")->executeQuery(array($dc->id, $dc->table));
$tags = array();
while (($row = $objTags->fetchAssociative()) !== false) {
\array_push($tags, array("table" => $dc->table, "tag" => $row['tag']));
}
foreach ($tags as $entry) {
$this->db->prepare("INSERT INTO tl_tag (tid, tag, from_table) VALUES (?, ?, ?)")->executeQuery(array($insertId, $entry['tag'], $entry['table']));
}
}

#[AsCallback(table: 'tl_content', target: 'config.ondelete')]
public function onDeleteContent(DataContainer $dc, int $undoId): void
{
if (!$dc->id) {
return;
}

$this->db->prepare("DELETE FROM tl_tag WHERE from_table = ? AND tid = ?")
->executeQuery(array($dc->table, $dc->id));
}
}
34 changes: 0 additions & 34 deletions src/EventListener/DataContainer/ContentCopyCallbackListener.php

This file was deleted.

28 changes: 0 additions & 28 deletions src/EventListener/DataContainer/ContentDeleteCallbackListener.php

This file was deleted.

Loading

0 comments on commit 5d03cca

Please sign in to comment.