bug fixing
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user