improve customer api & gui
This commit is contained in:
@@ -2,9 +2,11 @@
|
||||
namespace customerapi\manager;
|
||||
|
||||
use common\models\EventRegistration;
|
||||
use common\modules\event\manager\EventManager;
|
||||
use customerapi\models\available\EventInterval;
|
||||
use customerapi\models\registrations\EventRegistrationAvailable;
|
||||
use yii\db\ActiveQuery;
|
||||
use customerapi\models\dto\EventDTO;
|
||||
use customerapi\models\dto\EventRegistrationDTO;
|
||||
use yii\web\NotFoundHttpException;
|
||||
|
||||
class EventRegistrationManager
|
||||
{
|
||||
@@ -12,44 +14,55 @@ class EventRegistrationManager
|
||||
/** Get Customer registrations
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function findCustomerRegistrationsWithEvent()
|
||||
{
|
||||
return $this->prepareQueryFindRegistrationsForCustomer()->all();
|
||||
}
|
||||
|
||||
public function findCustomerRegistrations($clazz= EventRegistration::class )
|
||||
public function findCustomerRegistrationsWithEvent($idCustomer)
|
||||
{
|
||||
$interval = EventInterval::createInterval();
|
||||
return EventRegistration::find()
|
||||
->innerJoinWith('event')
|
||||
->andWhere(['and',
|
||||
['>=', 'event.start', $interval->firstActiveDate->getTimestamp()],
|
||||
['id_customer' => \Yii::$app->user->getId()]
|
||||
])->all();
|
||||
}
|
||||
$now = new \DateTime();
|
||||
$eventRegistrations = EventRegistration::find()
|
||||
->andWhere(['id_customer' => $idCustomer])
|
||||
// ->andWhere(['>=', 'event.start', $now->getTimestamp()])
|
||||
->all();
|
||||
|
||||
|
||||
public function findRegistration($id_registration)
|
||||
{
|
||||
return $this->prepareQueryFindRegistrationsForCustomer()
|
||||
->andWhere(['event_registration.id' => $id_registration])
|
||||
->one();
|
||||
$result = [];
|
||||
$eventManager = new EventManager();
|
||||
foreach ($eventRegistrations as $registration ){
|
||||
$dto = EventRegistrationDTO::fromEventRegistration($registration);
|
||||
|
||||
$event = $eventManager->findActiveEvent($registration->id_event, $interval,true);
|
||||
if ( isset($event)){
|
||||
$dto->event = EventDTO::fromEventWithRelatedObjects($event);
|
||||
$result[] = $dto;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prepare a query to get registrations for customer
|
||||
* @return ActiveQuery query
|
||||
* @throws \Exception
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
private function prepareQueryFindRegistrationsForCustomer(){
|
||||
public function findRegistration($id_registration, $id_customer)
|
||||
{
|
||||
$interval = EventInterval::createInterval();
|
||||
return EventRegistrationAvailable::find()
|
||||
->innerJoinWith('event')
|
||||
->andWhere(['and',
|
||||
['>=', 'event.start', $interval->firstActiveDate->getTimestamp()],
|
||||
['id_customer' => \Yii::$app->user->getId()]
|
||||
]);
|
||||
|
||||
$registration = EventRegistration::findOne(['id' => $id_registration, 'id_customer' => $id_customer]);
|
||||
|
||||
if ( !isset($registration)){
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
|
||||
$eventManager = new EventManager();
|
||||
$event = $eventManager->findActiveEvent($registration->id_event,$interval,true);
|
||||
|
||||
if ( !isset($event)){
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
|
||||
return EventRegistrationDTO::fromEventRegistrationWithEvent($registration,$event);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user