add registrations to customer gui

This commit is contained in:
Roland Schneider 2020-01-01 21:05:37 +01:00 committed by Roland Schneider
parent 2c5db234ce
commit 753cd46b2c
34 changed files with 473 additions and 98 deletions

View File

@ -8,6 +8,8 @@ use common\models\Customer;
use common\models\Event; use common\models\Event;
use common\models\EventRegistration; use common\models\EventRegistration;
use common\models\Ticket; use common\models\Ticket;
use customerapi\models\available\EventInterval;
use customerapi\models\registrations\EventRegistrationAvailable;
use Exception; use Exception;
use Throwable; use Throwable;
use Yii; use Yii;
@ -252,5 +254,4 @@ class EventRegistrationManager extends BaseObject
} }
} }

View File

@ -68,11 +68,19 @@ class EventRegistration extends \yii\db\ActiveRecord
public function getEvent(){ public function getEvent(){
return $this->hasOne(Event::class,['id' => 'id_event']); return $this->hasOne($this->getEventClass(),['id' => 'id_event']);
} }
public function getCustomer(){ public function getCustomer(){
return $this->hasOne(Customer::class,['id' => 'id_customer']); return $this->hasOne($this->getCustomerClass(),['id' => 'id_customer']);
} }
public function getEventClass(){
return Event::class;
}
public function getCustomerClass(){
return Customer::class;
}
} }

View File

@ -151,6 +151,10 @@ class EventManager
return $this->getEvents($start,$to); return $this->getEvents($start,$to);
} }
public function getEvent($id){
return Event::findOne($id);
}
} }

View File

@ -85,13 +85,12 @@ export class FakeBackendInterceptor implements HttpInterceptor {
eventType: eventTypes[id % eventTypes.length], eventType: eventTypes[id % eventTypes.length],
reservedAt: reservedAt, reservedAt: reservedAt,
reservationCount: id % 11, reservationCount: id % 11,
seatCount: 10 seat_count: 10
} }
) )
} }
} }
} }
console.info('events.size', events.length);
// wrapping the API's in delayed observable to simulate the Server API Calls // wrapping the API's in delayed observable to simulate the Server API Calls

View File

