improve customer api & gui
This commit is contained in:
@@ -3,10 +3,12 @@
|
||||
namespace common\modules\event\manager;
|
||||
|
||||
use common\models\Event;
|
||||
use common\models\EventRegistration;
|
||||
use common\modules\event\models\timetable\TimeTableMonth;
|
||||
use common\modules\event\models\timetable\TimeTableMonthDay;
|
||||
use common\modules\event\models\timetable\TimeTableMonthWeek;
|
||||
use customerapi\models\available\EventInterval;
|
||||
use customerapi\models\details\EventRegistrationView;
|
||||
use DateTime;
|
||||
use Exception;
|
||||
use yii\db\Query;
|
||||
@@ -23,13 +25,14 @@ class EventManager
|
||||
* @throws \yii\base\Exception on any error
|
||||
* @throws StaleObjectException
|
||||
*/
|
||||
public function deleteEvent($id){
|
||||
public function deleteEvent($id)
|
||||
{
|
||||
$event = Event::findOne($id);
|
||||
if ( !isset($event)){
|
||||
if (!isset($event)) {
|
||||
throw new \yii\base\Exception("Event $id not found");
|
||||
}
|
||||
$registrations = $event->eventRegistrations;
|
||||
if ( !isset($registrations) || count($registrations) === 0 ){
|
||||
if (!isset($registrations) || count($registrations) === 0) {
|
||||
$event->delete();
|
||||
} else {
|
||||
$event->deleted_at = time();
|
||||
@@ -43,7 +46,7 @@ class EventManager
|
||||
* @return TimeTableMonth
|
||||
* @throws Exception
|
||||
*/
|
||||
public function loadTimeTable($interval , $activeOrDisplayInterval = "active" )
|
||||
public function loadTimeTable($interval, $activeOrDisplayInterval = "active")
|
||||
{
|
||||
|
||||
$timeTable = new TimeTableMonth();
|
||||
@@ -73,11 +76,11 @@ class EventManager
|
||||
$timeTable->weeks[$weekNumber]->$weekDayName = $timeTableMonthDay;
|
||||
}
|
||||
|
||||
if ( $activeOrDisplayInterval == "active"){
|
||||
if ($activeOrDisplayInterval == "active") {
|
||||
$dateTimeFrom = $interval->firstActiveDate;
|
||||
$to = clone $interval->lastActiveDate;
|
||||
$dateTimeTo = $to->modify('+1 day');
|
||||
}else{
|
||||
} else {
|
||||
// active
|
||||
$dateTimeFrom = $interval->firstDisplayDate;
|
||||
$to = clone $interval->lastDisplayDate;
|
||||
@@ -85,7 +88,7 @@ class EventManager
|
||||
}
|
||||
// get events between active dates
|
||||
|
||||
$events =$this->getEvents($dateTimeFrom,$dateTimeTo);
|
||||
$events = $this->getEvents($dateTimeFrom, $dateTimeTo);
|
||||
|
||||
// set events per day
|
||||
/** @var Event $event */
|
||||
@@ -108,8 +111,8 @@ class EventManager
|
||||
|
||||
/**
|
||||
* Get all active events between the to dates
|
||||
* @param DateTime $fromInc from date inclusive (>=)
|
||||
* @param DateTime $toExcl to date exclusive (<)
|
||||
* @param DateTime $fromInc from date inclusive (>=)
|
||||
* @param DateTime $toExcl to date exclusive (<)
|
||||
* @return Event[]
|
||||
*/
|
||||
public function getEvents($fromInc, $toExcl)
|
||||
@@ -150,18 +153,61 @@ class EventManager
|
||||
public function getEventsForDay($date)
|
||||
{
|
||||
$start = clone $date;
|
||||
$start->setTime(0,0);
|
||||
$start->setTime(0, 0);
|
||||
|
||||
$to = clone $start;
|
||||
$to->modify('+1 day');
|
||||
|
||||
return $this->getEvents($start,$to);
|
||||
return $this->getEvents($start, $to);
|
||||
}
|
||||
|
||||
public function getEvent($id){
|
||||
public function getEvent($id)
|
||||
{
|
||||
return Event::findOne($id);
|
||||
}
|
||||
|
||||
public function findActiveRegistrations($idEvent, $idCustomer = null)
|
||||
{
|
||||
|
||||
$registrations = EventRegistrationView::find()->andWhere(['id_event' => $idEvent, 'id_customer' => \Yii::$app->user->id])->all();
|
||||
$allActiveRegistrations = EventRegistration::filterActive($registrations);
|
||||
if (isset($idCustomer)) {
|
||||
$allActiveRegistrations = EventRegistration::filterForCustomer($allActiveRegistrations, \Yii::$app->user->id);
|
||||
}
|
||||
return $allActiveRegistrations;
|
||||
}
|
||||
|
||||
|
||||
public function findActiveEvent($idEvent, $interval, $withRelatedObjects = false)
|
||||
{
|
||||
$paramEventStartMax = (clone $interval->lastActiveDate);
|
||||
$paramEventStartMax = $paramEventStartMax->modify('+1 day');
|
||||
$paramEventStartMax = $paramEventStartMax->getTimestamp();
|
||||
$query = Event::find()
|
||||
->andWhere(['event.id' => $idEvent])
|
||||
->andWhere(['>=', 'event.start', $interval->firstActiveDate->getTimestamp()])
|
||||
->andWhere(['<', 'event.start', $paramEventStartMax])
|
||||
->andWhere(['event.active' => '1']);
|
||||
|
||||
if ($withRelatedObjects) {
|
||||
$query = $query->innerJoinWith('trainer')
|
||||
->innerJoinWith('eventType')
|
||||
->innerJoinWith('room');
|
||||
}
|
||||
|
||||
|
||||
return $query->one();
|
||||
}
|
||||
|
||||
public function findActiveEvents($interval)
|
||||
{
|
||||
$paramEventStartMax = (clone $interval->lastActiveDate);
|
||||
$paramEventStartMax = $paramEventStartMax->modify('+1 day');
|
||||
$paramEventStartMax = $paramEventStartMax->getTimestamp();
|
||||
return Event::find()
|
||||
->andWhere(['>=', 'event.start', $interval->firstActiveDate->getTimestamp()])
|
||||
->andWhere(['<', 'event.start', $paramEventStartMax])
|
||||
->andWhere(['event.active' => '1'])->all();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user