Files
afup/sources/AppBundle/Event/Model/Repository/EventRepository.php
Jean-Baptiste Nahan 1eaa19cec8 migration de l'action de suppression d'un evenement (#1002)
* migration de l'action de suppression d'un evenement + securite augmentée

* suppression du code legacy pour la suppression d'un event
2020-07-11 23:41:45 +02:00

333 lines
12 KiB
PHP

<?php
namespace AppBundle\Event\Model\Repository;
use AppBundle\Event\Model\Event;
use AppBundle\Event\Model\GithubUser;
use AppBundle\Event\Model\Ticket;
use CCMBenchmark\Ting\Repository\HydratorArray;
use CCMBenchmark\Ting\Repository\HydratorSingleObject;
use CCMBenchmark\Ting\Repository\Metadata;
use CCMBenchmark\Ting\Repository\MetadataInitializer;
use CCMBenchmark\Ting\Repository\Repository;
use CCMBenchmark\Ting\Serializer\SerializerFactoryInterface;
class EventRepository extends Repository implements MetadataInitializer
{
/**
* @deprecated il y aura surement des soucis liés à l'AFUP Day en utilisant cette méthode
*
* @return Event|null
*/
public function getNextEvent()
{
$events = $this->getNextEvents();
if ($events->count() === 0) {
return null;
}
return $events->first();
}
public function getNextEvents()
{
$query = $this
->getQuery('SELECT id, path, titre, date_debut, date_fin, date_fin_appel_conferencier FROM afup_forum WHERE date_debut > NOW() ORDER BY date_debut')
;
$events = $query->query($this->getCollection(new HydratorSingleObject()));
return $events;
}
public function getNextEventForGithubUser(GithubUser $githubUser)
{
$events = $this
->getPreparedQuery('SELECT id, path, titre, date_debut, date_fin, date_fin_appel_conferencier
FROM afup_forum
WHERE date_debut > NOW()
AND afup_forum.id IN (
SELECT afup_sessions.id_forum
FROM afup_conferenciers_sessions
JOIN afup_sessions ON (afup_conferenciers_sessions.session_id = afup_sessions.session_id)
JOIN afup_conferenciers ON (afup_conferenciers_sessions.conferencier_id = afup_conferenciers.conferencier_id)
WHERE afup_sessions.plannifie = 1
AND afup_conferenciers.user_github = :user_github_id
)
ORDER BY date_debut LIMIT 1')
->setParams(['user_github_id' => $githubUser->getId()])
->query($this->getCollection(new HydratorSingleObject()))
;
if ($events->count() === 0) {
return null;
}
return $events->first();
}
public function getList($id = null)
{
$sql = <<<ENDSQL
SELECT f.id, f.titre, f.path, f.nb_places, f.date_debut, f.date_fin, f.date_fin_appel_conferencier, f.date_fin_vente, IF(count(s.session_id) + count(i.id)>0, 0, 1) as est_supprimable
FROM afup_forum f
LEFT JOIN afup_sessions s ON (f.id = s.id_forum)
LEFT JOIN afup_inscription_forum i ON (f.id = i.id_forum)
%s
GROUP BY f.id, f.titre, f.path, f.nb_places, f.date_debut, f.date_fin, f.date_fin_appel_conferencier, f.date_fin_vente
ORDER BY date_debut desc;
ENDSQL;
$sql = sprintf($sql, $id === null ? '':'WHERE f.id = :id');
$query = $this->getQuery($sql);
if ($id !== null) {
$query->setParams(['id'=>$id]);
}
return $query->query($this->getCollection(new HydratorArray()));
}
public function getAllPastEventWithSpeakerEmail($email)
{
$sql = <<<SQL
SELECT afup_forum.*
FROM afup_forum
JOIN afup_conferenciers ON (afup_forum.id = afup_conferenciers.id_forum)
JOIN afup_conferenciers_sessions ON (afup_conferenciers.conferencier_id = afup_conferenciers_sessions.conferencier_id)
JOIN afup_sessions ON (afup_conferenciers_sessions.session_id = afup_sessions.session_id)
WHERE (afup_sessions.date_publication IS NULL OR afup_sessions.date_publication < NOW())
AND afup_conferenciers.email = :email
AND afup_sessions.plannifie = 1
AND afup_forum.date_fin < NOW()
GROUP BY afup_forum.id
ORDER BY afup_forum.date_debut DESC
SQL;
$query = $this->getQuery($sql);
$query->setParams(['email' => $email]);
return $query->query($this->getCollection(new HydratorSingleObject()));
}
public function getAllPastEventWithTegistrationEmail($email)
{
$sql = <<<SQL
SELECT afup_forum.*
FROM afup_forum
JOIN afup_inscription_forum ON (afup_forum.id = afup_inscription_forum.id_forum)
WHERE afup_inscription_forum.email = :email
AND (afup_inscription_forum.etat = :status_paid OR afup_inscription_forum.etat = :status_guest)
AND afup_forum.date_fin < NOW()
GROUP BY afup_forum.id
ORDER BY afup_forum.date_debut DESC
SQL;
$query = $this->getQuery($sql);
$query->setParams([
'email' => $email,
'status_paid' => Ticket::STATUS_PAID,
'status_guest' => Ticket::STATUS_GUEST,
]);
return $query->query($this->getCollection(new HydratorSingleObject()));
}
/**
* @return Event|null
*/
public function getCurrentEvent()
{
$query = $this
->getQuery('SELECT id, path FROM afup_forum WHERE (date_debut > NOW() OR (NOW() BETWEEN date_debut AND DATE_ADD(date_fin, INTERVAL 1 DAY))) ORDER BY date_debut LIMIT 1')
;
$events = $query->query($this->getCollection(new HydratorSingleObject()));
if ($events->count() === 0) {
return null;
}
return $events->first();
}
/**
* @param int $eventCount
*
* @return \CCMBenchmark\Ting\Repository\CollectionInterface
*/
public function getPreviousEvents($eventCount)
{
$query = $this->getQuery('SELECT * FROM afup_forum WHERE date_debut < NOW() ORDER BY date_debut DESC LIMIT :limit');
$query->setParams(['limit' => $eventCount]);
return $query->query($this->getCollection(new HydratorSingleObject()));
}
/**
* @param $path
*
* @return Event|null
*/
public function getByPath($path)
{
return $this->getBy(['path' => $path])->first();
}
public static function initMetadata(SerializerFactoryInterface $serializerFactory, array $options = [])
{
$metadata = new Metadata($serializerFactory);
$metadata->setEntity(Event::class);
$metadata->setConnectionName('main');
$metadata->setDatabase($options['database']);
$metadata->setTable('afup_forum');
$metadata
->addField([
'columnName' => 'id',
'fieldName' => 'id',
'primary' => true,
'autoincrement' => true,
'type' => 'int'
])
->addField([
'columnName' => 'titre',
'fieldName' => 'title',
'type' => 'string'
])
->addField([
'columnName' => 'nb_places',
'fieldName' => 'seats',
'type' => 'int'
])
->addField([
'columnName' => 'date_debut',
'fieldName' => 'dateStart',
'type' => 'datetime',
'serializer_options' => [
'unserialize' => ['unSerializeUseFormat' => false]
]
])
->addField([
'columnName' => 'date_fin',
'fieldName' => 'dateEnd',
'type' => 'datetime',
'serializer_options' => [
'unserialize' => ['unSerializeUseFormat' => false]
]
])
->addField([
'columnName' => 'date_fin_appel_projet',
'fieldName' => 'dateEndCallForProjects',
'type' => 'datetime',
'serializer_options' => [
'unserialize' => ['unSerializeUseFormat' => true, 'format' => 'U']
]
])
->addField([
'columnName' => 'date_fin_appel_conferencier',
'fieldName' => 'dateEndCallForPapers',
'type' => 'datetime',
'serializer_options' => [
'unserialize' => ['unSerializeUseFormat' => true, 'format' => 'U']
]
])
->addField([
'columnName' => 'date_fin_vote',
'fieldName' => 'dateEndVote',
'type' => 'datetime'
])
->addField([
'columnName' => 'date_fin_prevente',
'fieldName' => 'dateEndPreSales',
'type' => 'datetime',
'serializer_options' => [
'unserialize' => ['unSerializeUseFormat' => true, 'format' => 'U']
]
])
->addField([
'columnName' => 'date_fin_vente',
'fieldName' => 'dateEndSales',
'type' => 'datetime',
'serializer_options' => [
'unserialize' => ['unSerializeUseFormat' => true, 'format' => 'U']
]
])
->addField([
'columnName' => 'date_fin_saisie_repas_speakers',
'fieldName' => 'dateEndSpeakersDinerInfosCollection',
'type' => 'datetime',
'serializer_options' => [
'unserialize' => ['unSerializeUseFormat' => true, 'format' => 'U']
]
])
->addField([
'columnName' => 'date_annonce_planning',
'fieldName' => 'datePlanningAnnouncement',
'type' => 'datetime',
'serializer_options' => [
'unserialize' => ['unSerializeUseFormat' => true, 'format' => 'U']
]
])
->addField([
'columnName' => 'date_fin_saisie_nuites_hotel',
'fieldName' => 'dateEndHotelInfosCollection',
'type' => 'datetime',
'serializer_options' => [
'unserialize' => ['unSerializeUseFormat' => true, 'format' => 'U']
]
])
->addField([
'columnName' => 'text',
'fieldName' => 'cfp',
'type' => 'json',
'serializer_options' => [
'unserialize' => ['assoc' => true]
]
])
->addField([
'columnName' => 'path',
'fieldName' => 'path',
'type' => 'string'
])
->addField([
'columnName' => 'trello_list_id',
'fieldName' => 'trelloListId',
'type' => 'string'
])
->addField([
'columnName' => 'logo_url',
'fieldName' => 'logoUrl',
'type' => 'string'
])
->addField([
'columnName' => 'place_name',
'fieldName' => 'placeName',
'type' => 'string'
])
->addField([
'columnName' => 'place_address',
'fieldName' => 'placeAddress',
'type' => 'string'
])
->addField([
'columnName' => 'vote_enabled',
'fieldName' => 'voteEnabled',
'type' => 'boolean'
])
->addField([
'columnName' => 'speakers_diner_enabled',
'fieldName' => 'speakersDinerEnabled',
'type' => 'boolean'
])
->addField([
'columnName' => 'accomodation_enabled',
'fieldName' => 'accomodationEnabled',
'type' => 'boolean'
])
->addField([
'columnName' => 'waiting_list_url',
'fieldName' => 'waitingListUrl',
'type' => 'string',
])
;
return $metadata;
}
}