Initial release
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MummertMedia\EventManagerBundle\Service;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
|
||||
class OrganizationRepository
|
||||
{
|
||||
public function __construct(
|
||||
private readonly Connection $connection,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
public function findByMemberId(int $memberId): array
|
||||
{
|
||||
return $this->connection->createQueryBuilder()
|
||||
->select('o.*')
|
||||
->from('tl_organization', 'o')
|
||||
->innerJoin('o', 'tl_member_organization', 'mo', 'mo.organization_id = o.id')
|
||||
->where('mo.member_id = :memberId')
|
||||
->setParameter('memberId', $memberId, ParameterType::INTEGER)
|
||||
->orderBy('o.title', 'ASC')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
}
|
||||
|
||||
public function memberHasOrganization(int $memberId, int $organizationId): bool
|
||||
{
|
||||
$exists = $this->connection->createQueryBuilder()
|
||||
->select('1')
|
||||
->from('tl_member_organization', 'mo')
|
||||
->where('mo.member_id = :memberId')
|
||||
->andWhere('mo.organization_id = :organizationId')
|
||||
->setParameter('memberId', $memberId, ParameterType::INTEGER)
|
||||
->setParameter('organizationId', $organizationId, ParameterType::INTEGER)
|
||||
->setMaxResults(1)
|
||||
->executeQuery()
|
||||
->fetchOne();
|
||||
|
||||
return false !== $exists;
|
||||
}
|
||||
|
||||
/** @return array<string, mixed>|null */
|
||||
public function findById(int $organizationId): ?array
|
||||
{
|
||||
$row = $this->connection->createQueryBuilder()
|
||||
->select('*')
|
||||
->from('tl_organization')
|
||||
->where('id = :id')
|
||||
->setParameter('id', $organizationId, ParameterType::INTEGER)
|
||||
->setMaxResults(1)
|
||||
->executeQuery()
|
||||
->fetchAssociative();
|
||||
|
||||
return false === $row ? null : $row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
public function update(int $organizationId, array $data): void
|
||||
{
|
||||
$this->connection->update(
|
||||
'tl_organization',
|
||||
[
|
||||
'title' => $data['title'] ?? '',
|
||||
'street' => $data['street'] ?? '',
|
||||
'postal' => $data['postal'] ?? '',
|
||||
'city' => $data['city'] ?? '',
|
||||
'state' => $data['state'] ?? '',
|
||||
'country' => $data['country'] ?? '',
|
||||
'phone' => $data['phone'] ?? '',
|
||||
'email' => $data['email'] ?? '',
|
||||
'website' => $data['website'] ?? '',
|
||||
'description' => $data['description'] ?? null,
|
||||
'type' => serialize($data['type'] ?? []),
|
||||
'tstamp' => time(),
|
||||
],
|
||||
['id' => $organizationId],
|
||||
[
|
||||
'id' => ParameterType::INTEGER,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
public function updateLogo(int $organizationId, ?string $logoUuid): void
|
||||
{
|
||||
$types = [
|
||||
'id' => ParameterType::INTEGER,
|
||||
];
|
||||
|
||||
if (null !== $logoUuid) {
|
||||
$types['logo'] = ParameterType::BINARY;
|
||||
}
|
||||
|
||||
$this->connection->update(
|
||||
'tl_organization',
|
||||
[
|
||||
'logo' => $logoUuid,
|
||||
'tstamp' => time(),
|
||||
],
|
||||
['id' => $organizationId],
|
||||
$types,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user