diff --git a/common/models/Customer.php b/common/models/Customer.php index 29a3177..c5f11d2 100644 --- a/common/models/Customer.php +++ b/common/models/Customer.php @@ -44,20 +44,20 @@ use yii\web\IdentityInterface; */ class Customer extends BaseFitnessActiveRecord implements IdentityInterface { - + const STATUS_DELETED = 0; const STATUS_ACTIVE = 10; - + const SEX_UNKNOWN = 0; const SEX_MAN = 10; const SEX_WOMAN = 20; - + public static $ENABLED = 1; - + public $photo_data; - - + + /** * @inheritdoc */ @@ -65,7 +65,7 @@ class Customer extends BaseFitnessActiveRecord implements IdentityInterface { return 'customer'; } - + /** * @inheritdoc @@ -117,16 +117,16 @@ class Customer extends BaseFitnessActiveRecord implements IdentityInterface 'birth_place' => Yii::t('common/customer', 'Születési hely'), ]; } - - - + + + static function statuses() { return [ self::STATUS_ACTIVE => Yii::t('common/account', 'Active'), self::STATUS_DELETED => Yii::t('common/account', 'Inactive'), ]; } - + public function getStatusHuman(){ $result = null; $s = self::statuses( ); @@ -135,7 +135,7 @@ class Customer extends BaseFitnessActiveRecord implements IdentityInterface } return $result; } - + static function sexes() { return [ 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'), ]; } - + public function getSexHuman(){ $result = null; $s = self::sexes( ); @@ -152,12 +152,12 @@ class Customer extends BaseFitnessActiveRecord implements IdentityInterface } return $result; } - + public function isInactive(){ return $this->status == self::STATUS_DELETED; } - - + + public function getCard(){ return $this->hasOne ( Card::className (), [ 'id_card' => 'id_customer_card' @@ -173,7 +173,7 @@ class Customer extends BaseFitnessActiveRecord implements IdentityInterface 'id_image' => 'id_image' ] ); } - + public function getCustomerCardNumber(){ $result = null; $card = $this->card; @@ -190,17 +190,17 @@ class Customer extends BaseFitnessActiveRecord implements IdentityInterface } return $result; } - + public function getFullAddress(){ $zip = $this->zip; $city = $this->city; $address = $this->address; - + $result = $zip . " " .$city . ", ". $address; return $result; - + } - + public function afterSave($insert, $changedAttributes){ if ( !$insert ){ Card::updateCardFlagTicket($this->id_customer_card); @@ -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; } /** diff --git a/common/models/Event.php b/common/models/Event.php index ee491c9..63db6eb 100644 --- a/common/models/Event.php +++ b/common/models/Event.php @@ -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()); } diff --git a/customer/app/src/app/app.types.ts b/customer/app/src/app/app.types.ts new file mode 100644 index 0000000..f408301 --- /dev/null +++ b/customer/app/src/app/app.types.ts @@ -0,0 +1,6 @@ +import {Event, Registration} from "./services/event.service"; + +export interface CalendarEvent{ + event: Event; + registrations: Registration; +} diff --git a/customer/app/src/app/components/month-calendar-day/month-calendar-day.component.spec.ts b/customer/app/src/app/components/month-calendar-day/month-calendar-day.component.spec.ts deleted file mode 100644 index fabd31d..0000000 --- a/customer/app/src/app/components/month-calendar-day/month-calendar-day.component.spec.ts +++ /dev/null @@ -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; - - beforeEach(waitForAsync(() => { - TestBed.configureTestingModule({ - declarations: [ MonthCalendarDayComponent ] - }) - .compileComponents(); - })); - - beforeEach(() => { - fixture = TestBed.createComponent(MonthCalendarDayComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/customer/app/src/app/components/month-calendar/month-calendar.component.html b/customer/app/src/app/components/month-calendar/month-calendar.component.html index 54580f2..54f8f77 100644 --- a/customer/app/src/app/components/month-calendar/month-calendar.component.html +++ b/customer/app/src/app/components/month-calendar/month-calendar.component.html @@ -5,7 +5,7 @@
{{dayOfWeek.name}}
-
+
diff --git a/customer/app/src/app/components/month-calendar/month-calendar.component.spec.ts b/customer/app/src/app/components/month-calendar/month-calendar.component.spec.ts deleted file mode 100644 index 01d1c17..0000000 --- a/customer/app/src/app/components/month-calendar/month-calendar.component.spec.ts +++ /dev/null @@ -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; - - beforeEach(waitForAsync(() => { - TestBed.configureTestingModule({ - declarations: [ MonthCalendarComponent ] - }) - .compileComponents(); - })); - - beforeEach(() => { - fixture = TestBed.createComponent(MonthCalendarComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/customer/app/src/app/pages/events/events.component.spec.ts b/customer/app/src/app/pages/events/events.component.spec.ts deleted file mode 100644 index 96aabbf..0000000 --- a/customer/app/src/app/pages/events/events.component.spec.ts +++ /dev/null @@ -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; - - beforeEach(waitForAsync(() => { - TestBed.configureTestingModule({ - declarations: [ EventsComponent ] - }) - .compileComponents(); - })); - - beforeEach(() => { - fixture = TestBed.createComponent(EventsComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/customer/app/src/app/pages/home/home.component.ts b/customer/app/src/app/pages/home/home.component.ts index bd02eb2..daa96b2 100644 --- a/customer/app/src/app/pages/home/home.component.ts +++ b/customer/app/src/app/pages/home/home.component.ts @@ -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"; diff --git a/customer/app/src/app/services/event.service.ts b/customer/app/src/app/services/event.service.ts index 5bf3447..311a2ca 100644 --- a/customer/app/src/app/services/event.service.ts +++ b/customer/app/src/app/services/event.service.ts @@ -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' diff --git a/customerapi/controllers/EventController.php b/customerapi/controllers/EventController.php index c3bc25d..f219a91 100644 --- a/customerapi/controllers/EventController.php +++ b/customerapi/controllers/EventController.php @@ -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']); diff --git a/customerapi/controllers/EventRegistrationController.php b/customerapi/controllers/EventRegistrationController.php index d41e983..8ce7bff 100644 --- a/customerapi/controllers/EventRegistrationController.php +++ b/customerapi/controllers/EventRegistrationController.php @@ -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 */ diff --git a/customerapi/controllers/SiteController.php b/customerapi/controllers/SiteController.php index 4662b77..08ead75 100644 --- a/customerapi/controllers/SiteController.php +++ b/customerapi/controllers/SiteController.php @@ -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. * diff --git a/customerapi/controllers/UserController.php b/customerapi/controllers/UserController.php index 31a20ee..9ea0e2a 100644 --- a/customerapi/controllers/UserController.php +++ b/customerapi/controllers/UserController.php @@ -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( ), ''); diff --git a/customerapi/manager/EventRegistrationManager.php b/customerapi/manager/EventRegistrationManager.php new file mode 100644 index 0000000..65483df --- /dev/null +++ b/customerapi/manager/EventRegistrationManager.php @@ -0,0 +1,55 @@ +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()] + ]); + } + + +} diff --git a/customerapi/models/available/EventAvailable.php b/customerapi/models/available/EventAvailable.php index 69f3dda..ef0d2bf 100644 --- a/customerapi/models/available/EventAvailable.php +++ b/customerapi/models/available/EventAvailable.php @@ -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; }