customer available events improvements

This commit is contained in:
Roland Schneider
2021-09-10 23:30:13 +02:00
parent 2bf9985928
commit 18cd8312b5
15 changed files with 125 additions and 179 deletions

View File

@@ -9,14 +9,13 @@
namespace customerapi\controllers;
use common\models\Event;
use common\models\EventRegistration;
use customerapi\models\available\EventInterval;
use customerapi\models\available\EventAvailable;
use customerapi\models\DayToDisplay;
use customerapi\models\details\EventDetailsView;
use DateTime;
use Exception;
use yii\db\ActiveRecord;
use yii\db\Query;
use yii\web\Response;
@@ -64,19 +63,21 @@ class EventController extends CustomerApiController
->innerJoinWith('trainer')
->innerJoinWith('eventType')
->innerJoinWith('room')
->joinWith('activeEventRegistrations')
->joinWith('activeEventRegistrationsForCustomer')
->andWhere(['>=', 'event.start', $interval->firstActiveDate->getTimestamp()])
->andWhere(['<', 'event.start', (clone $interval->lastActiveDate)->modify('+1 day')->getTimestamp()])
->andWhere(['event.active' => '1'])
->all();
// set events per day
/** @var Event $event */
/** @var EventAvailable $event */
foreach ($events as $event) {
$eventDay = new DateTime();
$eventDay->setTimestamp($event->start);
$eventDay->setTime(0, 0);
$event->reservationCount = $event->getEventRegistrationCount();
/** @var DayToDisplay $date */
foreach ($dates as $date) {
if ($date->date === $eventDay->getTimestamp()) {
@@ -96,7 +97,7 @@ class EventController extends CustomerApiController
/**
* @param Query $query
* @param $interval
* @return the query with the added conditions
* @return Query the query with the added conditions
*/
private function buildEventQuery($query, $interval)
{
@@ -104,7 +105,7 @@ class EventController extends CustomerApiController
->innerJoinWith('trainer')
->innerJoinWith('eventType')
->innerJoinWith('room')
->joinWith('activeEventRegistrations')
->joinWith('activeEventRegistrations as registrations')
->andWhere(['>=', 'event.start', $interval->firstActiveDate->getTimestamp()])
->andWhere(['<', 'event.start', (clone $interval->lastActiveDate)->modify('+1 day')->getTimestamp()])
->andWhere(['event.active' => '1']);