customer available events improvements
This commit is contained in:
parent
2bf9985928
commit
18cd8312b5
@ -295,6 +295,8 @@ class Customer extends BaseFitnessActiveRecord implements IdentityInterface
|
||||
public function setPassword($password)
|
||||
{
|
||||
$this->password_hash = Yii::$app->security->generatePasswordHash($password);
|
||||
// \Yii::info("pwd", $this->password_hash);
|
||||
// echo $this->password_hash;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -172,6 +172,19 @@ class Event extends ActiveRecord
|
||||
/**
|
||||
* @return EventRegistration[]|ActiveQuery
|
||||
*/
|
||||
public function getActiveEventRegistrationsForCustomer(){
|
||||
return $this->hasMany(EventRegistration::class,['id_event' => 'id'])->andWhere(
|
||||
[
|
||||
'event_registration.canceled_at' => null,
|
||||
'event_registration.deleted_at' => null,
|
||||
'event_registration.id_customer' => \Yii::$app->user->id
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return integer
|
||||
*/
|
||||
public function getEventRegistrationCount(){
|
||||
return count($this->getActiveEventRegistrations()->all());
|
||||
}
|
||||
|
||||
6
customer/app/src/app/app.types.ts
Normal file
6
customer/app/src/app/app.types.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import {Event, Registration} from "./services/event.service";
|
||||
|
||||
export interface CalendarEvent{
|
||||
event: Event;
|
||||
registrations: Registration;
|
||||
}
|
||||
@ -1,25 +0,0 @@
|
||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
|
||||
import { MonthCalendarDayComponent } from './month-calendar-day.component';
|
||||
|
||||
describe('MonthCalendarDayComponent', () => {
|
||||
let component: MonthCalendarDayComponent;
|
||||
let fixture: ComponentFixture<MonthCalendarDayComponent>;
|
||||
|
||||
beforeEach(waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ MonthCalendarDayComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(MonthCalendarDayComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -5,7 +5,7 @@
|
||||
<h5 *ngFor="let dayOfWeek of daysOfWeek" class="col-sm p-1 text-center name-of-day-of-week">{{dayOfWeek.name}}</h5>
|
||||
</div>
|
||||
</header>
|
||||
<div *ngIf="eventsAvailableResponse" class="row border border-right-0 border-bottom-0">
|
||||
<div *ngIf="eventsAvailableResponse" class="row border border-right-0 border-bottom-0 mb-4">
|
||||
<ng-container *ngFor="let day of eventsAvailableResponse.dates; let i = index">
|
||||
<div app-month-calendar-day [day]="day" (onEvent)="handleEvent($event)" ></div>
|
||||
<div *ngIf="i > 0 && ( ((i+1) % 7) == 0)" class="w-100"></div>
|
||||
|
||||
@ -1,25 +0,0 @@
|
||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
|
||||
import { MonthCalendarComponent } from './month-calendar.component';
|
||||
|
||||
describe('MonthCalendarComponent', () => {
|
||||
let component: MonthCalendarComponent;
|
||||
let fixture: ComponentFixture<MonthCalendarComponent>;
|
||||
|
||||
beforeEach(waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ MonthCalendarComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(MonthCalendarComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -1,25 +0,0 @@
|
||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
|
||||
import { EventsComponent } from './events.component';
|
||||
|
||||
describe('EventsComponent', () => {
|
||||
let component: EventsComponent;
|
||||
let fixture: ComponentFixture<EventsComponent>;
|
||||
|
||||
beforeEach(waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ EventsComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(EventsComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -1,6 +1,6 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import {EventsAvailableResponse, EventService} from "../../services/event.service";
|
||||
import {Observable} from "rxjs";
|
||||
import {forkJoin, Observable} from "rxjs";
|
||||
import {MonthCalendarEvent} from "../../components/month-calendar/month-calendar.component";
|
||||
import {NavigationService} from "../../services/navigation.service";
|
||||
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {HttpClient} from "@angular/common/http";
|
||||
import {Endpoints} from "./endpoints";
|
||||
import {Observable} from "rxjs";
|
||||
import {forkJoin, Observable} from "rxjs";
|
||||
import {map} from "rxjs/operators";
|
||||
import {CalendarEvent} from "../app.types";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
|
||||
@ -9,14 +9,13 @@
|
||||
namespace customerapi\controllers;
|
||||
|
||||
|
||||
use common\models\Event;
|
||||
use common\models\EventRegistration;
|
||||
use customerapi\models\available\EventInterval;
|
||||
use customerapi\models\available\EventAvailable;
|
||||
use customerapi\models\DayToDisplay;
|
||||
use customerapi\models\details\EventDetailsView;
|
||||
use DateTime;
|
||||
use Exception;
|
||||
use yii\db\ActiveRecord;
|
||||
use yii\db\Query;
|
||||
use yii\web\Response;
|
||||
|
||||
@ -64,19 +63,21 @@ class EventController extends CustomerApiController
|
||||
->innerJoinWith('trainer')
|
||||
->innerJoinWith('eventType')
|
||||
->innerJoinWith('room')
|
||||
->joinWith('activeEventRegistrations')
|
||||
->joinWith('activeEventRegistrationsForCustomer')
|
||||
->andWhere(['>=', 'event.start', $interval->firstActiveDate->getTimestamp()])
|
||||
->andWhere(['<', 'event.start', (clone $interval->lastActiveDate)->modify('+1 day')->getTimestamp()])
|
||||
->andWhere(['event.active' => '1'])
|
||||
->all();
|
||||
|
||||
// set events per day
|
||||
/** @var Event $event */
|
||||
/** @var EventAvailable $event */
|
||||
foreach ($events as $event) {
|
||||
$eventDay = new DateTime();
|
||||
$eventDay->setTimestamp($event->start);
|
||||
$eventDay->setTime(0, 0);
|
||||
|
||||
$event->reservationCount = $event->getEventRegistrationCount();
|
||||
|
||||
/** @var DayToDisplay $date */
|
||||
foreach ($dates as $date) {
|
||||
if ($date->date === $eventDay->getTimestamp()) {
|
||||
@ -96,7 +97,7 @@ class EventController extends CustomerApiController
|
||||
/**
|
||||
* @param Query $query
|
||||
* @param $interval
|
||||
* @return the query with the added conditions
|
||||
* @return Query the query with the added conditions
|
||||
*/
|
||||
private function buildEventQuery($query, $interval)
|
||||
{
|
||||
@ -104,7 +105,7 @@ class EventController extends CustomerApiController
|
||||
->innerJoinWith('trainer')
|
||||
->innerJoinWith('eventType')
|
||||
->innerJoinWith('room')
|
||||
->joinWith('activeEventRegistrations')
|
||||
->joinWith('activeEventRegistrations as registrations')
|
||||
->andWhere(['>=', 'event.start', $interval->firstActiveDate->getTimestamp()])
|
||||
->andWhere(['<', 'event.start', (clone $interval->lastActiveDate)->modify('+1 day')->getTimestamp()])
|
||||
->andWhere(['event.active' => '1']);
|
||||
|
||||
@ -9,15 +9,11 @@
|
||||
namespace customerapi\controllers;
|
||||
|
||||
|
||||
use common\manager\EventRegistrationManager;
|
||||
use customerapi\manager\EventRegistrationManager;
|
||||
use common\models\CardEventRegistrationForm;
|
||||
use common\models\Customer;
|
||||
use customerapi\models\available\EventInterval;
|
||||
use customerapi\models\registrations\EventRegistrationAvailable;
|
||||
use Exception;
|
||||
use Throwable;
|
||||
use Yii;
|
||||
use yii\db\ActiveQuery;
|
||||
use yii\web\Response;
|
||||
|
||||
/** @noinspection PhpUnused */
|
||||
@ -32,8 +28,8 @@ class EventRegistrationController extends CustomerApiController
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
$registrations =$this->prepareQueryFindRegistrationsForCustomer()->all();
|
||||
return $this->asJson( $registrations );
|
||||
$registrationManager = new EventRegistrationManager();
|
||||
return $this->asJson( $registrationManager->findCustomerRegistrationsWithEvent() );
|
||||
}
|
||||
|
||||
/** @noinspection PhpUnused */
|
||||
@ -44,35 +40,15 @@ class EventRegistrationController extends CustomerApiController
|
||||
*/
|
||||
public function actionRegistration($id_registration)
|
||||
{
|
||||
$registrations = $this->prepareQueryFindRegistrationsForCustomer()
|
||||
->andWhere(['event_registration.id' => $id_registration])
|
||||
->one();
|
||||
$registrationManager = new EventRegistrationManager();
|
||||
return $this->asJson(
|
||||
$registrations
|
||||
$registrationManager->findRegistration($id_registration)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @param $id_event
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function actionRegister($id_event) {
|
||||
/** @var Customer $customer */
|
||||
|
||||
@ -2,13 +2,9 @@
|
||||
namespace customerapi\controllers;
|
||||
|
||||
use Yii;
|
||||
use common\models\LoginForm;
|
||||
use yii\web\Controller;
|
||||
use yii\filters\VerbFilter;
|
||||
use yii\filters\AccessControl;
|
||||
use common\models\User;
|
||||
use common\components\Helper;
|
||||
use common\models\Log;
|
||||
|
||||
/**
|
||||
* Site controller
|
||||
@ -68,43 +64,6 @@ class SiteController extends Controller
|
||||
return $this->render('index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs in a user.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionLogin()
|
||||
{
|
||||
if (!\Yii::$app->user->isGuest) {
|
||||
return $this->goHome();
|
||||
}
|
||||
|
||||
$model = new LoginForm();
|
||||
if ($model->load(Yii::$app->request->post()) && $model->login()) {
|
||||
|
||||
$geoip = Helper::getGeoIp();
|
||||
|
||||
$message = "";
|
||||
$user = User::findOne(\Yii::$app->user->id);
|
||||
if ( isset($geoip)){
|
||||
$ip = isset( $geoip->ip ) ? $geoip->ip : "";
|
||||
$city = isset( $geoip->city ) ? $geoip->city : "";
|
||||
$message = "Bejelentkezés: " .$user->username. " Ip cím:". $ip . " Város: " . $city;
|
||||
}
|
||||
|
||||
Log::log([
|
||||
'type' =>Log::$TYPE_LOGIN,
|
||||
'message' => $message
|
||||
]);
|
||||
|
||||
return $this->redirect(['account/select']);
|
||||
} else {
|
||||
return $this->render('login', ['model' => $model,]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Logs out the current user.
|
||||
*
|
||||
|
||||
@ -20,10 +20,16 @@ class UserController extends RestController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* hash for password test is:
|
||||
* $2y$13$D2BauYE2nhCdVDNatT9BMeWGxOvi5t5V6W2OUjr6sj2FRpb317Cpq
|
||||
*
|
||||
*/
|
||||
/** @noinspection PhpUnused */
|
||||
public function actionLogin( )
|
||||
{
|
||||
|
||||
// $customer = new Customer();
|
||||
// $customer->setPassword("test");
|
||||
$form = new LoginForm();
|
||||
|
||||
$form->load(\Yii::$app->request->post( ), '');
|
||||
|
||||
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()]
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -29,20 +29,21 @@ class EventAvailable extends Event
|
||||
}
|
||||
|
||||
|
||||
|
||||
function fields()
|
||||
{
|
||||
|
||||
$fields = [
|
||||
"id" => "id",
|
||||
"start" => "start",
|
||||
"end" => "end",
|
||||
"seat_count" => "seat_count",
|
||||
"active" => "active",
|
||||
// "reservationCount" => "reservationCount"
|
||||
"reservationCount" => "reservationCount",
|
||||
];
|
||||
$fields['trainer'] = 'trainer';
|
||||
$fields['eventType'] = 'eventType';
|
||||
$fields['room'] = 'room';
|
||||
$fields['registrations'] = 'activeEventRegistrationsForCustomer';
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user