2018-10-11 11:15:09 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace common\models;
|
|
|
|
|
2019-07-16 11:58:05 +03:00
|
|
|
use common\classes\Debug;
|
2021-12-16 17:14:33 +03:00
|
|
|
use Exception;
|
|
|
|
use phpDocumentor\Reflection\Types\This;
|
2018-10-11 11:15:09 +03:00
|
|
|
use Yii;
|
|
|
|
use yii\behaviors\TimestampBehavior;
|
2021-12-16 17:14:33 +03:00
|
|
|
use yii\db\ActiveQuery;
|
2018-10-11 11:15:09 +03:00
|
|
|
use yii\db\Expression;
|
2020-01-29 11:26:01 +03:00
|
|
|
use yii\filters\AccessControl;
|
2019-07-03 13:55:32 +03:00
|
|
|
use yii\helpers\ArrayHelper;
|
2018-10-11 11:15:09 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This is the model class for table "user_card".
|
|
|
|
*
|
|
|
|
* @property int $id
|
2019-11-14 17:21:34 +03:00
|
|
|
* @property int $id_user
|
2018-10-11 11:15:09 +03:00
|
|
|
* @property string $fio
|
|
|
|
* @property string $passport
|
|
|
|
* @property string $photo
|
|
|
|
* @property string $email
|
|
|
|
* @property int $gender
|
|
|
|
* @property string $dob
|
|
|
|
* @property int $status
|
|
|
|
* @property string $created_at
|
|
|
|
* @property string $updated_at
|
2018-11-06 11:44:27 +03:00
|
|
|
* @property string $deleted_at
|
2018-10-11 11:15:09 +03:00
|
|
|
* @property string $resume
|
2018-10-11 17:38:49 +03:00
|
|
|
* @property string $salary
|
2021-06-25 13:24:32 +03:00
|
|
|
* @property string $vc_text
|
2021-07-13 13:45:44 +03:00
|
|
|
* @property string $vc_text_short
|
2021-08-11 17:21:18 +03:00
|
|
|
* @property string $specification
|
|
|
|
* @property int $years_of_exp
|
2018-10-12 14:52:08 +03:00
|
|
|
* @property int $position_id
|
2019-12-09 10:54:39 +03:00
|
|
|
* @property int $city
|
2021-06-30 17:30:53 +03:00
|
|
|
* @property int $level
|
2022-03-07 12:32:01 +03:00
|
|
|
* @property string $test_task_getting_date
|
|
|
|
* @property string $test_task_complete_date
|
2022-11-03 17:46:36 +03:00
|
|
|
* @property string $resume_text
|
2022-11-14 13:48:31 +03:00
|
|
|
* @property int $resume_template_id
|
2022-11-17 12:40:22 +03:00
|
|
|
* @property int $resume_tariff
|
2018-10-11 11:15:09 +03:00
|
|
|
*
|
2018-10-12 14:52:08 +03:00
|
|
|
* @property FieldsValue[] $fieldsValues
|
|
|
|
* @property ProjectUser[] $projectUsers
|
2022-11-14 13:48:31 +03:00
|
|
|
* @property ResumeTemplate $resumeTemplate
|
2018-10-12 14:52:08 +03:00
|
|
|
* @property Position $position
|
2018-10-11 11:15:09 +03:00
|
|
|
* @property Status $status0
|
2021-09-09 13:12:37 +03:00
|
|
|
* @property Achievement[] $achievements
|
2018-10-11 11:15:09 +03:00
|
|
|
*/
|
|
|
|
class UserCard extends \yii\db\ActiveRecord
|
|
|
|
{
|
|
|
|
const GENDER_M = 0;
|
|
|
|
const GENDER_W = 1;
|
|
|
|
|
2021-06-30 17:30:53 +03:00
|
|
|
const LEVEL_JUNIOR = 1;
|
|
|
|
const LEVEL_MIDDLE = 2;
|
|
|
|
const LEVEL_MIDDLE_PLUS = 3;
|
|
|
|
const LEVEL_SENIOR = 4;
|
|
|
|
|
2022-11-03 17:46:36 +03:00
|
|
|
const SCENARIO_GENERATE_RESUME_TEXT = 'generate_resume_text';
|
|
|
|
const SCENARIO_UPDATE_RESUME_TEXT = 'update_resume_text';
|
2022-11-21 13:54:58 +03:00
|
|
|
const SCENARIO_DOWNLOAD_RESUME = 'download_resume_text';
|
2022-11-03 17:46:36 +03:00
|
|
|
|
|
|
|
|
2021-06-30 17:30:53 +03:00
|
|
|
/**
|
|
|
|
* @return string[]
|
|
|
|
*/
|
|
|
|
public static function getLevelList(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
self::LEVEL_JUNIOR => 'Junior',
|
|
|
|
self::LEVEL_MIDDLE => 'Middle',
|
|
|
|
self::LEVEL_MIDDLE_PLUS => 'Middle+',
|
|
|
|
self::LEVEL_SENIOR => 'Senior',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $level
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function getLevelLabel(int $level): string
|
|
|
|
{
|
|
|
|
return self::getLevelList()[$level];
|
|
|
|
}
|
|
|
|
|
2018-10-11 11:15:09 +03:00
|
|
|
public function behaviors()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
'class' => TimestampBehavior::class,
|
|
|
|
'createdAtAttribute' => 'created_at',
|
|
|
|
'updatedAtAttribute' => 'updated_at',
|
|
|
|
'value' => new Expression('NOW()'),
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public static function tableName()
|
|
|
|
{
|
|
|
|
return 'user_card';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function rules()
|
|
|
|
{
|
|
|
|
return [
|
2021-07-07 16:42:11 +03:00
|
|
|
[['fio', 'status', 'gender', 'email', 'level', 'position_id'], 'required'],
|
2022-11-17 12:40:22 +03:00
|
|
|
[['gender', 'status', 'position_id', 'id_user', 'level', 'years_of_exp', 'resume_tariff'], 'integer'],
|
2022-03-07 12:32:01 +03:00
|
|
|
[['dob', 'created_at', 'updated_at', 'deleted_at', 'vc_text', 'vc_text_short', 'test_task_getting_date', 'test_task_complete_date'], 'safe'],
|
2021-12-20 17:49:11 +03:00
|
|
|
['email', 'unique', 'message'=>'Почтовый адрес уже используется'],
|
2021-08-11 17:21:18 +03:00
|
|
|
[['fio', 'passport', 'photo', 'email', 'resume', 'city', 'link_vk', 'link_telegram', 'specification'], 'string', 'max' => 255],
|
2018-10-11 17:38:49 +03:00
|
|
|
[['salary'], 'string', 'max' => 100],
|
2018-10-12 14:52:08 +03:00
|
|
|
[['position_id'], 'exist', 'skipOnError' => true, 'targetClass' => Position::class, 'targetAttribute' => ['position_id' => 'id']],
|
2018-10-11 11:15:09 +03:00
|
|
|
[['status'], 'exist', 'skipOnError' => true, 'targetClass' => Status::class, 'targetAttribute' => ['status' => 'id']],
|
2022-11-14 13:48:31 +03:00
|
|
|
['resume_template_id', 'required', 'on' => self::SCENARIO_GENERATE_RESUME_TEXT],
|
|
|
|
['resume_template_id', 'integer', 'on' => self::SCENARIO_GENERATE_RESUME_TEXT],
|
2022-11-03 17:46:36 +03:00
|
|
|
['resume_text', 'required', 'on' => self::SCENARIO_UPDATE_RESUME_TEXT],
|
2022-11-21 13:54:58 +03:00
|
|
|
['resume_template_id', 'required', 'on' => self::SCENARIO_DOWNLOAD_RESUME],
|
2018-10-11 11:15:09 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function attributeLabels()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'id' => 'ID',
|
2019-11-14 17:21:34 +03:00
|
|
|
'id_user' => 'ID пользователя',
|
2018-10-11 11:15:09 +03:00
|
|
|
'fio' => 'ФИО',
|
|
|
|
'passport' => 'Паспорт',
|
|
|
|
'photo' => 'Фото',
|
|
|
|
'email' => 'Email',
|
|
|
|
'gender' => 'Пол',
|
|
|
|
'dob' => 'Дата рождения',
|
|
|
|
'status' => 'Статус',
|
|
|
|
'created_at' => 'Дата создания',
|
|
|
|
'updated_at' => 'Дата редактирование',
|
2018-11-06 11:44:27 +03:00
|
|
|
'deleted_at' => 'Дата удаления',
|
2018-10-11 11:15:09 +03:00
|
|
|
'resume' => 'Резюме',
|
2018-10-11 17:38:49 +03:00
|
|
|
'salary' => 'Зарплата',
|
2018-10-12 14:52:08 +03:00
|
|
|
'position_id' => 'Должность',
|
2019-12-09 10:54:39 +03:00
|
|
|
'city' => 'Город',
|
2020-08-05 15:34:23 +03:00
|
|
|
'link_vk' => 'VK',
|
|
|
|
'link_telegram' => 'Telegram',
|
2021-06-30 17:30:53 +03:00
|
|
|
'vc_text' => 'Резюме текст',
|
2021-07-13 13:45:44 +03:00
|
|
|
'vc_text_short' => 'Резюме короткий текст',
|
2021-08-11 17:21:18 +03:00
|
|
|
'level' => 'Уровень',
|
|
|
|
'years_of_exp' => 'Лет опыта',
|
2022-03-07 12:32:01 +03:00
|
|
|
'specification' => 'Спецификация',
|
|
|
|
'test_task_getting_date' => 'Дата получения тестового',
|
|
|
|
'test_task_complete_date' => 'Дата выполнения тестового',
|
2022-11-14 13:48:31 +03:00
|
|
|
'resume_template_id' => 'Шаблон резюме',
|
2022-11-17 12:40:22 +03:00
|
|
|
'resume_text' => 'Резюме сгенерированный текст',
|
|
|
|
'resume_tariff' => 'Ставка для резюме'
|
2018-10-11 11:15:09 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2018-10-11 17:38:49 +03:00
|
|
|
/**
|
2021-12-16 17:14:33 +03:00
|
|
|
* @return ActiveQuery
|
2018-10-11 17:38:49 +03:00
|
|
|
*/
|
|
|
|
public function getFieldsValues()
|
|
|
|
{
|
2019-06-27 15:41:58 +03:00
|
|
|
return $this->hasMany(FieldsValueNew::class, ['item_id' => 'id'])->where(['item_type' => FieldsValueNew::TYPE_PROFILE])->with('field');
|
2018-10-11 17:38:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-12-16 17:14:33 +03:00
|
|
|
* @return ActiveQuery
|
2018-10-11 17:38:49 +03:00
|
|
|
*/
|
|
|
|
public function getProjectUsers()
|
|
|
|
{
|
|
|
|
return $this->hasMany(ProjectUser::class, ['card_id' => 'id']);
|
|
|
|
}
|
|
|
|
|
2018-10-12 14:52:08 +03:00
|
|
|
/**
|
2021-12-16 17:14:33 +03:00
|
|
|
* @return ActiveQuery
|
2018-10-12 14:52:08 +03:00
|
|
|
*/
|
|
|
|
public function getPosition()
|
|
|
|
{
|
|
|
|
return $this->hasOne(Position::class, ['id' => 'position_id']);
|
|
|
|
}
|
|
|
|
|
2018-10-11 11:15:09 +03:00
|
|
|
/**
|
2021-12-16 17:14:33 +03:00
|
|
|
* @return ActiveQuery
|
2018-10-11 11:15:09 +03:00
|
|
|
*/
|
|
|
|
public function getStatus0()
|
|
|
|
{
|
|
|
|
return $this->hasOne(Status::class, ['id' => 'status']);
|
|
|
|
}
|
|
|
|
|
2021-09-09 13:12:37 +03:00
|
|
|
/**
|
2021-12-16 17:14:33 +03:00
|
|
|
* @return ActiveQuery
|
2021-09-09 13:12:37 +03:00
|
|
|
*/
|
2021-12-16 17:14:33 +03:00
|
|
|
public function getAchievements(): ActiveQuery
|
2021-09-09 13:12:37 +03:00
|
|
|
{
|
|
|
|
return $this->hasMany(AchievementUserCard::class, ['user_card_id' => 'id'])->with('achievement');
|
|
|
|
}
|
|
|
|
|
2018-10-11 11:15:09 +03:00
|
|
|
public function getGenders()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
self::GENDER_M => 'Мужчина',
|
|
|
|
self::GENDER_W => 'Женщина'
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string status text label
|
|
|
|
*/
|
|
|
|
public function getGendersText()
|
|
|
|
{
|
|
|
|
return $this->genders[$this->gender];
|
|
|
|
}
|
2019-07-03 13:55:32 +03:00
|
|
|
|
|
|
|
public function getSkillValues()
|
|
|
|
{
|
|
|
|
return $this->hasMany(CardSkill::class, ['card_id' => 'id'])->with('skill');
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getNameSkills()
|
|
|
|
{
|
2019-11-14 17:21:34 +03:00
|
|
|
return ArrayHelper::map(Skill::find()->all(), 'id', 'name');
|
2019-07-03 13:55:32 +03:00
|
|
|
}
|
2019-07-16 11:58:05 +03:00
|
|
|
|
2021-12-16 17:14:33 +03:00
|
|
|
public function getUser(): ActiveQuery
|
|
|
|
{
|
|
|
|
return $this->hasOne(User::class, ['id' => 'id_user']);
|
|
|
|
}
|
|
|
|
|
2019-07-16 11:58:05 +03:00
|
|
|
public static function getUserList()
|
|
|
|
{
|
|
|
|
return ArrayHelper::map(self::find()->all(), 'id', 'fio');
|
|
|
|
}
|
2020-05-22 16:42:24 +03:00
|
|
|
|
2021-12-23 11:28:27 +03:00
|
|
|
public function getManager()
|
|
|
|
{
|
|
|
|
return $this->hasOne(Manager::class, ['user_card_id' => 'id']);
|
|
|
|
}
|
|
|
|
|
2022-01-05 17:11:31 +03:00
|
|
|
public function getManagerEmployee()
|
|
|
|
{
|
|
|
|
return $this->hasMany(ManagerEmployee::class, ['user_card_id' => 'id']);
|
|
|
|
}
|
|
|
|
|
2022-12-01 14:11:29 +03:00
|
|
|
/**
|
|
|
|
* @return \yii\db\ActiveQuery
|
|
|
|
*/
|
|
|
|
public function getCompanyManagers()
|
|
|
|
{
|
|
|
|
return $this->hasMany(CompanyManager::className(), ['user_card_id' => 'id']);
|
|
|
|
}
|
|
|
|
|
2020-05-22 16:42:24 +03:00
|
|
|
public static function generateUserForUserCard($card_id = null)
|
|
|
|
{
|
|
|
|
$userCardQuery = self::find();
|
|
|
|
$card_id ? $userCardQuery->where(['id' => $card_id]) : $userCardQuery->where(['id_user' => NULL]);
|
|
|
|
$user_card_array = $userCardQuery->all();
|
|
|
|
$user_array = User::find()->all();
|
|
|
|
|
|
|
|
foreach ($user_card_array as $user_card_value) {
|
|
|
|
|
|
|
|
foreach ($user_array as $user_value)
|
|
|
|
if ($user_card_value->email == $user_value->email) {
|
|
|
|
$user_id = $user_value->id;
|
|
|
|
break;
|
|
|
|
} else $user_id = NULL;
|
|
|
|
|
|
|
|
if ($user_id) {
|
|
|
|
UserCard::genereateLinlkOnUser($user_card_value, $user_id);
|
|
|
|
} else {
|
|
|
|
$user_id = UserCard::generateUser($user_card_value->email, $user_card_value->status);
|
|
|
|
UserCard::genereateLinlkOnUser($user_card_value, $user_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($user_card_array) return "data generated successfully";
|
|
|
|
else return "no data to generate";
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function generateUser($email, $status)
|
|
|
|
{
|
|
|
|
$user = new User();
|
|
|
|
$auth_key = Yii::$app->security->generateRandomString();
|
|
|
|
$password = Yii::$app->security->generateRandomString(12);
|
|
|
|
$password_hash = Yii::$app->security->generatePasswordHash($password);
|
|
|
|
|
|
|
|
$user->username = $email;
|
|
|
|
$user->auth_key = $auth_key;
|
|
|
|
$user->password_hash = $password_hash;
|
|
|
|
$user->email = $email;
|
|
|
|
if ($status == 1) $user->status = 10;
|
|
|
|
|
|
|
|
$user->save();
|
|
|
|
|
|
|
|
$auth = Yii::$app->authManager;
|
|
|
|
$authorRole = $auth->getRole('user');
|
|
|
|
$auth->assign($authorRole, $user->id);
|
|
|
|
|
|
|
|
$log = "Логин: " . $email . " Пароль: " . $password . " | ";
|
|
|
|
file_put_contents("log.txt", $log, FILE_APPEND | LOCK_EX);
|
|
|
|
|
|
|
|
return $user->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function genereateLinlkOnUser($user_card, $user_id)
|
|
|
|
{
|
|
|
|
$user_card->id_user = $user_id;
|
|
|
|
$user_card->save();
|
|
|
|
}
|
2021-12-16 17:14:33 +03:00
|
|
|
|
|
|
|
public static function getUserIdByCardId ($card_id)
|
|
|
|
{
|
|
|
|
$userCard = self::findOne(['id' => $card_id]);
|
|
|
|
if (empty($userCard)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return $userCard['id_user'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getCardIdByUserId ($user_id)
|
|
|
|
{
|
|
|
|
$userCard = self::findOne(['id_user' => $user_id]);
|
|
|
|
if (empty($userCard)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return $userCard['id'];
|
|
|
|
|
|
|
|
}
|
2022-12-01 14:11:29 +03:00
|
|
|
|
|
|
|
public static function getCardByUserRole($role): array
|
|
|
|
{
|
|
|
|
$auth = Yii::$app->authManager;
|
|
|
|
$usersId = $auth->getUserIdsByRole($role);
|
|
|
|
|
|
|
|
return UserCard::find()->where([ 'IN', 'id_user', $usersId])->all();
|
|
|
|
}
|
2018-10-11 11:15:09 +03:00
|
|
|
}
|