customer available events improvements

This commit is contained in:
Roland Schneider 2021-09-10 23:30:13 +02:00
parent 2bf9985928
commit 18cd8312b5
15 changed files with 125 additions and 179 deletions

View File

@ -44,20 +44,20 @@ use yii\web\IdentityInterface;
*/ */
class Customer extends BaseFitnessActiveRecord implements IdentityInterface class Customer extends BaseFitnessActiveRecord implements IdentityInterface
{ {
const STATUS_DELETED = 0; const STATUS_DELETED = 0;
const STATUS_ACTIVE = 10; const STATUS_ACTIVE = 10;
const SEX_UNKNOWN = 0; const SEX_UNKNOWN = 0;
const SEX_MAN = 10; const SEX_MAN = 10;
const SEX_WOMAN = 20; const SEX_WOMAN = 20;
public static $ENABLED = 1; public static $ENABLED = 1;
public $photo_data; public $photo_data;
/** /**
* @inheritdoc * @inheritdoc
*/ */
@ -65,7 +65,7 @@ class Customer extends BaseFitnessActiveRecord implements IdentityInterface
{ {
return 'customer'; return 'customer';
} }
/** /**
* @inheritdoc * @inheritdoc
@ -117,16 +117,16 @@ class Customer extends BaseFitnessActiveRecord implements IdentityInterface
'birth_place' => Yii::t('common/customer', 'Születési hely'), 'birth_place' => Yii::t('common/customer', 'Születési hely'),
]; ];
} }
static function statuses() { static function statuses() {
return [ return [
self::STATUS_ACTIVE => Yii::t('common/account', 'Active'), self::STATUS_ACTIVE => Yii::t('common/account', 'Active'),
self::STATUS_DELETED => Yii::t('common/account', 'Inactive'), self::STATUS_DELETED => Yii::t('common/account', 'Inactive'),
]; ];
} }
public function getStatusHuman(){ public function getStatusHuman(){
$result = null; $result = null;
$s = self::statuses( ); $s = self::statuses( );
@ -135,7 +135,7 @@ class Customer extends BaseFitnessActiveRecord implements IdentityInterface
} }
return $result; return $result;
} }
static function sexes() { static function sexes() {
return [ return [
self::SEX_UNKNOWN => Yii::t('common/customer', 'Unknown sex'), self::SEX_UNKNOWN => Yii::t('common/customer', 'Unknown sex'),
@ -143,7 +143,7 @@ class Customer extends BaseFitnessActiveRecord implements IdentityInterface
self::SEX_WOMAN => Yii::t('common/customer', 'Woman'), self::SEX_WOMAN => Yii::t('common/customer', 'Woman'),
]; ];
} }
public function getSexHuman(){ public function getSexHuman(){
$result = null; $result = null;
$s = self::sexes( ); $s = self::sexes( );
@ -152,12 +152,12 @@ class Customer extends BaseFitnessActiveRecord implements IdentityInterface
} }
return $result; return $result;
} }
public function isInactive(){ public function isInactive(){
return $this->status == self::STATUS_DELETED; return $this->status == self::STATUS_DELETED;
} }
public function getCard(){ public function getCard(){
return $this->hasOne ( Card::className (), [ return $this->hasOne ( Card::className (), [
'id_card' => 'id_customer_card' 'id_card' => 'id_customer_card'
@ -173,7 +173,7 @@ class Customer extends BaseFitnessActiveRecord implements IdentityInterface
'id_image' => 'id_image' 'id_image' => 'id_image'
] ); ] );
} }
public function getCustomerCardNumber(){ public function getCustomerCardNumber(){
$result = null; $result = null;
$card = $this->card; $card = $this->card;
@ -190,17 +190,17 @@ class Customer extends BaseFitnessActiveRecord implements IdentityInterface
} }
return $result; return $result;
} }
public function getFullAddress(){ public function getFullAddress(){
$zip = $this->zip; $zip = $this->zip;
$city = $this->city; $city = $this->city;
$address = $this->address; $address = $this->address;
$result = $zip . " " .$city . ", ". $address; $result = $zip . " " .$city . ", ". $address;
return $result; return $result;
} }
public function afterSave($insert, $changedAttributes){ public function afterSave($insert, $changedAttributes){
if ( !$insert ){ if ( !$insert ){
Card::updateCardFlagTicket($this->id_customer_card); Card::updateCardFlagTicket($this->id_customer_card);
@ -295,6 +295,8 @@ class Customer extends BaseFitnessActiveRecord implements IdentityInterface
public function setPassword($password) public function setPassword($password)
{ {
$this->password_hash = Yii::$app->security->generatePasswordHash($password); $this->password_hash = Yii::$app->security->generatePasswordHash($password);
// \Yii::info("pwd", $this->password_hash);
// echo $this->password_hash;
} }
/** /**

View File

@ -172,6 +172,19 @@ class Event extends ActiveRecord
/** /**
* @return EventRegistration[]|ActiveQuery * @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(){ public function getEventRegistrationCount(){
return count($this->getActiveEventRegistrations()->all()); return count($this->getActiveEventRegistrations()->all());
} }

View File

@ -0,0 +1,6 @@
import {Event, Registration} from "./services/event.service";
export interface CalendarEvent{
event: Event;
registrations: Registration;
}

View File

@ -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();
});
});

View File

@ -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> <h5 *ngFor="let dayOfWeek of daysOfWeek" class="col-sm p-1 text-center name-of-day-of-week">{{dayOfWeek.name}}</h5>
</div> </div>
</header> </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"> <ng-container *ngFor="let day of eventsAvailableResponse.dates; let i = index">
<div app-month-calendar-day [day]="day" (onEvent)="handleEvent($event)" ></div> <div app-month-calendar-day [day]="day" (onEvent)="handleEvent($event)" ></div>
<div *ngIf="i > 0 && ( ((i+1) % 7) == 0)" class="w-100"></div> <div *ngIf="i > 0 && ( ((i+1) % 7) == 0)" class="w-100"></div>

View File

@ -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();
});
});

View File

@ -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();
});
});

View File

@ -1,6 +1,6 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import {EventsAvailableResponse, EventService} from "../../services/event.service"; 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 {MonthCalendarEvent} from "../../components/month-calendar/month-calendar.component";
import {NavigationService} from "../../services/navigation.service"; import {NavigationService} from "../../services/navigation.service";

View File

@ -1,7 +1,9 @@
import {Injectable} from '@angular/core'; import {Injectable} from '@angular/core';
import {HttpClient} from "@angular/common/http"; import {HttpClient} from "@angular/common/http";
import {Endpoints} from "./endpoints"; import {Endpoints} from "./endpoints";
import {Observable} from "rxjs"; import {forkJoin, Observable} from "rxjs";
import {map} from "rxjs/operators";
import {CalendarEvent} from "../app.types";
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'

View File

@ -9,14 +9,13 @@
namespace customerapi\controllers; namespace customerapi\controllers;
use common\models\Event;
use common\models\EventRegistration;
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 customerapi\models\details\EventDetailsView;
use DateTime; use DateTime;
use Exception; use Exception;
use yii\db\ActiveRecord;
use yii\db\Query; use yii\db\Query;
use yii\web\Response; use yii\web\Response;
@ -64,19 +63,21 @@ class EventController extends CustomerApiController
->innerJoinWith('trainer') ->innerJoinWith('trainer')
->innerJoinWith('eventType') ->innerJoinWith('eventType')
->innerJoinWith('room') ->innerJoinWith('room')
->joinWith('activeEventRegistrations') ->joinWith('activeEventRegistrationsForCustomer')
->andWhere(['>=', 'event.start', $interval->firstActiveDate->getTimestamp()]) ->andWhere(['>=', 'event.start', $interval->firstActiveDate->getTimestamp()])
->andWhere(['<', 'event.start', (clone $interval->lastActiveDate)->modify('+1 day')->getTimestamp()]) ->andWhere(['<', 'event.start', (clone $interval->lastActiveDate)->modify('+1 day')->getTimestamp()])
->andWhere(['event.active' => '1']) ->andWhere(['event.active' => '1'])
->all(); ->all();
// set events per day // set events per day
/** @var Event $event */ /** @var EventAvailable $event */
foreach ($events as $event) { foreach ($events as $event) {
$eventDay = new DateTime(); $eventDay = new DateTime();
$eventDay->setTimestamp($event->start); $eventDay->setTimestamp($event->start);
$eventDay->setTime(0, 0); $eventDay->setTime(0, 0);
$event->reservationCount = $event->getEventRegistrationCount();
/** @var DayToDisplay $date */ /** @var DayToDisplay $date */
foreach ($dates as $date) { foreach ($dates as $date) {
if ($date->date === $eventDay->getTimestamp()) { if ($date->date === $eventDay->getTimestamp()) {
@ -96,7 +97,7 @@ class EventController extends CustomerApiController
/** /**
* @param Query $query * @param Query $query
* @param $interval * @param $interval
* @return the query with the added conditions * @return Query the query with the added conditions
*/ */
private function buildEventQuery($query, $interval) private function buildEventQuery($query, $interval)
{ {
@ -104,7 +105,7 @@ class EventController extends CustomerApiController
->innerJoinWith('trainer') ->innerJoinWith('trainer')
->innerJoinWith('eventType') ->innerJoinWith('eventType')
->innerJoinWith('room') ->innerJoinWith('room')
->joinWith('activeEventRegistrations') ->joinWith('activeEventRegistrations as registrations')
->andWhere(['>=', 'event.start', $interval->firstActiveDate->getTimestamp()]) ->andWhere(['>=', 'event.start', $interval->firstActiveDate->getTimestamp()])
->andWhere(['<', 'event.start', (clone $interval->lastActiveDate)->modify('+1 day')->getTimestamp()]) ->andWhere(['<', 'event.start', (clone $interval->lastActiveDate)->modify('+1 day')->getTimestamp()])
->andWhere(['event.active' => '1']); ->andWhere(['event.active' => '1']);

View File

@ -9,15 +9,11 @@
namespace customerapi\controllers; namespace customerapi\controllers;
use common\manager\EventRegistrationManager; use customerapi\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\registrations\EventRegistrationAvailable;
use Exception; use Exception;
use Throwable;
use Yii; use Yii;
use yii\db\ActiveQuery;
use yii\web\Response; use yii\web\Response;
/** @noinspection PhpUnused */ /** @noinspection PhpUnused */
@ -32,8 +28,8 @@ class EventRegistrationController extends CustomerApiController
*/ */
public function actionIndex() public function actionIndex()
{ {
$registrations =$this->prepareQueryFindRegistrationsForCustomer()->all(); $registrationManager = new EventRegistrationManager();
return $this->asJson( $registrations ); return $this->asJson( $registrationManager->findCustomerRegistrationsWithEvent() );
} }
/** @noinspection PhpUnused */ /** @noinspection PhpUnused */
@ -44,35 +40,15 @@ class EventRegistrationController extends CustomerApiController
*/ */
public function actionRegistration($id_registration) public function actionRegistration($id_registration)
{ {
$registrations = $this->prepareQueryFindRegistrationsForCustomer() $registrationManager = new EventRegistrationManager();
->andWhere(['event_registration.id' => $id_registration])
->one();
return $this->asJson( 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 * @noinspection PhpUnused
* @param $id_event * @param $id_event
* @throws Throwable
*/ */
public function actionRegister($id_event) { public function actionRegister($id_event) {
/** @var Customer $customer */ /** @var Customer $customer */

View File

@ -2,13 +2,9 @@
namespace customerapi\controllers; namespace customerapi\controllers;
use Yii; use Yii;
use common\models\LoginForm;
use yii\web\Controller; use yii\web\Controller;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;
use yii\filters\AccessControl; use yii\filters\AccessControl;
use common\models\User;
use common\components\Helper;
use common\models\Log;
/** /**
* Site controller * Site controller
@ -68,43 +64,6 @@ class SiteController extends Controller
return $this->render('index'); 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. * Logs out the current user.
* *

View File

@ -20,10 +20,16 @@ class UserController extends RestController
{ {
/**
* hash for password test is:
* $2y$13$D2BauYE2nhCdVDNatT9BMeWGxOvi5t5V6W2OUjr6sj2FRpb317Cpq
*
*/
/** @noinspection PhpUnused */ /** @noinspection PhpUnused */
public function actionLogin( ) public function actionLogin( )
{ {
// $customer = new Customer();
// $customer->setPassword("test");
$form = new LoginForm(); $form = new LoginForm();
$form->load(\Yii::$app->request->post( ), ''); $form->load(\Yii::$app->request->post( ), '');

View 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()]
]);
}
}

View File

@ -29,20 +29,21 @@ class EventAvailable extends Event
} }
function fields() function fields()
{ {
$fields = [ $fields = [
"id" => "id", "id" => "id",
"start" => "start", "start" => "start",
"end" => "end", "end" => "end",
"seat_count" => "seat_count", "seat_count" => "seat_count",
"active" => "active", "active" => "active",
// "reservationCount" => "reservationCount" "reservationCount" => "reservationCount",
]; ];
$fields['trainer'] = 'trainer'; $fields['trainer'] = 'trainer';
$fields['eventType'] = 'eventType'; $fields['eventType'] = 'eventType';
$fields['room'] = 'room'; $fields['room'] = 'room';
$fields['registrations'] = 'activeEventRegistrationsForCustomer';
return $fields; return $fields;
} }