From f98dcb656f2dc2bd4a80257ce5865fd53b8a747d Mon Sep 17 00:00:00 2001 From: Roland Schneider Date: Sat, 2 Oct 2021 22:21:14 +0200 Subject: [PATCH] improve customer api & gui --- backend/views/event-type/_form.php | 1 + backend/views/event-type/index.php | 8 +- backend/views/event-type/view.php | 4 + common/components/Helper.php | 198 +++++++++--------- common/config/params.php | 3 +- common/helpers/AppArrayHelper.php | 40 ++++ common/helpers/AppDateTimeHelper.php | 16 ++ common/mail/customer_password_change.php | 45 ++-- common/models/Event.php | 16 +- common/models/EventRegistration.php | 59 ++++-- common/models/EventType.php | 14 +- common/models/Trainer.php | 1 + common/modules/event/manager/EventManager.php | 70 +++++-- ...alter_table_event_type_add_field_color.php | 42 ++++ customer/app/src/app/_helpers/fake-backend.ts | 6 +- customer/app/src/app/app.module.ts | 2 + customer/app/src/app/app.service.ts | 26 +++ .../fit-event-types.component.ts | 6 +- .../fit-navigation.component.html | 3 +- .../fit-navigation.component.ts | 2 +- .../month-calendar-event.component.html | 14 +- .../month-calendar-event.component.ts | 34 ++- .../event-details.component.html | 4 +- .../event-details/event-details.component.ts | 7 +- .../registration/registration.component.html | 12 ++ .../registrations.component.html | 30 ++- .../registrations/registrations.component.ts | 10 +- customer/app/src/app/pipes/event-time.pipe.ts | 19 ++ .../app/src/app/services/event.service.ts | 1 + .../src/app/services/reservation.service.ts | 8 +- customer/app/src/styles.scss | 5 + customer/app/src/styles/event.themes.scss | 52 +++++ customerapi/controllers/EventController.php | 68 +++--- .../EventRegistrationController.php | 4 +- .../manager/EventRegistrationManager.php | 73 ++++--- .../models/available/EventAvailable.php | 68 +++--- .../models/available/EventTypeAvailable.php | 3 +- customerapi/models/dto/EventDTO.php | 70 +++++++ .../models/dto/EventRegistrationDTO.php | 63 ++++++ customerapi/models/dto/EventTypeDTO.php | 23 ++ customerapi/models/dto/RoomDTO.php | 27 +++ customerapi/models/dto/TrainerDTO.php | 32 +++ frontend/controllers/CustomerController.php | 1 + frontend/models/PasswordChangeModel.php | 1 + 44 files changed, 893 insertions(+), 298 deletions(-) create mode 100644 common/helpers/AppArrayHelper.php create mode 100644 common/helpers/AppDateTimeHelper.php create mode 100644 console/migrations/m210930_101018_alter_table_event_type_add_field_color.php create mode 100644 customer/app/src/app/app.service.ts create mode 100644 customer/app/src/app/pipes/event-time.pipe.ts create mode 100644 customer/app/src/styles/event.themes.scss create mode 100644 customerapi/models/dto/EventDTO.php create mode 100644 customerapi/models/dto/EventRegistrationDTO.php create mode 100644 customerapi/models/dto/EventTypeDTO.php create mode 100644 customerapi/models/dto/RoomDTO.php create mode 100644 customerapi/models/dto/TrainerDTO.php diff --git a/backend/views/event-type/_form.php b/backend/views/event-type/_form.php index 02abc8a..8b4c9e6 100644 --- a/backend/views/event-type/_form.php +++ b/backend/views/event-type/_form.php @@ -13,6 +13,7 @@ use yii\widgets\ActiveForm; field($model, 'name')->textInput(['maxlength' => true]) ?> + field($model, 'theme')->dropDownList(\common\models\EventType::themes()) ?>
isNewRecord ? Yii::t('event-type', 'Create') : Yii::t('event-type', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> diff --git a/backend/views/event-type/index.php b/backend/views/event-type/index.php index 3163e74..ef18f81 100644 --- a/backend/views/event-type/index.php +++ b/backend/views/event-type/index.php @@ -26,7 +26,13 @@ $this->params['breadcrumbs'][] = $this->title; 'name', 'created_at:datetime', 'updated_at:datetime', - + [ + 'attribute' => 'theme', + 'label' => 'Színtéma', + 'value' => function ($model, $key, $index, $column){ + return isset($model['theme']) ? "Színtéma " . ($model['theme']+1) : ""; + } + ], ['class' => 'yii\grid\ActionColumn', 'template' => '{view} {update}' ], diff --git a/backend/views/event-type/view.php b/backend/views/event-type/view.php index 1a6a8cd..1ea0c5d 100644 --- a/backend/views/event-type/view.php +++ b/backend/views/event-type/view.php @@ -30,6 +30,10 @@ $this->params['breadcrumbs'][] = $this->title; 'attributes' => [ 'id', 'name', + [ + 'label'=> 'Színtéma', + 'value' => ( isset($model->theme) ? 'Színtéma ' . ($model->theme+1) : '-' ) + ], 'created_at', 'updated_at', ], diff --git a/common/components/Helper.php b/common/components/Helper.php index 74939f5..fee3699 100644 --- a/common/components/Helper.php +++ b/common/components/Helper.php @@ -22,7 +22,7 @@ class Helper { */ public static function calcStartDatimeDaysSinceToday($start, $format = "datetime" ){ $now = time(); - + if ( $format == "datetime"){ $format = "Y-m-d H:i"; }else if ( $format == "date") { @@ -30,10 +30,10 @@ class Helper { }else{ //use format } - + $d = \DateTime::createFromFormat( $format , $start)->getTimeStamp(); $days_between = ceil(abs( $now - $d) / 86400 ); - + return $days_between; } @@ -52,8 +52,8 @@ class Helper { */ public static function restrictIfNotAdminTheStartDate($query,$date, $fields = ['transfer.paid_at','transfer.created_at'], $format = 'datetime'){ $result = null; - - + + $needFix = false; if ( !isset($date) || empty($date)){ $needFix = true; @@ -63,19 +63,19 @@ class Helper { $needFix = true; } } - + if ( $needFix == true ){ $d = Helper::getReceptionVisibilityDays(); - + $time = date( "Y-m-d H:i:s", strtotime("today -$d day") ); - + $conditions = []; - + foreach ($fields as $f ){ $conditions[] = ['>=', $f, $time]; } - - + + if ( count($conditions) > 1 ){ $andWhereCond = []; $andWhereCond[0] = "or"; @@ -87,26 +87,26 @@ class Helper { }else if ( count($conditions) == 1 ){ $andWhereCond = $conditions[0]; } - + // $start_date_condition = ['or',[ '>=', 'transfer.created_at', $time ] ,[ '>=', 'transfer.paid_at', $time] ]; - if ( isset($andWhereCond)){ + if ( isset($andWhereCond)){ $query->andWhere( $andWhereCond ); } - + } - + return $result; } - + public static function getDateTimeString( ){ - + return date("Y-m-d H:i:s"); } public static function getDateString( ){ - + return date("Y-m-d"); } - + public static function getArrayValue($arr,$key,$def){ $result = $def; if ( array_key_exists($key, $arr)){ @@ -114,8 +114,8 @@ class Helper { } return $result; } - - + + public static function hufRound($m) { $result = round ( $m / 5, 0 ) * 5; return $result; @@ -128,18 +128,18 @@ class Helper { * @param $end */ public static function notInInterval($query, $field, $start, $end) { - $query->andFilterWhere ( [ + $query->andFilterWhere ( [ 'or', - [ + [ '<', $field, - isset ( $start ) ? $start : '1900-01-01' + isset ( $start ) ? $start : '1900-01-01' ], - [ + [ '>=', $field, - isset ( $end ) ? $end : '3000-01-01' - ] + isset ( $end ) ? $end : '3000-01-01' + ] ] ); } @@ -150,21 +150,21 @@ class Helper { * @param string $end the end date */ public static function notPaid($query, $field, $start, $end) { - $query->andFilterWhere ( [ + $query->andFilterWhere ( [ 'or', - [ + [ '<', $field, - isset ( $start ) ? $start : '1900-01-01' + isset ( $start ) ? $start : '1900-01-01' ], - [ + [ '>=', $field, - isset ( $end ) ? $end : '3000-01-01' + isset ( $end ) ? $end : '3000-01-01' ], - [ - "transfer.status" => Transfer::STATUS_NOT_PAID - ] + [ + "transfer.status" => Transfer::STATUS_NOT_PAID + ] ] ); } @@ -175,15 +175,15 @@ class Helper { * @param string $end the end date */ public static function inInterval($query, $field, $start, $end) { - $query->andFilterWhere ( [ + $query->andFilterWhere ( [ '>=', $field, - $start + $start ] ); - $query->andFilterWhere ( [ + $query->andFilterWhere ( [ '<', $field, - $end + $end ] ); } @@ -194,53 +194,53 @@ class Helper { * @return array the query 'in interval' rule */ public static function queryInIntervalRule($field, $start, $end) { - return [ + return [ 'and', - [ + [ '>=', $field, - $start + $start ], - [ + [ '<', $field, - $end - ] + $end + ] ]; } public static function queryExpireRule($field_start, $field_end, $start, $end) { - return [ + return [ 'and', - [ + [ '<', $field_start, - $end + $end ], - [ + [ '>=', $field_end, - $start + $start ], - [ + [ '<=', $field_end, - $end - ] + $end + ] ]; } public static function queryValidRule($field_start, $field_end, $start, $end) { - return [ + return [ 'and', - [ + [ '<', $field_start, - $end + $end ], - [ + [ '>=', $field_end, - $start - ] + $start + ] ]; } public static function sqlInIntervalRule($field, $paramStart, $paramEnd) { @@ -270,35 +270,35 @@ class Helper { public static function queryAccountConstraint($query, $field) { if (! RoleDefinition::isAdmin ()) { $query->innerJoin ( "user_account_assignment", $field . ' = user_account_assignment.id_account' ); - $query->andWhere ( [ - 'user_account_assignment.id_user' => Yii::$app->user->id + $query->andWhere ( [ + 'user_account_assignment.id_user' => Yii::$app->user->id ] ); } } public static function roleLabels() { - return [ + return [ 'reception' => Yii::t ( 'common/role', 'Reception' ), 'admin' => Yii::t ( 'common/role', 'Administrator' ), - 'employee' => Yii::t ( 'common/role', 'Alkalmazott' ) + 'employee' => Yii::t ( 'common/role', 'Alkalmazott' ) ]; } public static function roleDefinitions() { - return [ - 'employee' => [ - 'canAllow' => [ - 'employee' - ] + return [ + 'employee' => [ + 'canAllow' => [ + 'employee' + ] ], - 'admin' => [ - 'canAllow' => [ + 'admin' => [ + 'canAllow' => [ 'admin', 'reception', - 'employee' - ] + 'employee' + ] ], - 'reception' => [ - 'canAllow' => [ ] - ] + 'reception' => [ + 'canAllow' => [ ] + ] ]; } public static function flash($mode, $message) { @@ -322,26 +322,26 @@ class Helper { public static function isUserCartVisibilityAll() { return \Yii::$app->params ['user_cart_item_visibility'] == 'all'; } - + public static function getBackendSkin() { return \Yii::$app->params ['backend_skin'] ; } - + public static function getCompany() { return \Yii::$app->params ['company'] ; } public static function getCompanyName() { return \Yii::$app->params ['company_name'] ; } - + public static function isCompanyMovar() { return \Yii::$app->params ['company'] == 'movar'; } - + public static function isCompanyGyor() { return \Yii::$app->params ['company'] == 'gyor'; } - + public static function isUserCartOn() { return \Yii::$app->params ['user_cart_on'] == true; } @@ -353,26 +353,26 @@ class Helper { public static function isTicketTypeDoorAllowedCheckOn() { return \Yii::$app->params ['ticket_type_door_allowed_check_on'] == true; } - + public static function getProductSaleDefaultFocus() { return \Yii::$app->params ['product_sale_default_focus'] ; } public static function isProductVisibilityAccount() { return \Yii::$app->params ['product_visiblity'] == 'account'; } - + public static function isAccountStateClosePreloadMoney() { return \Yii::$app->params ['account_state_close_preload_money'] == true; } - + public static function isAccountStateOpenSendMail() { return \Yii::$app->params ['mail_account_state_open'] == true; } - + public static function isAccountStateCloseSendMail() { return \Yii::$app->params ['mail_account_state_close'] == true; } - + public static function getReceptionVisibilityDays() { return \Yii::$app->params ['reception_visibility_days'] ; } @@ -399,12 +399,16 @@ class Helper { public static function isReceptionTransferIndexEnabled(){ return !Helper::isReceptionTransferListToday(); } - + + public static function getGroupTrainingUrl(){ + return \Yii::$app->params['group_training.url']; + } + public static function getRealUserIp() { $client = @$_SERVER ['HTTP_CLIENT_IP']; $forward = @$_SERVER ['HTTP_X_FORWARDED_FOR']; $remote = $_SERVER ['REMOTE_ADDR']; - + if (filter_var ( $client, FILTER_VALIDATE_IP )) { $ip = $client; } elseif (filter_var ( $forward, FILTER_VALIDATE_IP )) { @@ -412,10 +416,10 @@ class Helper { } else { $ip = $remote; } - + return $ip; } - + public static function url_get_contents ($Url) { if (!function_exists('curl_init')){ die('CURL is not installed!'); @@ -427,14 +431,14 @@ class Helper { curl_close($ch); return $output; } - + public static function getGeoIp() { $ip = Helper::getRealUserIp (); $details = json_decode ( Helper::url_get_contents( "http://ipinfo.io/{$ip}/json" ) ); return $details; } - - + + public static function mkYiiSortItem($field, $column){ return [ $field => [ @@ -454,7 +458,7 @@ class Helper { } return $result; } - + public static function setBit($val,$index,$bit_on){ $flag = +$val; if ( $bit_on ){ @@ -471,7 +475,7 @@ class Helper { return $result ; } - + public static function generateRandomString($length = 6,$characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWX' ) { $charactersLength = strlen($characters); $randomString = ''; @@ -480,7 +484,7 @@ class Helper { } return $randomString; } - + public static function getWebUrl(){ if ( \Yii::$app->params['development'] == true ){ return "http://localhost/fitness-web"; @@ -529,5 +533,5 @@ class Helper { return $result; } - -} \ No newline at end of file + +} diff --git a/common/config/params.php b/common/config/params.php index ccdbe50..ca98fd8 100644 --- a/common/config/params.php +++ b/common/config/params.php @@ -64,5 +64,6 @@ return [ 'ticket_type_door_allowed_check_on' => false, 'warn_ticket_expire_in_days_count' => 3, 'warn_ticket_expire_in_usage_count' => 3, - 'inventory.products.only.active' => true + 'inventory.products.only.active' => true, + 'group_training.url' => 'https://fitnessadmin.hu' ]; diff --git a/common/helpers/AppArrayHelper.php b/common/helpers/AppArrayHelper.php new file mode 100644 index 0000000..7dc2598 --- /dev/null +++ b/common/helpers/AppArrayHelper.php @@ -0,0 +1,40 @@ + [obj1.id => obj1,obj2.id => obj2] + * @param $array + * @return array + */ + public static function objectArrayToMapById($array){ + return AppArrayHelper::objectArrayToMap( + $array, + function ($item){ + return $item->id; + }, + function ($item){ + return $item; + } + ); + } + +} diff --git a/common/helpers/AppDateTimeHelper.php b/common/helpers/AppDateTimeHelper.php new file mode 100644 index 0000000..f0233fd --- /dev/null +++ b/common/helpers/AppDateTimeHelper.php @@ -0,0 +1,16 @@ + -

Kedves customer->name?>!

-

- Az Ön új jelszava: -

- -

- Üdvözlettel: -

-

- companyName ?> -

-

- Ez egy automatikus e-mail üzenet, amelyre nem tud válaszolni. -

+
Kedves customer->name ?>!
+

+ Az Ön új jelszava: +

+

+ plainPassword ?> +

+

A bejelentkezéshez kattintson a következő linkre: groupTrainingUrl ?>

+

+ Üdvözlettel: +

+

+ companyName ?> +

+

+ Ez egy automatikus e-mail üzenet, amelyre nem tud válaszolni. +

diff --git a/common/models/Event.php b/common/models/Event.php index 63db6eb..82059d0 100644 --- a/common/models/Event.php +++ b/common/models/Event.php @@ -161,7 +161,8 @@ class Event extends ActiveRecord * @return EventRegistration[]|ActiveQuery */ public function getActiveEventRegistrations(){ - return $this->hasMany(EventRegistration::class,['id_event' => 'id'])->andWhere( + return $this->hasMany(EventRegistration::class,['id_event' => 'id']) + ->andWhere( [ 'event_registration.canceled_at' => null, 'event_registration.deleted_at' => null, @@ -169,19 +170,6 @@ 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 */ diff --git a/common/models/EventRegistration.php b/common/models/EventRegistration.php index 8a4f2b8..468afd2 100644 --- a/common/models/EventRegistration.php +++ b/common/models/EventRegistration.php @@ -57,45 +57,52 @@ class EventRegistration extends \yii\db\ActiveRecord public function behaviors() { - return ArrayHelper::merge( [ + return ArrayHelper::merge([ [ 'class' => TimestampBehavior::className(), - 'value' => function(){ return date('Y-m-d H:i:s' ); } + 'value' => function () { + return date('Y-m-d H:i:s'); + } ] ], parent::behaviors()); } - public function getEvent(){ - return $this->hasOne($this->getEventClass(),['id' => 'id_event']); + public function getEvent() + { + return $this->hasOne($this->getEventClass(), ['id' => 'id_event']); } - public function getCustomer(){ - return $this->hasOne($this->getCustomerClass(),['id' => 'id_customer']); + public function getCustomer() + { + return $this->hasOne($this->getCustomerClass(), ['id' => 'id_customer']); } - public function getEventClass(){ + public function getEventClass() + { return Event::class; } - public function getCustomerClass(){ + public function getCustomerClass() + { return Customer::class; } /** * @param EventRegistration $eventRegistration */ - public static function isActive($eventRegistration){ - if ( !isset($eventRegistration ) ){ + public static function isActive($eventRegistration) + { + if (!isset($eventRegistration)) { return false; } - if ( isset($eventRegistration->canceled_at ) ){ + if (isset($eventRegistration->canceled_at)) { return false; } - if ( isset($eventRegistration->deleted_at ) ){ + if (isset($eventRegistration->deleted_at)) { return false; } @@ -105,32 +112,40 @@ class EventRegistration extends \yii\db\ActiveRecord /** * @param EventRegistration $eventRegistration */ - public static function isForCustomer($eventRegistration,$idCustomer){ - if ( !isset($eventRegistration ) ){ + public static function isForCustomer($eventRegistration, $idCustomer) + { + if (!isset($eventRegistration)) { return false; } - if ( !isset($eventRegistration->id_customer ) ){ + if (!isset($eventRegistration->id_customer)) { return false; } - return $eventRegistration->id_customer == $idCustomer; + return $eventRegistration->id_customer == $idCustomer; } /** * @param EventRegistration[] $eventRegistrations */ - public static function filterActive($eventRegistrations){ - return array_filter($eventRegistrations, EventRegistration::class.'::isActive' ); + public static function filterActive($eventRegistrations) + { + if (!isset($eventRegistrations)) { + return []; + } + return array_filter($eventRegistrations, EventRegistration::class . '::isActive'); } /** * @param EventRegistration[] $eventRegistrations */ - public static function filterForCustomer($eventRegistrations,$idCustomer){ + public static function filterForCustomer($eventRegistrations, $idCustomer) + { $result = []; - foreach ($eventRegistrations as $eventRegistration){ - if ( EventRegistration::isForCustomer($eventRegistration,$idCustomer)){ - $result[] = $eventRegistration; + if (isset($eventRegistrations)) { + foreach ($eventRegistrations as $eventRegistration) { + if (EventRegistration::isForCustomer($eventRegistration, $idCustomer)) { + $result[] = $eventRegistration; + } } } return $result; diff --git a/common/models/EventType.php b/common/models/EventType.php index 07f2717..fd440a1 100644 --- a/common/models/EventType.php +++ b/common/models/EventType.php @@ -11,6 +11,7 @@ use yii\helpers\ArrayHelper; * * @property integer $id * @property string $name + * @property string $theme * @property string $created_at * @property string $updated_at */ @@ -30,9 +31,10 @@ class EventType extends \yii\db\ActiveRecord public function rules() { return [ - [['name'], 'required'], + [['name','theme'], 'required'], [['name'], 'unique'], - [['name'], 'string', 'max' => 255] + [['name'], 'string', 'max' => 255], + [['theme'], 'string', 'max' => 50] ]; } @@ -104,4 +106,12 @@ class EventType extends \yii\db\ActiveRecord // TODO: implement bossiness logic to select ticket return $possibleTickets[0]; } + + static function themes() { + $themes = []; + for ($x = 0; $x < 10; $x++) { + $themes[$x] = "Színtéma " . ($x+1); + } + return $themes; + } } diff --git a/common/models/Trainer.php b/common/models/Trainer.php index 18ec78d..da43ec1 100644 --- a/common/models/Trainer.php +++ b/common/models/Trainer.php @@ -2,6 +2,7 @@ namespace common\models; +use common\helpers\AppArrayHelper; use Yii; use yii\behaviors\TimestampBehavior; use yii\helpers\ArrayHelper; diff --git a/common/modules/event/manager/EventManager.php b/common/modules/event/manager/EventManager.php index 38ed3b6..e9253ff 100644 --- a/common/modules/event/manager/EventManager.php +++ b/common/modules/event/manager/EventManager.php @@ -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(); + } } diff --git a/console/migrations/m210930_101018_alter_table_event_type_add_field_color.php b/console/migrations/m210930_101018_alter_table_event_type_add_field_color.php new file mode 100644 index 0000000..fe83dda --- /dev/null +++ b/console/migrations/m210930_101018_alter_table_event_type_add_field_color.php @@ -0,0 +1,42 @@ +addColumn("event_type",'theme',$this->string(50)); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + echo "m210930_101018_alter_table_event_type_add_field_color cannot be reverted.\n"; + + return false; + } + + /* + // Use up()/down() to run migration code without a transaction. + public function up() + { + + } + + public function down() + { + echo "m210930_101018_alter_table_event_type_add_field_color cannot be reverted.\n"; + + return false; + } + */ +} diff --git a/customer/app/src/app/_helpers/fake-backend.ts b/customer/app/src/app/_helpers/fake-backend.ts index 7b8a54b..aa93a9c 100644 --- a/customer/app/src/app/_helpers/fake-backend.ts +++ b/customer/app/src/app/_helpers/fake-backend.ts @@ -47,11 +47,13 @@ export class FakeBackendInterceptor implements HttpInterceptor { let eventTypes: EventType[] = [ { id: 1, - name: 'Típus 1' + name: 'Típus 1', + theme: '0' }, { id: 2, - name: 'Típus 2' + name: 'Típus 2', + theme: '0' } ]; diff --git a/customer/app/src/app/app.module.ts b/customer/app/src/app/app.module.ts index fe301ba..9fbc8dc 100644 --- a/customer/app/src/app/app.module.ts +++ b/customer/app/src/app/app.module.ts @@ -39,6 +39,7 @@ import {environment} from "../environments/environment"; import {AppState} from "./state/app.state"; import {NgxsReduxDevtoolsPluginModule} from "@ngxs/devtools-plugin"; import {NgxsLoggerPluginModule} from "@ngxs/logger-plugin"; +import { EventDatePipe } from './pipes/event-time.pipe'; @@ -66,6 +67,7 @@ registerLocaleData(localeHu, 'hu'); GuestLayoutComponent, SecuredLayoutComponent, PasswordChangeComponent, + EventDatePipe, ], imports: [ diff --git a/customer/app/src/app/app.service.ts b/customer/app/src/app/app.service.ts new file mode 100644 index 0000000..cf35947 --- /dev/null +++ b/customer/app/src/app/app.service.ts @@ -0,0 +1,26 @@ +import { Injectable } from '@angular/core'; +import * as moment from "moment"; + +@Injectable({ + providedIn: 'root' +}) +export class AppService { + + constructor() { } + + formatDateTime(datetime: number, date:boolean, time: boolean) { + let format ; + if ( date && time ){ + format = 'YYYY.MM.DD HH:mm'; + } else if (date){ + format = 'YYYY.MM.DD'; + } else { + format = 'HH:mm'; + } + return this.dateToMoment(datetime).utc().format(format); + } + + dateToMoment(date: number) { + return moment.unix(date); + } +} diff --git a/customer/app/src/app/components/fit-event-types/fit-event-types.component.ts b/customer/app/src/app/components/fit-event-types/fit-event-types.component.ts index f767788..8c957ab 100644 --- a/customer/app/src/app/components/fit-event-types/fit-event-types.component.ts +++ b/customer/app/src/app/components/fit-event-types/fit-event-types.component.ts @@ -1,6 +1,6 @@ import {Component, forwardRef, OnInit} from '@angular/core'; import {EventService, EventType} from "../../services/event.service"; -import {ControlValueAccessor, FormControl, FormGroup, NG_VALUE_ACCESSOR} from "@angular/forms"; +import {ControlValueAccessor, NG_VALUE_ACCESSOR} from "@angular/forms"; const FIT_EVENT_TYPES_VALUE_ACCESSOR: any = { provide: NG_VALUE_ACCESSOR, @@ -22,10 +22,8 @@ export class FitEventTypesComponent implements OnInit, ControlValueAccessor { private onChange: Function; private onTouched: Function; - public value: string; - constructor(private eventService: EventService) { this.onChange = (_: any) => { }; this.onTouched = () => { }; @@ -34,7 +32,7 @@ export class FitEventTypesComponent implements OnInit, ControlValueAccessor { ngOnInit() { this.eventService.findAllEventTypes() .subscribe(value => { - this.types = [{ id: -1, name: 'Minden Típus'}].concat( value); + this.types = [{ id: -1, name: 'Minden Típus', theme: '' }].concat( value); this._setValue(this.types[0].id); } ); diff --git a/customer/app/src/app/components/fit-navigation/fit-navigation.component.html b/customer/app/src/app/components/fit-navigation/fit-navigation.component.html index 8b54512..213aa7f 100644 --- a/customer/app/src/app/components/fit-navigation/fit-navigation.component.html +++ b/customer/app/src/app/components/fit-navigation/fit-navigation.component.html @@ -6,7 +6,8 @@ -