assign trainers to user; add email to jwt token

This commit is contained in:
Roland Schneider
2021-10-04 18:13:32 +02:00
parent 439fb12b6e
commit 7a55ca9ff3
21 changed files with 671 additions and 350 deletions

View File

@@ -26,7 +26,7 @@ class User extends ActiveRecord implements IdentityInterface
{
const STATUS_DELETED = 0;
const STATUS_ACTIVE = 10;
const ROLE_RECEPTION = 'receptionist';
/**
@@ -192,18 +192,22 @@ class User extends ActiveRecord implements IdentityInterface
{
$this->password_reset_token = null;
}
public function getUserAccountAssignments(){
return $this->hasMany(UserAccountAssignment::className(), ['id_user' =>'id']);
}
public function getUserTrainerAssignments(){
return $this->hasMany(UserTrainerAssignment::className(), ['id_user' =>'id']);
}
static function statuses() {
return [
self::STATUS_ACTIVE => Yii::t('app', 'Aktív'),
self::STATUS_DELETED => Yii::t('app', 'Inaktív'),
] ;
}
public function getStatusHuman(){
$result = null;
$s = self::statuses($this->status);
@@ -212,8 +216,8 @@ class User extends ActiveRecord implements IdentityInterface
}
return $result;
}
public function attributeLabels(){
return [
'status' => 'Státusz',
@@ -224,14 +228,14 @@ class User extends ActiveRecord implements IdentityInterface
'statusHuman' => Yii::t('backend/user', 'Status'),
];
}
/**
*
*
*
*
* @return \yii\rbac\Role[]*/
public function getRoles(){
$roles = \Yii::$app->authManager->getRolesByUser($this->id );
return $roles;
return $roles;
}
/**
@@ -239,28 +243,28 @@ class User extends ActiveRecord implements IdentityInterface
* */
public function getRoleString(){
$roles = \Yii::$app->authManager->getRolesByUser($this->id );
return implode(', ', array_map(function ($role) { return sprintf("%s", RoleDefinition::getRoleLabel($role->name)); }, $roles ));
}
/**
* $param int $forceIncludeAccount id warehouse, that should be included in list, even if it is inactive
* */
public static function read($forceIncludeObjectWithId = null){
$users = null;
$query = User::find();
if ( RoleDefinition::isReception()){
$query->andWhere(['id' => Yii::$app->user->id ]);
}
if ( $forceIncludeObjectWithId == null){
$users = $query->andWhere(['status' => User::STATUS_ACTIVE])->all();
}else{
$users = $query->andWhere( ['or', ['status' => User::STATUS_ACTIVE], ['id' => $forceIncludeObjectWithId ] ])->all();
}
return $users;
}
}