add registrations to customer gui
This commit is contained in:
@@ -13,8 +13,11 @@ use common\models\Event;
|
||||
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\Query;
|
||||
use yii\web\Response;
|
||||
|
||||
/** @noinspection PhpUnused */
|
||||
|
||||
@@ -82,7 +85,6 @@ class EventController extends CustomerApiController
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return
|
||||
$this->asJson([
|
||||
'interval' => $interval,
|
||||
@@ -90,4 +92,41 @@ class EventController extends CustomerApiController
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Query $query
|
||||
* @param $interval
|
||||
* @return the query with the added conditions
|
||||
*/
|
||||
private function buildEventQuery($query, $interval)
|
||||
{
|
||||
return $query
|
||||
->innerJoinWith('trainer')
|
||||
->innerJoinWith('eventType')
|
||||
->innerJoinWith('room')
|
||||
->joinWith('activeEventRegistrations')
|
||||
->andWhere(['>=', 'event.start', $interval->firstActiveDate->getTimestamp()])
|
||||
->andWhere(['<', 'event.start', (clone $interval->lastActiveDate)->modify('+1 day')->getTimestamp()])
|
||||
->andWhere(['event.active' => '1']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer $id_event the id of the event
|
||||
* @return Response the response
|
||||
* @throws \yii\base\Exception on any error
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionEvent($id_event)
|
||||
{
|
||||
$interval = EventInterval::createInterval();
|
||||
try {
|
||||
$query = EventDetailsView::find();
|
||||
$query = $this->buildEventQuery($query, $interval);
|
||||
$query = $query->andWhere(['event.id' => $id_event]);
|
||||
$event = $query->one();
|
||||
return $this->asJson($event);
|
||||
} catch (Exception $e) {
|
||||
throw new \yii\base\Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,9 +13,12 @@ use common\manager\EventRegistrationManager;
|
||||
use common\models\CardEventRegistrationForm;
|
||||
use common\models\Customer;
|
||||
use customerapi\models\available\EventInterval;
|
||||
use customerapi\models\available\EventRegistrationAvailable;
|
||||
use customerapi\models\registrations\EventRegistrationAvailable;
|
||||
use Exception;
|
||||
use Throwable;
|
||||
use Yii;
|
||||
use yii\db\ActiveQuery;
|
||||
use yii\web\Response;
|
||||
|
||||
/** @noinspection PhpUnused */
|
||||
|
||||
@@ -23,37 +26,62 @@ class EventRegistrationController extends CustomerApiController
|
||||
{
|
||||
|
||||
/** @noinspection PhpUnused */
|
||||
/**
|
||||
* @return Response
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
$interval = EventInterval::createInterval();
|
||||
|
||||
$registrations = EventRegistrationAvailable::find()
|
||||
->innerJoinWith('event')
|
||||
->andWhere(['and',
|
||||
['>=', 'event.start', $interval->firstActiveDate->getTimestamp()],
|
||||
['<', 'event.start', $interval->lastActiveDate->getTimestamp()],
|
||||
['id_customer' => Yii::$app->user->getId()]
|
||||
])->all();
|
||||
$registrations =$this->prepareQueryFindRegistrationsForCustomer()->all();
|
||||
return $this->asJson( $registrations );
|
||||
}
|
||||
|
||||
/** @noinspection PhpUnused */
|
||||
/***
|
||||
* @param $id_registration
|
||||
* @return Response
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionRegistration($id_registration)
|
||||
{
|
||||
$registrations = $this->prepareQueryFindRegistrationsForCustomer()
|
||||
->andWhere(['id_event_registration' => $id_registration])
|
||||
->one();
|
||||
return $this->asJson(
|
||||
|
||||
$registrations
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 $idEvent
|
||||
* @param $id_event
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function actionRegister($idEvent) {
|
||||
public function actionRegister($id_event) {
|
||||
/** @var Customer $customer */
|
||||
$customer = Yii::$app->user->getIdentity();
|
||||
$card =$customer->card;
|
||||
|
||||
$form = new CardEventRegistrationForm();
|
||||
$form->event_id = $idEvent;
|
||||
$form->event_id = $id_event;
|
||||
$form->card_number = $card->number;
|
||||
|
||||
$manager = new EventRegistrationManager();
|
||||
|
||||
Reference in New Issue
Block a user