add employee module

This commit is contained in:
iIronside
2021-11-16 13:14:28 +03:00
parent f7c8ab4de6
commit e561687b09
30 changed files with 4503 additions and 26 deletions

63
common/models/Manager.php Normal file
View File

@ -0,0 +1,63 @@
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "manager".
*
* @property int $id
* @property int $user_id
*
* @property User $user
* @property ManagerEmployee[] $managerEmployees
*/
class Manager extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'manager';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['user_id'], 'integer'],
[['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'user_id' => 'Менеджер',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getUser()
{
return $this->hasOne(User::className(), ['id' => 'user_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getManagerEmployees()
{
return $this->hasMany(ManagerEmployee::className(), ['manager_id' => 'id']);
}
}

View File

@ -0,0 +1,67 @@
<?php
namespace common\models;
use yii\db\ActiveQuery;
/**
* This is the model class for table "manager_employee".
*
* @property int $id
* @property int $manager_id
* @property int $employee_id
*
* @property User $user
* @property Manager $manager
*/
class ManagerEmployee extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'manager_employee';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['manager_id', 'employee_id'], 'required'],
[['manager_id', 'employee_id'], 'integer'],
[['employee_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['employee_id' => 'id']],
[['manager_id'], 'exist', 'skipOnError' => true, 'targetClass' => Manager::className(), 'targetAttribute' => ['manager_id' => 'id']],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'manager_id' => 'Менеджер',
'employee_id' => 'Работник',
];
}
/**
* @return ActiveQuery
*/
public function getUser()
{
return $this->hasOne(User::className(), ['id' => 'employee_id']);
}
/**
* @return ActiveQuery
*/
public function getManager()
{
return $this->hasOne(Manager::className(), ['id' => 'manager_id']);
}
}

View File

@ -57,6 +57,17 @@ class User extends ActiveRecord implements IdentityInterface
];
}
public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
if ($this->isNewRecord) {
$this->auth_key = Yii::$app->security->generateRandomString();
}
return true;
}
return false;
}
/**
* {@inheritdoc}
*/
@ -205,20 +216,13 @@ class User extends ActiveRecord implements IdentityInterface
$this->password_reset_token = null;
}
public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
if ($this->isNewRecord) {
$this->auth_key = Yii::$app->security->generateRandomString();
}
return true;
}
return false;
}
public function getUserCard()
{
return $this->hasOne(UserCard::class, ['id_user' => 'id']);
}
public function getManager()
{
return $this->hasOne(Manager::class, ['user_id' => 'id']);
}
}