@ -6,6 +6,8 @@ import {ProfileComponent} from "./pages/profile/profile.component";
import {AuthGuard} from "./_guards"; import {AuthGuard} from "./_guards";
import {EventsComponent} from "./pages/events/events.component"; import {EventsComponent} from "./pages/events/events.component";
import {EventDetailsComponent} from "./pages/event-details/event-details.component"; import {EventDetailsComponent} from "./pages/event-details/event-details.component";
import {RegistrationsComponent} from "./pages/registrations/registrations.component";
import {RegistrationComponent} from "./pages/registration/registration.component";
const routes: Routes = [ const routes: Routes = [
{ path: 'home', component: HomeComponent }, { path: 'home', component: HomeComponent },
@ -15,6 +17,8 @@ const routes: Routes = [
{ path: 'profile', component: ProfileComponent, canActivate: [AuthGuard] }, { path: 'profile', component: ProfileComponent, canActivate: [AuthGuard] },
{ path: 'events', component: EventsComponent, canActivate: [AuthGuard] }, { path: 'events', component: EventsComponent, canActivate: [AuthGuard] },
{ path: 'event-details/:idEvent', component: EventDetailsComponent, canActivate: [AuthGuard] , pathMatch: 'full' }, { path: 'event-details/:idEvent', component: EventDetailsComponent, canActivate: [AuthGuard] , pathMatch: 'full' },
{ path: 'registrations', component: RegistrationsComponent, canActivate: [AuthGuard] , pathMatch: 'full' },
{ path: 'registration/:idRegistration', component: RegistrationComponent, canActivate: [AuthGuard] , pathMatch: 'full' },
]; ];
@NgModule({ @NgModule({

View File

@ -28,6 +28,8 @@ import { MonthCalendarComponent } from './components/month-calendar/month-calend
import { MonthCalendarDayComponent } from './components/month-calendar-day/month-calendar-day.component'; import { MonthCalendarDayComponent } from './components/month-calendar-day/month-calendar-day.component';
import { MonthCalendarEventComponent } from './components/month-calendar-event/month-calendar-event.component'; import { MonthCalendarEventComponent } from './components/month-calendar-event/month-calendar-event.component';
import { EventDetailsComponent } from './pages/event-details/event-details.component'; import { EventDetailsComponent } from './pages/event-details/event-details.component';
import { RegistrationsComponent } from './pages/registrations/registrations.component';
import { RegistrationComponent } from './pages/registration/registration.component';
@ -50,6 +52,8 @@ registerLocaleData(localeHu, 'hu');
MonthCalendarDayComponent, MonthCalendarDayComponent,
MonthCalendarEventComponent, MonthCalendarEventComponent,
EventDetailsComponent, EventDetailsComponent,
RegistrationsComponent,
RegistrationComponent,
], ],
imports: [ imports: [
BrowserModule, BrowserModule,

View File

@ -47,7 +47,6 @@ export class FitEventTypesComponent implements OnInit, ControlValueAccessor {
} }
setValue($event: Event) { setValue($event: Event) {
console.info($event);
this._setValue((<any>$event.target).value); this._setValue((<any>$event.target).value);
} }

View File

@ -16,14 +16,19 @@ export class FitNavigationComponent implements OnInit {
label: 'Home', label: 'Home',
roles: ['*'] roles: ['*']
}, },
// {
// route: '/profile',
// label: 'Profil',
// roles: ['@']
// },
// {
// route: '/events',
// label: 'Események',
// roles: ['@']
// },
{ {
route: '/profile', route: '/registrations',
label: 'Profil', label: 'Foglalások',
roles: ['@']
},
{
route: '/events',
label: 'Események',
roles: ['@'] roles: ['@']
}, },
{ {

View File

@ -21,8 +21,6 @@ export class MonthCalendarDayComponent implements OnInit {
ngOnInit() { ngOnInit() {
if ( this.day ){ if ( this.day ){
console.info(this.day);
this.oMoment = dateToMoment(this.day.date); this.oMoment = dateToMoment(this.day.date);
} }
} }

View File

@ -1,36 +1,37 @@
<div class="container" *ngIf="event"> <div class="container" *ngIf="event">
<div class="row"> <h1>Jelentkezés</h1>
<div class="col-lg-3 col-sm-12"><span class="title">Edzés típusa</span></div> <div class="row">
<div class="col-lg-9 col-sm-12"><span>{{event.eventType.name}}</span></div> <div class="col-lg-3 col-sm-12"><span class="title">Edzés típusa</span></div>
<div class="col-lg-9 col-sm-12"><span>{{event.eventType.name}}</span></div>
</div>
<div class="row" *ngIf="event.trainer">
<div class="col-lg-3 col-sm-12"><span class="title">Edző</span></div>
<div class="col-lg-9 col-sm-12"><span>{{event?.trainer?.name}}</span></div>
</div>
<div class="row">
<div class="col-lg-3 col-sm-12"><span class="title">Edzés kezdési időpontja</span></div>
<div class="col-lg-9 col-sm-12"><span>{{event.start * 1000 | date:'yyyy.MM.dd HH:mm'}}</span></div>
</div>
<div class="row">
<div class="col-lg-3 col-sm-12"><span class="title">Edzés vége</span></div>
<div class="col-lg-9 col-sm-12"><span>{{event.end * 1000 | date:'yyyy.MM.dd HH:mm'}}</span></div>
</div>
<div class="row">
<div class="col-lg-3 col-sm-12"><span class="title">Férőhelyek száma</span></div>
<div class="col-lg-9 col-sm-12"><span>{{event.seat_count }}</span></div>
</div>
<div class="row">
<div class="col-lg-3 col-sm-12"><span class="title">Terem</span></div>
<div class="col-lg-9 col-sm-12"><span>{{event?.room?.name }}</span></div>
</div>
<div class="row">
<div class="col-lg-9 col-sm-12 pt-2">
<a *ngIf="mayRegister(event)" class="btn btn-primary " (click)="register(event)">Foglalás</a>
<a *ngIf="mayCancel(event)" class="btn btn-primary" (click)="cancel(event)">Lemondás</a>
<span *ngIf="!mayCancel(event) && noFreeSeat(event)">Már nincs szabad hely</span>
</div> </div>
<div class="row" *ngIf="event.trainer"> <div class="col-lg-3 text-lg-right col-sm-12 pt-2">
<div class="col-lg-3 col-sm-12"><span class="title">Edző</span></div> <a class="btn btn-primary " (click)="goBack(event)">Vissza</a>
<div class="col-lg-9 col-sm-12"><span>{{event.trainer.name}}</span></div>
</div>
<div class="row">
<div class="col-lg-3 col-sm-12"><span class="title">Edzés kezdési időpontja</span></div>
<div class="col-lg-9 col-sm-12"><span>{{event.start | date:'yyyy.MM.dd HH:mm'}}</span></div>
</div>
<div class="row">
<div class="col-lg-3 col-sm-12"><span class="title">Edzés vége</span></div>
<div class="col-lg-9 col-sm-12"><span>{{event.end | date:'yyyy.MM.dd HH:mm'}}</span></div>
</div>
<div class="row">
<div class="col-lg-3 col-sm-12"><span class="title">Férőhelyek száma</span></div>
<div class="col-lg-9 col-sm-12"><span>{{event.seatCount }}</span></div>
</div>
<!-- <div class="row">-->
<!-- <div class="col-lg-3 col-sm-12"><span class="title">Szabad helyek száma</span></div>-->
<!-- <div class="col-lg-9 col-sm-12"><span>{{event.seatCount - event.reservationCount }}</span></div>-->
<!-- </div>-->
<div class="row">
<div class="col-lg-9 col-sm-12 pt-2">
<a *ngIf="mayRegister(event)" class="btn btn-primary " (click)="register(event)" >Foglalás</a>
<a *ngIf="mayCancel(event)" class="btn btn-primary" (click)="cancel(event)" >Lemondás</a>
<span *ngIf="!mayCancel(event) && noFreeSeat(event)">Már nincs szabad hely</span>
</div>
<div class="col-lg-3 text-lg-right col-sm-12 pt-2">
<a class="btn btn-primary " (click)="goBack(event)" >Vissza</a>
</div>
</div> </div>
</div>
</div> </div>

View File

@ -1,6 +1,6 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import {Event, EventService} from "../../services/event.service"; import {Event, EventService} from "../../services/event.service";
import {ActivatedRoute, RouterState} from "@angular/router"; import {ActivatedRoute} from "@angular/router";
import {NavigationService} from "../../services/navigation.service"; import {NavigationService} from "../../services/navigation.service";
@Component({ @Component({
@ -23,11 +23,11 @@ export class EventDetailsComponent implements OnInit {
this.eventService.findEvent(idEvent).subscribe( this.eventService.findEvent(idEvent).subscribe(
value => this.event = value value => this.event = value
); );
} }
mayRegister(event: Event) { mayRegister(event: Event) {
return event.reservedAt == null && event.reservationCount < event.seatCount; // return event.reservedAt == null && event.reservationCount < event.seat_count;
return true
} }
mayCancel(event: Event) { mayCancel(event: Event) {
@ -35,19 +35,24 @@ export class EventDetailsComponent implements OnInit {
} }
noFreeSeat(event: Event) { noFreeSeat(event: Event) {
return event.reservedAt == null && event.reservationCount >= event.seatCount; return event.reservedAt == null && event.reservationCount >= event.seat_count;
} }
goBack(event: Event) { goBack(event: Event) {
this.navigationService.navigateToHome(); this.navigationService.navigateToHome();
} }
register(event: Event) { register(event: Event) {
console.info("register", event);
this.eventService.register(event.id)
.subscribe(
value => {},
value => {},
);
} }
cancel(event: Event) { cancel(event: Event) {
} }
} }

View File

@ -18,11 +18,11 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col-lg-3 col-sm-12"><span class="title">Férőhelyek száma</span></div> <div class="col-lg-3 col-sm-12"><span class="title">Férőhelyek száma</span></div>
<div class="col-lg-9 col-sm-12"><span>{{event.seatCount }}</span></div> <div class="col-lg-9 col-sm-12"><span>{{event.seat_count }}</span></div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-lg-3 col-sm-12"><span class="title">Szabad helyek száma</span></div> <div class="col-lg-3 col-sm-12"><span class="title">Szabad helyek száma</span></div>
<div class="col-lg-9 col-sm-12"><span>{{event.seatCount - event.reservationCount }}</span></div> <div class="col-lg-9 col-sm-12"><span>{{event.seat_count - event.reservationCount }}</span></div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-lg-9 col-sm-12 pt-2"> <div class="col-lg-9 col-sm-12 pt-2">

View File

@ -30,7 +30,6 @@ export class EventsComponent implements OnInit {
}); });
this.eventTypeForm.get('eventType').valueChanges.subscribe((params) => { this.eventTypeForm.get('eventType').valueChanges.subscribe((params) => {
console.info('event type value change', params);
this.selectedEventType = params; this.selectedEventType = params;
this.filterEvents(); this.filterEvents();
}); });
@ -38,7 +37,6 @@ export class EventsComponent implements OnInit {
} }
filterEvents() { filterEvents() {
console.info(this.events);
this.eventTypeForm.get('eventType'); this.eventTypeForm.get('eventType');
this.events = this.originalEvents; this.events = this.originalEvents;
if (this.selectedEventType && this.selectedEventType > 0) { if (this.selectedEventType && this.selectedEventType > 0) {
@ -71,7 +69,7 @@ export class EventsComponent implements OnInit {
} }
mayRegister(event: Event) { mayRegister(event: Event) {
return event.reservedAt == null && event.reservationCount < event.seatCount; return event.reservedAt == null && event.reservationCount < event.seat_count;
} }
mayCancel(event: Event) { mayCancel(event: Event) {
@ -79,7 +77,7 @@ export class EventsComponent implements OnInit {
} }
noFreeSeat(event: Event) { noFreeSeat(event: Event) {
return event.reservedAt == null && event.reservationCount >= event.seatCount; return event.reservedAt == null && event.reservationCount >= event.seat_count;
} }
prepareEventDates(events: Event[]) { prepareEventDates(events: Event[]) {

View File

@ -23,7 +23,6 @@ export class HomeComponent implements OnInit {
} }
handleEvent($event: MonthCalendarEvent) { handleEvent($event: MonthCalendarEvent) {
console.info($event);
this.navigationService.navigateToEventDetails($event.event.id); this.navigationService.navigateToEventDetails($event.event.id);
} }
} }

View File

@ -0,0 +1,7 @@
<div class="container">
<!-- <app-fit-weekday-selector [days]="(availableEvents | async)?.days" ></app-fit-weekday-selector>-->
<ng-container *ngIf="registration | async">
{{registration | json}}
</ng-container>
</div>

View File

@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { RegistrationComponent } from './registration.component';
describe('RegistrationComponent', () => {
let component: RegistrationComponent;
let fixture: ComponentFixture<RegistrationComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ RegistrationComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(RegistrationComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,27 @@
import { Component, OnInit } from '@angular/core';
import {EventService, Registration} from "../../services/event.service";
import {Observable} from "rxjs";
import {ActivatedRoute, Router} from "@angular/router";
@Component({
selector: 'app-registration',
templateUrl: './registration.component.html',
styleUrls: ['./registration.component.scss']
})
export class RegistrationComponent implements OnInit {
registration: Observable<Registration>;
constructor(private eventService: EventService,
private route: Router,
private activeRoute: ActivatedRoute ) { }
ngOnInit() {
this.activeRoute.params.subscribe( value => {
console.info("map: ", this.activeRoute.snapshot.paramMap);
this.registration = this.eventService.findRegistration(+this.activeRoute.snapshot.paramMap.get('idRegistration'));
});
}
}

View File

@ -0,0 +1,13 @@
<div class="container">
<!-- <app-fit-weekday-selector [days]="(availableEvents | async)?.days" ></app-fit-weekday-selector>-->
<ng-container *ngIf="registrations | async">
<div class="list-group ">
<div class="list-group-item"
*ngFor="let registration of (registrations | async) "
(click)="showRegistration(registration)">
{{(registration.event.start * 1000) | date:'yyyy.MM.dd HH:mm'}} - {{registration.event.eventType.name}}
</div>
</div>
</ng-container>
</div>

View File

@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { RegistrationsComponent } from './registrations.component';
describe('RegistrationsComponent', () => {
let component: RegistrationsComponent;
let fixture: ComponentFixture<RegistrationsComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ RegistrationsComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(RegistrationsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,31 @@
import { Component, OnInit } from '@angular/core';
import {Observable} from "rxjs";
import {EventService, Registration} from "../../services/event.service";
import {NavigationService} from "../../services/navigation.service";
import {flatMap, map, mergeMap} from "rxjs/operators";
@Component({
selector: 'app-registrations',
templateUrl: './registrations.component.html',
styleUrls: ['./registrations.component.scss']
})
export class RegistrationsComponent implements OnInit {
registrations: Observable<Registration[]>;
constructor(private eventService: EventService, private navigationService: NavigationService) { }
ngOnInit() {
this.registrations = this.eventService.findRegistrations()
.pipe( map(
(registration: Registration[]) => {
registration = registration.sort( (a, b) => a.created_at - b.created_at);
return registration;
}
) );
}
showRegistration(registration: Registration) {
this.navigationService.navigateRegistration(registration.id);
}
}

View File

@ -1,6 +1,3 @@
import {Observable} from "rxjs";
import {EventType} from "./event.service";
export class Endpoints { export class Endpoints {
private static contextPath = "http://localhost:86/fitness_web"; private static contextPath = "http://localhost:86/fitness_web";
private static baseUrl: string = Endpoints.contextPath + "/customerapi/web/index.php?r="; private static baseUrl: string = Endpoints.contextPath + "/customerapi/web/index.php?r=";
@ -14,11 +11,20 @@ export class Endpoints {
} }
public static GET_EVENT( id: number){ public static GET_EVENT( id: number){
return `${this.baseUrl}/event&id_event=${id}`; return `${this.baseUrl}/event/event&id_event=${id}`;
} }
public static POST_EVENT_REGISTER( id: number){
return `${this.baseUrl}/event/register&id_event=${id}`; public static POST_EVENT_REGISTRATIONS_REGISTER(id: number){
return `${this.baseUrl}/event-registration/register&id_event=${id}`;
}
public static GET_EVENT_REGISTRATIONS_FIND(){
return `${this.baseUrl}/event-registration/index`;
}
public static GET_REGISTRATION( id: number){
return `${this.baseUrl}/event-registration/registration&id_registration=${id}`;
} }
public static POST_EVENT_CANCEL( id: number){ public static POST_EVENT_CANCEL( id: number){

View File

@ -20,12 +20,19 @@ export class EventService {
} }
findEvent(idEvent: number ): Observable<Event> { findEvent(idEvent: number ): Observable<Event> {
console.info(Endpoints.GET_EVENT( idEvent ));
return this.http.get(Endpoints.GET_EVENT( idEvent )) as Observable<Event>; return this.http.get(Endpoints.GET_EVENT( idEvent )) as Observable<Event>;
} }
register(idEvent: number ): Observable<Event> { register(idEvent: number ): Observable<Event> {
return this.http.post(Endpoints.POST_EVENT_REGISTER( idEvent ),{}) as Observable<Event>; return this.http.post(Endpoints.POST_EVENT_REGISTRATIONS_REGISTER( idEvent ),{}) as Observable<Event>;
}
findRegistrations(): Observable<Registration[]> {
return this.http.get(Endpoints.GET_EVENT_REGISTRATIONS_FIND()) as Observable<Registration[]>;
}
findRegistration(idRegistration: number ): Observable<Registration> {
return this.http.get(Endpoints.GET_REGISTRATION( idRegistration )) as Observable<Registration>;
} }
cancel(idEvent: number ): Observable<Event> { cancel(idEvent: number ): Observable<Event> {
@ -49,7 +56,7 @@ export interface Event {
start: number; start: number;
end: number; end: number;
trainer?: Trainer; trainer?: Trainer;
seatCount: number; seat_count: number;
reservationCount: number; reservationCount: number;
eventType: EventType; eventType: EventType;
reservedAt: number; reservedAt: number;
@ -77,3 +84,8 @@ export interface EventsAvailableResponse {
events: Event[]; events: Event[];
} }
export interface Registration {
id: number;
created_at: number;
event: Event
}

View File

@ -25,4 +25,9 @@ export class NavigationService {
} }
public navigateRegistration(idRegistration){
this.navigate(['/registration/'+idRegistration ])
}
} }

View File

@ -13,8 +13,11 @@ use common\models\Event;
use customerapi\models\available\EventInterval; use customerapi\models\available\EventInterval;
use customerapi\models\available\EventAvailable; use customerapi\models\available\EventAvailable;
use customerapi\models\DayToDisplay; use customerapi\models\DayToDisplay;
use customerapi\models\details\EventDetailsView;
use DateTime; use DateTime;
use Exception; use Exception;
use yii\db\Query;
use yii\web\Response;
/** @noinspection PhpUnused */ /** @noinspection PhpUnused */
@ -82,7 +85,6 @@ class EventController extends CustomerApiController
} }
} }
return return
$this->asJson([ $this->asJson([
'interval' => $interval, '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());
}
}
} }

View File

@ -13,9 +13,12 @@ use common\manager\EventRegistrationManager;
use common\models\CardEventRegistrationForm; use common\models\CardEventRegistrationForm;
use common\models\Customer; use common\models\Customer;
use customerapi\models\available\EventInterval; use customerapi\models\available\EventInterval;
use customerapi\models\available\EventRegistrationAvailable; use customerapi\models\registrations\EventRegistrationAvailable;
use Exception;
use Throwable; use Throwable;
use Yii; use Yii;
use yii\db\ActiveQuery;
use yii\web\Response;
/** @noinspection PhpUnused */ /** @noinspection PhpUnused */
@ -23,37 +26,62 @@ class EventRegistrationController extends CustomerApiController
{ {
/** @noinspection PhpUnused */ /** @noinspection PhpUnused */
/**
* @return Response
* @throws Exception
*/
public function actionIndex() public function actionIndex()
{ {
$interval = EventInterval::createInterval(); $registrations =$this->prepareQueryFindRegistrationsForCustomer()->all();
return $this->asJson( $registrations );
$registrations = EventRegistrationAvailable::find() }
->innerJoinWith('event')
->andWhere(['and',
['>=', 'event.start', $interval->firstActiveDate->getTimestamp()],
['<', 'event.start', $interval->lastActiveDate->getTimestamp()],
['id_customer' => Yii::$app->user->getId()]
])->all();
/** @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( return $this->asJson(
$registrations $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 * @noinspection PhpUnused
* @param $idEvent * @param $id_event
* @throws Throwable * @throws Throwable
*/ */
public function actionRegister($idEvent) { public function actionRegister($id_event) {
/** @var Customer $customer */ /** @var Customer $customer */
$customer = Yii::$app->user->getIdentity(); $customer = Yii::$app->user->getIdentity();
$card =$customer->card; $card =$customer->card;
$form = new CardEventRegistrationForm(); $form = new CardEventRegistrationForm();
$form->event_id = $idEvent; $form->event_id = $id_event;
$form->card_number = $card->number; $form->card_number = $card->number;
$manager = new EventRegistrationManager(); $manager = new EventRegistrationManager();

View File

@ -5,7 +5,6 @@ namespace customerapi\models\available;
use common\models\Event; use common\models\Event;
use common\models\EventType;
class EventAvailable extends Event class EventAvailable extends Event
{ {

View File

@ -1,13 +0,0 @@
<?php
namespace customerapi\models\available;
use common\models\EventRegistration;
class EventRegistrationAvailable extends EventRegistration
{
}

View File

@ -0,0 +1,56 @@
<?php
namespace customerapi\models\details;
use common\models\Event;
class EventDetailsView extends Event
{
public $reservationCount;
/**
* @return string
*/
protected function getTrainerClass()
{
// override trainer class to have more control
// about json fields
return TrainerDetailsView::class;
}
protected function getEventTypeClass()
{
return EventTypeDetailsView::class;
}
protected function getRoomClass()
{
return RoomDetailsView::class;
}
/**
* @Override
* @return array|false
*/
function fields()
{
$fields = [
"id" => "id",
"start" => "start",
"end" => "end",
"seat_count" => "seat_count",
"active" => "active",
// "reservationCount" => "reservationCount"
];
$fields['trainer'] = 'trainer';
$fields['eventType'] = 'eventType';
$fields['room'] = 'room';
return $fields;
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace customerapi\models\details;
use common\models\EventType;
class EventTypeDetailsView extends EventType
{
function fields()
{
return [
'id' => 'id',
'name' => 'name'
];
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace customerapi\models\details;
use common\models\Room;
class RoomDetailsView extends Room
{
function fields()
{
return [
'id' => 'id',
'name' => 'name',
'seat_count' => 'seat_count'
];
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace customerapi\models\details;
use common\models\Trainer;
class TrainerDetailsView extends Trainer
{
public function fields()
{
return [
'id' => 'id',
'name' => 'name'
];
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace customerapi\models\registrations;
use common\models\EventRegistration;
use customerapi\models\available\EventAvailable;
class EventRegistrationAvailable extends EventRegistration
{
function fields()
{
$fields = [
"id" => "id",
"created_at" => "created_at",
"updated_at" => "updated_at",
];
$fields['event'] = 'event';
return $fields;
}
public function getEventClass()
{
return EventAvailable::class;
}
}