56 lines
1.6 KiB
PHP
56 lines
1.6 KiB
PHP
<?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($clazz= EventRegistration::class )
|
|
{
|
|
$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()]
|
|
]);
|
|
}
|
|
|
|
|
|
}
|