first commit

This commit is contained in:
king199025
2018-10-11 11:15:09 +03:00
commit 9e8e98c379
230 changed files with 12117 additions and 0 deletions

View File

@ -0,0 +1,66 @@
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "additional_fields".
*
* @property int $id
* @property string $name
*
* @property FieldsValue[] $fieldsValues
* @property UseField[] $useFields
*/
class AdditionalFields extends \yii\db\ActiveRecord
{
public $use = [];
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'additional_fields';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['name', 'use'], 'required'],
[['name'], 'string', 'max' => 100],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'name' => 'Название',
'use' => 'Применение',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getFieldsValues()
{
return $this->hasMany(FieldsValue::className(), ['field_id' => 'id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getUseFields()
{
return $this->hasMany(UseField::className(), ['field_id' => 'id']);
}
}

View File

@ -0,0 +1,82 @@
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "fields_value".
*
* @property int $id
* @property int $card_id
* @property int $project_id
* @property int $field_id
* @property string $value
* @property int $order
*
* @property AdditionalFields $field
* @property UserCard $card
*/
class FieldsValue extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'fields_value';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['field_id', 'value'], 'required'],
[['card_id', 'field_id', 'order', 'project_id'], 'integer'],
[['value'], 'string', 'max' => 255],
[['field_id'], 'exist', 'skipOnError' => true, 'targetClass' => AdditionalFields::class, 'targetAttribute' => ['field_id' => 'id']],
[['project_id'], 'exist', 'skipOnError' => true, 'targetClass' => Project::class, 'targetAttribute' => ['project_id' => 'id']],
[['card_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::class, 'targetAttribute' => ['card_id' => 'id']],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'card_id' => 'Card ID',
'field_id' => 'Field ID',
'value' => 'Value',
'project_id' => 'Project ID',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getField()
{
return $this->hasOne(AdditionalFields::class, ['id' => 'field_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getProject()
{
return $this->hasOne(Project::class, ['id' => 'project_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getCard()
{
return $this->hasOne(UserCard::class, ['id' => 'card_id']);
}
}

View File

@ -0,0 +1,78 @@
<?php
namespace common\models;
use Yii;
use yii\base\Model;
/**
* Login form
*/
class LoginForm extends Model
{
public $username;
public $password;
public $rememberMe = true;
private $_user;
/**
* {@inheritdoc}
*/
public function rules()
{
return [
// username and password are both required
[['username', 'password'], 'required'],
// rememberMe must be a boolean value
['rememberMe', 'boolean'],
// password is validated by validatePassword()
['password', 'validatePassword'],
];
}
/**
* Validates the password.
* This method serves as the inline validation for password.
*
* @param string $attribute the attribute currently being validated
* @param array $params the additional name-value pairs given in the rule
*/
public function validatePassword($attribute, $params)
{
if (!$this->hasErrors()) {
$user = $this->getUser();
if (!$user || !$user->validatePassword($this->password)) {
$this->addError($attribute, 'Incorrect username or password.');
}
}
}
/**
* Logs in a user using the provided username and password.
*
* @return bool whether the user is logged in successfully
*/
public function login()
{
if ($this->validate()) {
return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0);
}
return false;
}
/**
* Finds user by [[username]]
*
* @return User|null
*/
protected function getUser()
{
if ($this->_user === null) {
$this->_user = User::findByUsername($this->username);
}
return $this->_user;
}
}

66
common/models/Project.php Normal file
View File

@ -0,0 +1,66 @@
<?php
namespace common\models;
use Yii;
use yii\behaviors\TimestampBehavior;
use yii\db\Expression;
/**
* This is the model class for table "project".
*
* @property int $id
* @property string $name
* @property string $description
* @property string $created_at
* @property string $updated_at
*/
class Project extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'project';
}
public function behaviors()
{
return [
[
'class' => TimestampBehavior::class,
'createdAtAttribute' => 'created_at',
'updatedAtAttribute' => 'updated_at',
'value' => new Expression('NOW()'),
],
];
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['name'], 'required'],
[['description'], 'string'],
[['created_at', 'updated_at'], 'safe'],
[['name'], 'string', 'max' => 255],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'name' => 'Название',
'description' => 'Описание',
'created_at' => 'Дата создания',
'updated_at' => 'Дата редактирования',
];
}
}

View File

@ -0,0 +1,67 @@
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "project_user".
*
* @property int $id
* @property int $card_id
* @property int $project_id
*
* @property Project $project
* @property UserCard $card
*/
class ProjectUser extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'project_user';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['card_id', 'project_id'], 'required'],
[['card_id', 'project_id'], 'integer'],
[['project_id'], 'exist', 'skipOnError' => true, 'targetClass' => Project::className(), 'targetAttribute' => ['project_id' => 'id']],
[['card_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::className(), 'targetAttribute' => ['card_id' => 'id']],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'card_id' => 'Card ID',
'project_id' => 'Project ID',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getProject()
{
return $this->hasOne(Project::className(), ['id' => 'project_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getCard()
{
return $this->hasOne(UserCard::className(), ['id' => 'card_id']);
}
}

66
common/models/Status.php Normal file
View File

@ -0,0 +1,66 @@
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "status".
*
* @property int $id
* @property string $name
*
* @property UseStatus[] $useStatuses
* @property UserCard[] $userCards
*/
class Status extends \yii\db\ActiveRecord
{
public $use = [];
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'status';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['name', 'use'], 'required'],
[['name'], 'string', 'max' => 100],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'name' => 'Название',
'use' => 'Применение',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getUseStatuses()
{
return $this->hasMany(UseStatus::class, ['status_id' => 'id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getUserCards()
{
return $this->hasMany(UserCard::class, ['status' => 'id']);
}
}

View File

@ -0,0 +1,80 @@
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "use_field".
*
* @property int $id
* @property int $field_id
* @property int $use
*
* @property array $statuses
* @property string $statusesText
*
* @property AdditionalFields $field
*/
class UseField extends \yii\db\ActiveRecord
{
const USE_PROFILE = 0;
const USE_PROJECT = 1;
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'use_field';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['field_id', 'use'], 'required'],
[['field_id', 'use'], 'integer'],
[['field_id'], 'exist', 'skipOnError' => true, 'targetClass' => AdditionalFields::className(), 'targetAttribute' => ['field_id' => 'id']],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'field_id' => 'Поле',
'use' => 'Применение',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getField()
{
return $this->hasOne(AdditionalFields::className(), ['id' => 'field_id']);
}
public function getStatuses()
{
return [
self::USE_PROFILE => 'Профиль',
self::USE_PROJECT => 'Проект'
];
}
/**
* @return string status text label
*/
public function getStatusesText()
{
return $this->statuses[$this->status_id];
}
}

View File

@ -0,0 +1,79 @@
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "use_status".
*
* @property int $id
* @property int $status_id
* @property int $use
*
* @property array $statuses
* @property string $statusesText
*
* @property Status $status
*/
class UseStatus extends \yii\db\ActiveRecord
{
const USE_PROFILE = 0;
const USE_PROJECT = 1;
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'use_status';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['status_id', 'use'], 'required'],
[['status_id', 'use'], 'integer'],
[['status_id'], 'exist', 'skipOnError' => true, 'targetClass' => Status::class, 'targetAttribute' => ['status_id' => 'id']],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'status_id' => 'Статус',
'use' => 'Применение',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getStatus()
{
return $this->hasOne(Status::class, ['id' => 'status_id']);
}
public function getStatuses()
{
return [
self::USE_PROFILE => 'Профиль',
self::USE_PROJECT => 'Проект'
];
}
/**
* @return string status text label
*/
public function getStatusesText()
{
return $this->statuses[$this->status_id];
}
}

189
common/models/User.php Normal file
View File

@ -0,0 +1,189 @@
<?php
namespace common\models;
use Yii;
use yii\base\NotSupportedException;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use yii\web\IdentityInterface;
/**
* User model
*
* @property integer $id
* @property string $username
* @property string $password_hash
* @property string $password_reset_token
* @property string $email
* @property string $auth_key
* @property integer $status
* @property integer $created_at
* @property integer $updated_at
* @property string $password write-only password
*/
class User extends ActiveRecord implements IdentityInterface
{
const STATUS_DELETED = 0;
const STATUS_ACTIVE = 10;
/**
* {@inheritdoc}
*/
public static function tableName()
{
return '{{%user}}';
}
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
TimestampBehavior::className(),
];
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
['status', 'default', 'value' => self::STATUS_ACTIVE],
['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED]],
];
}
/**
* {@inheritdoc}
*/
public static function findIdentity($id)
{
return static::findOne(['id' => $id, 'status' => self::STATUS_ACTIVE]);
}
/**
* {@inheritdoc}
*/
public static function findIdentityByAccessToken($token, $type = null)
{
throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.');
}
/**
* Finds user by username
*
* @param string $username
* @return static|null
*/
public static function findByUsername($username)
{
return static::findOne(['username' => $username, 'status' => self::STATUS_ACTIVE]);
}
/**
* Finds user by password reset token
*
* @param string $token password reset token
* @return static|null
*/
public static function findByPasswordResetToken($token)
{
if (!static::isPasswordResetTokenValid($token)) {
return null;
}
return static::findOne([
'password_reset_token' => $token,
'status' => self::STATUS_ACTIVE,
]);
}
/**
* Finds out if password reset token is valid
*
* @param string $token password reset token
* @return bool
*/
public static function isPasswordResetTokenValid($token)
{
if (empty($token)) {
return false;
}
$timestamp = (int) substr($token, strrpos($token, '_') + 1);
$expire = Yii::$app->params['user.passwordResetTokenExpire'];
return $timestamp + $expire >= time();
}
/**
* {@inheritdoc}
*/
public function getId()
{
return $this->getPrimaryKey();
}
/**
* {@inheritdoc}
*/
public function getAuthKey()
{
return $this->auth_key;
}
/**
* {@inheritdoc}
*/
public function validateAuthKey($authKey)
{
return $this->getAuthKey() === $authKey;
}
/**
* Validates password
*
* @param string $password password to validate
* @return bool if password provided is valid for current user
*/
public function validatePassword($password)
{
return Yii::$app->security->validatePassword($password, $this->password_hash);
}
/**
* Generates password hash from password and sets it to the model
*
* @param string $password
*/
public function setPassword($password)
{
$this->password_hash = Yii::$app->security->generatePasswordHash($password);
}
/**
* Generates "remember me" authentication key
*/
public function generateAuthKey()
{
$this->auth_key = Yii::$app->security->generateRandomString();
}
/**
* Generates new password reset token
*/
public function generatePasswordResetToken()
{
$this->password_reset_token = Yii::$app->security->generateRandomString() . '_' . time();
}
/**
* Removes password reset token
*/
public function removePasswordResetToken()
{
$this->password_reset_token = null;
}
}

112
common/models/UserCard.php Normal file
View File

@ -0,0 +1,112 @@
<?php
namespace common\models;
use Yii;
use yii\behaviors\TimestampBehavior;
use yii\db\Expression;
/**
* This is the model class for table "user_card".
*
* @property int $id
* @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
* @property string $resume
*
* @property array $genders
* @property string $gendersText
*
* @property Status $status0
*/
class UserCard extends \yii\db\ActiveRecord
{
const GENDER_M = 0;
const GENDER_W = 1;
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 [
[['fio', 'status'], 'required'],
[['status'], 'integer'],
[['gender'], 'in', 'range' => array_keys($this->genders)],
[['dob', 'created_at', 'updated_at'], 'safe'],
[['fio', 'passport', 'photo', 'email', 'resume'], 'string', 'max' => 255],
[['status'], 'exist', 'skipOnError' => true, 'targetClass' => Status::class, 'targetAttribute' => ['status' => 'id']],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'fio' => 'ФИО',
'passport' => 'Паспорт',
'photo' => 'Фото',
'email' => 'Email',
'gender' => 'Пол',
'dob' => 'Дата рождения',
'status' => 'Статус',
'created_at' => 'Дата создания',
'updated_at' => 'Дата редактирование',
'resume' => 'Резюме',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getStatus0()
{
return $this->hasOne(Status::class, ['id' => 'status']);
}
public function getGenders()
{
return [
self::GENDER_M => 'Мужчина',
self::GENDER_W => 'Женщина'
];
}
/**
* @return string status text label
*/
public function getGendersText()
{
return $this->genders[$this->gender];
}
}