2021-11-16 13:14:28 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace common\models;
|
|
|
|
|
|
|
|
use Yii;
|
2021-11-22 15:34:46 +03:00
|
|
|
use yii\db\ActiveQuery;
|
2022-01-14 10:09:02 +03:00
|
|
|
use yii\db\StaleObjectException;
|
2021-11-16 13:14:28 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This is the model class for table "manager".
|
|
|
|
*
|
|
|
|
* @property int $id
|
2021-12-23 11:28:27 +03:00
|
|
|
* @property int $user_card_id
|
2021-11-16 13:14:28 +03:00
|
|
|
*
|
2021-12-23 11:28:27 +03:00
|
|
|
* @property UserCard $userCard
|
2021-11-16 13:14:28 +03:00
|
|
|
* @property ManagerEmployee[] $managerEmployees
|
|
|
|
*/
|
|
|
|
class Manager extends \yii\db\ActiveRecord
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public static function tableName()
|
|
|
|
{
|
|
|
|
return 'manager';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function rules()
|
|
|
|
{
|
|
|
|
return [
|
2021-12-23 11:28:27 +03:00
|
|
|
[['user_card_id'], 'integer'],
|
|
|
|
[['user_card_id'], 'required'],
|
|
|
|
['user_card_id', 'unique', 'message'=>'Уже является менеджером'],
|
|
|
|
[['user_card_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::className(), 'targetAttribute' => ['user_card_id' => 'id']],
|
2021-11-16 13:14:28 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function attributeLabels()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'id' => 'ID',
|
2021-12-23 11:28:27 +03:00
|
|
|
'user_card_id' => 'Карточка менеджера',
|
2021-11-16 13:14:28 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-01-14 10:09:02 +03:00
|
|
|
/**
|
|
|
|
* @throws StaleObjectException
|
|
|
|
* @throws \Throwable
|
|
|
|
*/
|
2021-11-22 15:34:46 +03:00
|
|
|
public function beforeDelete()
|
|
|
|
{
|
|
|
|
foreach ($this->managerEmployees as $employee){
|
|
|
|
$employee->delete();
|
|
|
|
}
|
|
|
|
return parent::beforeDelete();
|
|
|
|
}
|
|
|
|
|
2021-11-16 13:14:28 +03:00
|
|
|
/**
|
2021-11-22 15:34:46 +03:00
|
|
|
* @return ActiveQuery
|
2021-11-16 13:14:28 +03:00
|
|
|
*/
|
2021-12-23 11:28:27 +03:00
|
|
|
public function getUserCard()
|
2021-11-16 13:14:28 +03:00
|
|
|
{
|
2021-12-23 11:28:27 +03:00
|
|
|
return $this->hasOne(UserCard::className(), ['id' => 'user_card_id']);
|
2021-11-16 13:14:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-22 15:34:46 +03:00
|
|
|
* @return ActiveQuery
|
2021-11-16 13:14:28 +03:00
|
|
|
*/
|
|
|
|
public function getManagerEmployees()
|
|
|
|
{
|
|
|
|
return $this->hasMany(ManagerEmployee::className(), ['manager_id' => 'id']);
|
|
|
|
}
|
|
|
|
}
|