Рефакторинг. В АПИ добавлены методы в изменения: username, email, password
This commit is contained in:
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\modules\api\models\profile;
|
||||
use yii\base\Model;
|
||||
|
||||
class ProfileChangeEmailForm extends Model
|
||||
{
|
||||
|
||||
public $newEmail;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['newEmail'], 'string'],
|
||||
[['newEmail'], 'required'],
|
||||
[['newEmail'], 'email'],
|
||||
['newEmail', 'unique', 'targetAttribute' => 'email', 'targetClass' => User::class],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function formName(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\modules\api\models\profile;
|
||||
use yii\base\Model;
|
||||
|
||||
class ProfileChangePasswordForm extends Model
|
||||
{
|
||||
|
||||
public $password;
|
||||
public $newPassword;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['password', 'newPassword'], 'string'],
|
||||
[['password', 'newPassword'], 'required'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function formName(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\modules\api\models\profile;
|
||||
|
||||
use yii\base\Model;
|
||||
|
||||
class ProfileChangePersonalDataForm extends Model
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $newUsername;
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['newUsername'], 'string', 'max' => 255],
|
||||
[['newUsername'], 'required'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function formName(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
105
frontend/modules/api/models/profile/ProfileSearchForm.php
Normal file
105
frontend/modules/api/models/profile/ProfileSearchForm.php
Normal file
@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace frontend\modules\api\models\profile;
|
||||
|
||||
|
||||
use backend\modules\card\models\UserCard;
|
||||
use yii\base\Model;
|
||||
|
||||
/**
|
||||
* Class ProfileSearchForm
|
||||
* @property integer $limit
|
||||
* @property integer $offset
|
||||
* @property integer $id
|
||||
* @package frontend\modules\api\models
|
||||
*/
|
||||
class ProfileSearchForm extends Model
|
||||
{
|
||||
public $limit = 10;
|
||||
public $offset = 0;
|
||||
public $skills;
|
||||
|
||||
public $position_id;
|
||||
public $id;
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id', 'limit', 'offset', 'position_id'], 'safe'],
|
||||
[['skills'], 'checkIsArray'],
|
||||
];
|
||||
}
|
||||
|
||||
public function exclude($arr)
|
||||
{
|
||||
$ex = ['passport', 'resume', 'link_vk', 'link_telegram', 'email', 'salary'];
|
||||
foreach ($ex as $remove) {
|
||||
if (isset($arr[$remove])) {
|
||||
unset($arr[$remove]);
|
||||
}
|
||||
}
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
|
||||
public function checkIsArray()
|
||||
{
|
||||
if (!is_array($this->_task)) {
|
||||
$this->addError('_task', 'X is not array!');
|
||||
}
|
||||
}
|
||||
|
||||
public function byId()
|
||||
{
|
||||
if ($this->id) {
|
||||
return $this->exclude(UserCard::find()
|
||||
->where(['id' => $this->id])
|
||||
->with(['skillValues'])
|
||||
->with(['achievements'])
|
||||
->asArray()
|
||||
->one());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function byParams()
|
||||
{
|
||||
$model = UserCard::find();
|
||||
|
||||
if ($this->skills) {
|
||||
$model->joinWith(['skillValues']);
|
||||
$this->skills = explode(',', $this->skills);
|
||||
$model->where(['card_skill.skill_id' => $this->skills]);
|
||||
$model->having('COUNT(DISTINCT skill_id) = ' . count($this->skills));
|
||||
} else {
|
||||
$model->joinWith('skillValues');
|
||||
}
|
||||
|
||||
$model->joinWith('achievements');
|
||||
|
||||
$model->andFilterWhere(['position_id' => $this->position_id]);
|
||||
|
||||
$model->andWhere(['status' => [4, 12]]);
|
||||
$model->andWhere(['deleted_at' => null]);
|
||||
|
||||
//$model->groupBy('card_skill.card_id');
|
||||
|
||||
$res = $model->limit($this->limit)
|
||||
->offset($this->offset)->orderBy('updated_at DESC')->asArray()->all();
|
||||
|
||||
if(!$res){
|
||||
return [];
|
||||
}
|
||||
|
||||
$resArr = [];
|
||||
foreach ($res as $re){
|
||||
$resArr[] = $this->exclude($re);
|
||||
}
|
||||
|
||||
return $resArr;
|
||||
}
|
||||
|
||||
}
|
28
frontend/modules/api/models/profile/User.php
Normal file
28
frontend/modules/api/models/profile/User.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\modules\api\models\profile;
|
||||
|
||||
use frontend\modules\api\services\ProfileService;
|
||||
|
||||
class User extends \common\models\User
|
||||
{
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function fields(): array
|
||||
{
|
||||
return [
|
||||
'email',
|
||||
'username',
|
||||
'userCard' => function () {
|
||||
if(isset($this->userCard->id)){
|
||||
return ProfileService::getProfileById($this->userCard->id);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user