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']);

View File

@@ -9,15 +9,11 @@
namespace customerapi\controllers;
use common\manager\EventRegistrationManager;
use customerapi\manager\EventRegistrationManager;
use common\models\CardEventRegistrationForm;
use common\models\Customer;
use customerapi\models\available\EventInterval;
use customerapi\models\registrations\EventRegistrationAvailable;
use Exception;
use Throwable;
use Yii;
use yii\db\ActiveQuery;
use yii\web\Response;
/** @noinspection PhpUnused */
@@ -32,8 +28,8 @@ class EventRegistrationController extends CustomerApiController
*/
public function actionIndex()
{
$registrations =$this->prepareQueryFindRegistrationsForCustomer()->all();
return $this->asJson( $registrations );
$registrationManager = new EventRegistrationManager();
return $this->asJson( $registrationManager->findCustomerRegistrationsWithEvent() );
}
/** @noinspection PhpUnused */
@@ -44,35 +40,15 @@ class EventRegistrationController extends CustomerApiController
*/
public function actionRegistration($id_registration)
{
$registrations = $this->prepareQueryFindRegistrationsForCustomer()
->andWhere(['event_registration.id' => $id_registration])
->one();
$registrationManager = new EventRegistrationManager();
return $this->asJson(
$registrations
);
$registrationManager->findRegistration($id_registration)
);
}
/**
* Prepare a query to get registrations for customer
*
* @return ActiveQuery
* @throws Exception
*/
private function prepareQueryFindRegistrationsForCustomer(){
$interval = EventInterval::createInterval();
return EventRegistrationAvailable::find()
->innerJoinWith('event')
->andWhere(['and',
['>=', 'event.start', $interval->firstActiveDate->getTimestamp()],
['id_customer' => Yii::$app->user->getId()]
]);
}
/**
* @noinspection PhpUnused
* @param $id_event
* @throws Throwable
*/
public function actionRegister($id_event) {
/** @var Customer $customer */

View File

@@ -2,13 +2,9 @@
namespace customerapi\controllers;
use Yii;
use common\models\LoginForm;
use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use common\models\User;
use common\components\Helper;
use common\models\Log;
/**
* Site controller
@@ -68,43 +64,6 @@ class SiteController extends Controller
return $this->render('index');
}
/**
* Logs in a user.
*
* @return mixed
*/
public function actionLogin()
{
if (!\Yii::$app->user->isGuest) {
return $this->goHome();
}
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
$geoip = Helper::getGeoIp();
$message = "";
$user = User::findOne(\Yii::$app->user->id);
if ( isset($geoip)){
$ip = isset( $geoip->ip ) ? $geoip->ip : "";
$city = isset( $geoip->city ) ? $geoip->city : "";
$message = "Bejelentkezés: " .$user->username. " Ip cím:". $ip . " Város: " . $city;
}
Log::log([
'type' =>Log::$TYPE_LOGIN,
'message' => $message
]);
return $this->redirect(['account/select']);
} else {
return $this->render('login', ['model' => $model,]);
}
}
/**
* Logs out the current user.
*

View File

@@ -20,10 +20,16 @@ class UserController extends RestController
{
/**
* hash for password test is:
* $2y$13$D2BauYE2nhCdVDNatT9BMeWGxOvi5t5V6W2OUjr6sj2FRpb317Cpq
*
*/
/** @noinspection PhpUnused */
public function actionLogin( )
{
// $customer = new Customer();
// $customer->setPassword("test");
$form = new LoginForm();
$form->load(\Yii::$app->request->post( ), '');

View File

@@ -0,0 +1,55 @@
<?php
namespace customerapi\manager;
use common\models\EventRegistration;
use customerapi\models\available\EventInterval;
use customerapi\models\registrations\EventRegistrationAvailable;
use yii\db\ActiveQuery;
class EventRegistrationManager
{
/** Get Customer registrations
* @throws \Exception
*/
public function findCustomerRegistrationsWithEvent()
{
return $this->prepareQueryFindRegistrationsForCustomer()->all();
}
public function findCustomerRegistrations()
{
$interval = EventInterval::createInterval();
return EventRegistration::find()
->innerJoinWith('event')
->andWhere(['and',
['>=', 'event.start', $interval->firstActiveDate->getTimestamp()],
['id_customer' => \Yii::$app->user->getId()]
])->all();
}
public function findRegistration($id_registration)
{
return $this->prepareQueryFindRegistrationsForCustomer()
->andWhere(['event_registration.id' => $id_registration])
->one();
}
/**
* Prepare a query to get registrations for customer
* @return ActiveQuery query
* @throws \Exception
*/
private function prepareQueryFindRegistrationsForCustomer(){
$interval = EventInterval::createInterval();
return EventRegistrationAvailable::find()
->innerJoinWith('event')
->andWhere(['and',
['>=', 'event.start', $interval->firstActiveDate->getTimestamp()],
['id_customer' => \Yii::$app->user->getId()]
]);
}
}

View File

@@ -29,20 +29,21 @@ class EventAvailable extends Event
}
function fields()
{
$fields = [
"id" => "id",
"start" => "start",
"end" => "end",
"seat_count" => "seat_count",
"active" => "active",
// "reservationCount" => "reservationCount"
"reservationCount" => "reservationCount",
];
$fields['trainer'] = 'trainer';
$fields['eventType'] = 'eventType';
$fields['room'] = 'room';
$fields['registrations'] = 'activeEventRegistrationsForCustomer';
return $fields;
}