add company-manager role
This commit is contained in:
74
common/models/CompanyManager.php
Normal file
74
common/models/CompanyManager.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
/**
|
||||
* This is the model class for table "company_manager".
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $company_id
|
||||
* @property int $user_card_id
|
||||
*
|
||||
* @property Company $company
|
||||
* @property UserCard $userCard
|
||||
*/
|
||||
class CompanyManager extends \yii\db\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'company_manager';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['company_id', 'user_card_id'], 'required'],
|
||||
[['company_id', 'user_card_id'], 'integer'],
|
||||
['user_card_id', 'unique', 'targetAttribute' => ['company_id', 'user_card_id'], 'message'=>'Этот менеджер уже закреплён за компанией'],
|
||||
[['company_id'], 'exist', 'skipOnError' => true, 'targetClass' => Company::className(), 'targetAttribute' => ['company_id' => 'id']],
|
||||
[['user_card_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::className(), 'targetAttribute' => ['user_card_id' => 'id']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'company_id' => 'Компания',
|
||||
'user_card_id' => 'Менеджер',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getCompany()
|
||||
{
|
||||
return $this->hasOne(Company::className(), ['id' => 'company_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getUserCard()
|
||||
{
|
||||
return $this->hasOne(UserCard::className(), ['id' => 'user_card_id']);
|
||||
}
|
||||
|
||||
public static function getManagersByCompany($company_id): array
|
||||
{
|
||||
return self::find()->where(['company_id' => $company_id])->all();
|
||||
}
|
||||
}
|
@ -21,9 +21,9 @@ use yii\db\Expression;
|
||||
*
|
||||
* @property Company $company
|
||||
* @property Company $contractorCompany
|
||||
* @property Manager $contractorManager
|
||||
* @property CompanyManager $contractorManager
|
||||
* @property DocumentTemplate $template
|
||||
* @property Manager $manager
|
||||
* @property CompanyManager $manager
|
||||
*/
|
||||
class Document extends \yii\db\ActiveRecord
|
||||
{
|
||||
@ -56,19 +56,19 @@ class Document extends \yii\db\ActiveRecord
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['company_id', 'contractor_company_id', 'manager_id', 'contractor_manager_id', 'title', 'template_id'], 'required'],
|
||||
[['title', 'template_id'], 'required'],
|
||||
[['company_id', 'contractor_company_id', 'manager_id', 'contractor_manager_id', 'template_id'], 'integer'],
|
||||
[['body'], 'string'],
|
||||
[['created_at', 'updated_at'], 'safe'],
|
||||
[['title'], 'string', 'max' => 255],
|
||||
[['company_id'], 'exist', 'skipOnError' => true, 'targetClass' => Company::className(), 'targetAttribute' => ['company_id' => 'id']],
|
||||
[['contractor_company_id'], 'exist', 'skipOnError' => true, 'targetClass' => Company::className(), 'targetAttribute' => ['contractor_company_id' => 'id']],
|
||||
[['contractor_manager_id'], 'exist', 'skipOnError' => true, 'targetClass' => Manager::className(), 'targetAttribute' => ['contractor_manager_id' => 'id']],
|
||||
[['contractor_manager_id'], 'exist', 'skipOnError' => true, 'targetClass' => CompanyManager::className(), 'targetAttribute' => ['contractor_manager_id' => 'id']],
|
||||
[['template_id'], 'exist', 'skipOnError' => true, 'targetClass' => DocumentTemplate::className(), 'targetAttribute' => ['template_id' => 'id']],
|
||||
[['manager_id'], 'exist', 'skipOnError' => true, 'targetClass' => Manager::className(), 'targetAttribute' => ['manager_id' => 'id']],
|
||||
[['manager_id'], 'exist', 'skipOnError' => true, 'targetClass' => CompanyManager::className(), 'targetAttribute' => ['manager_id' => 'id']],
|
||||
['body', 'required', 'on' => self::SCENARIO_UPDATE_DOCUMENT_BODY],
|
||||
['body', function ($attribute, $params) {
|
||||
preg_match_all('/(\${\w+|№|№+w})/', $this->$attribute,$out);
|
||||
preg_match_all('/\${(\w+|№|№+w)}/', $this->$attribute,$out);
|
||||
if (!empty($out[0])) {
|
||||
$this->addError('body', 'В теле документа все переменные должны быть заменены!');
|
||||
}
|
||||
@ -125,7 +125,7 @@ class Document extends \yii\db\ActiveRecord
|
||||
*/
|
||||
public function getContractorManager()
|
||||
{
|
||||
return $this->hasOne(Manager::className(), ['id' => 'contractor_manager_id']);
|
||||
return $this->hasOne(CompanyManager::className(), ['id' => 'contractor_manager_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -133,6 +133,6 @@ class Document extends \yii\db\ActiveRecord
|
||||
*/
|
||||
public function getManager()
|
||||
{
|
||||
return $this->hasOne(Manager::className(), ['id' => 'manager_id']);
|
||||
return $this->hasOne(CompanyManager::className(), ['id' => 'manager_id']);
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use developeruz\db_rbac\interfaces\UserRbacInterface;
|
||||
use Yii;
|
||||
use yii\behaviors\TimestampBehavior;
|
||||
use yii\db\ActiveRecord;
|
||||
@ -23,7 +24,7 @@ use yii\web\UnauthorizedHttpException;
|
||||
* @property $access_token_expired_at
|
||||
* @property string $password write-only password
|
||||
*/
|
||||
class User extends ActiveRecord implements IdentityInterface
|
||||
class User extends ActiveRecord implements IdentityInterface, UserRbacInterface
|
||||
{
|
||||
const STATUS_DELETED = 0;
|
||||
const STATUS_ACTIVE = 10;
|
||||
@ -76,6 +77,11 @@ class User extends ActiveRecord implements IdentityInterface
|
||||
return static::findOne(['id' => $id, 'status' => self::STATUS_ACTIVE]);
|
||||
}
|
||||
|
||||
public function getUserName()
|
||||
{
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
public function generateAccessToken()
|
||||
{
|
||||
$this->access_token = Yii::$app->security->generateRandomString();
|
||||
|
@ -63,7 +63,6 @@ class UserCard extends \yii\db\ActiveRecord
|
||||
const SCENARIO_UPDATE_RESUME_TEXT = 'update_resume_text';
|
||||
const SCENARIO_DOWNLOAD_RESUME = 'download_resume_text';
|
||||
|
||||
// public $resumeTemplateId;
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
@ -251,6 +250,14 @@ class UserCard extends \yii\db\ActiveRecord
|
||||
return $this->hasMany(ManagerEmployee::class, ['user_card_id' => 'id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getCompanyManagers()
|
||||
{
|
||||
return $this->hasMany(CompanyManager::className(), ['user_card_id' => 'id']);
|
||||
}
|
||||
|
||||
public static function generateUserForUserCard($card_id = null)
|
||||
{
|
||||
$userCardQuery = self::find();
|
||||
@ -327,4 +334,12 @@ class UserCard extends \yii\db\ActiveRecord
|
||||
return $userCard['id'];
|
||||
|
||||
}
|
||||
|
||||
public static function getCardByUserRole($role): array
|
||||
{
|
||||
$auth = Yii::$app->authManager;
|
||||
$usersId = $auth->getUserIdsByRole($role);
|
||||
|
||||
return UserCard::find()->where([ 'IN', 'id_user', $usersId])->all();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user