customer available events improvements
This commit is contained in:
55
customerapi/manager/EventRegistrationManager.php
Normal file
55
customerapi/manager/EventRegistrationManager.php
Normal 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()]
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user