bug fixing
This commit is contained in:
@@ -20,6 +20,7 @@ use yii\helpers\ArrayHelper;
|
||||
* @property integer $end
|
||||
* @property integer $id_room
|
||||
* @property integer $id_trainer
|
||||
* @property integer $id_user
|
||||
* @property integer $id_event_type
|
||||
* @property integer $seat_count
|
||||
* @property string $created_at
|
||||
@@ -40,6 +41,7 @@ class Event extends ActiveRecord
|
||||
public $timestampStart;
|
||||
public $timestampEnd;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
@@ -58,6 +60,7 @@ class Event extends ActiveRecord
|
||||
[['endDateString',], 'date', 'format' => Yii::$app->formatter->datetimeFormat, 'timestampAttribute' => 'end' , 'timeZone' => 'UTC'],
|
||||
[['id_trainer','id_room', 'id_event_type','seat_count'], 'required'],
|
||||
[['id_trainer','id_room', 'id_event_type','seat_count'], 'integer'],
|
||||
[['id_trainer','id_room', 'id_event_type','seat_count'], 'integer'],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -155,8 +158,6 @@ class Event extends ActiveRecord
|
||||
return $this->hasMany($this->getEquipmentTypeAssignmentsClass(),['id_event' => 'id']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return EventRegistration[]|ActiveQuery
|
||||
*/
|
||||
@@ -174,7 +175,9 @@ class Event extends ActiveRecord
|
||||
* @return integer
|
||||
*/
|
||||
public function getEventRegistrationCount(){
|
||||
return count($this->getActiveEventRegistrations()->all());
|
||||
$registrations = EventRegistration::find()->andWhere(['id_event' => $this->id])->all();
|
||||
$activeRegistrations = EventRegistration::filterActive($registrations);
|
||||
return count($activeRegistrations);
|
||||
}
|
||||
|
||||
protected function getEquipmentTypeAssignmentsClass()
|
||||
@@ -188,7 +191,9 @@ class Event extends ActiveRecord
|
||||
}
|
||||
|
||||
public function hasFreeSeats(){
|
||||
$registrationCount = count($this->eventRegistrations) ;
|
||||
$registrations = EventRegistration::find()->andWhere(['id_event' => $this->id])->all();
|
||||
$activeRegistrations = EventRegistration::filterActive($registrations);
|
||||
$registrationCount = count($activeRegistrations) ;
|
||||
|
||||
$seatCount = $this->seat_count;
|
||||
if ( !isset($seatCount ) || $seatCount === 0){
|
||||
|
||||
@@ -174,6 +174,8 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
|
||||
'payment_method' => Yii::t('common/transfer', 'Fizetési mód'),
|
||||
'original_price' => Yii::t('common/transfer', 'Eredeti ár'),
|
||||
'original_end' => Yii::t('common/transfer', 'Eredeti érvényesség vége'),
|
||||
'max_reservation_count' => Yii::t('common/transfer', 'Max foglalások száma'),
|
||||
'reservation_count' => Yii::t('common/transfer', 'Foglalások száma'),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -467,6 +469,10 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
|
||||
if ( $this->reservation_count < 0 ){
|
||||
$this->reservation_count = 0;
|
||||
}
|
||||
|
||||
if ( $this->reservation_count > $this->max_reservation_count ){
|
||||
$this->reservation_count = $this->max_reservation_count;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use common\components\RoleDefinition;
|
||||
use common\helpers\AppArrayHelper;
|
||||
use Yii;
|
||||
use yii\behaviors\TimestampBehavior;
|
||||
@@ -80,8 +81,18 @@ class Trainer extends \yii\db\ActiveRecord
|
||||
return \Yii::t("trainer",'active_off');
|
||||
}
|
||||
|
||||
public static function trainerOptions($all = false, $emptyString = false){
|
||||
$items = ArrayHelper::map(Trainer::find()->all(),'id','name');
|
||||
public function getUserTrainerAssignments()
|
||||
{
|
||||
return $this->hasMany(UserTrainerAssignment::class, ['id_trainer' => 'id']);
|
||||
}
|
||||
|
||||
|
||||
public static function trainerOptions($all = false, $emptyString = false, $trainers = null){
|
||||
|
||||
if ( !isset($trainers)){
|
||||
$trainers = Trainer::find()->all();
|
||||
}
|
||||
$items = ArrayHelper::map($trainers,'id','name');
|
||||
$extra = [];
|
||||
if ( $all ) {
|
||||
$extra = ['' => \Yii::t('trainer','All')];
|
||||
@@ -92,4 +103,27 @@ class Trainer extends \yii\db\ActiveRecord
|
||||
return ArrayHelper::merge($extra,$items);
|
||||
}
|
||||
|
||||
public static function getTrainersAllowed($idUser){
|
||||
$query = Trainer::find();
|
||||
if (RoleDefinition::isAdmin() == false) {
|
||||
$query = $query->innerJoinWith('userTrainerAssignments')
|
||||
->andWhere(
|
||||
[
|
||||
'user_trainer_assignment.id_user' => $idUser
|
||||
]
|
||||
);
|
||||
}
|
||||
return $query->all();
|
||||
}
|
||||
|
||||
public static function isTrainerAllowed($trainers,$idUser,$idTrainer){
|
||||
$trainerAllowed = false;
|
||||
foreach ($trainers as $trainer){
|
||||
if ( $trainer->id == $idTrainer){
|
||||
$trainerAllowed = true;
|
||||
}
|
||||
}
|
||||
return $trainerAllowed;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
45
common/models/UserTrainerAssignment.php
Normal file
45
common/models/UserTrainerAssignment.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* This is the model class for table "user_trainer_assignment".
|
||||
*
|
||||
* @property integer $id_user_trainer_assignment
|
||||
* @property integer $id_user
|
||||
* @property integer $id_trainer
|
||||
*/
|
||||
class UserTrainerAssignment extends \yii\db\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'user_trainer_assignment';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id_user', 'id_trainer'], 'integer']
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id_user_trainer_assignment' => Yii::t('common/user-trainer-assignment', 'Id User Trainer Assignment'),
|
||||
'id_user' => Yii::t('common/user-trainer-assignment', 'Id User'),
|
||||
'id_trainer' => Yii::t('common/user-trainer-assignment', 'Id Trainer'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user