Skip to content

Commit

Permalink
big update
Browse files Browse the repository at this point in the history
  • Loading branch information
skeeks-semenov committed May 6, 2022
1 parent 2f8200e commit 55de523
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
10 changes: 6 additions & 4 deletions src/models/User.php
Expand Up @@ -198,6 +198,7 @@ public function _cmsAfterSave(AfterSaveEvent $e)
} else {
$cmsUserEmail = new CmsUserEmail();
$cmsUserEmail->value = $value;
$cmsUserEmail->cms_site_id = $this->cms_site_id;
$cmsUserEmail->cms_user_id = $this->id;
if (!$cmsUserEmail->save()) {
throw new Exception("Email не добавлен! ".print_r($cmsUserEmail->errors, true));
Expand All @@ -217,6 +218,7 @@ public function _cmsAfterSave(AfterSaveEvent $e)
}
} else {
$cmsUserPhone = new CmsUserPhone();
$cmsUserPhone->cms_site_id = $this->cms_site_id;
$cmsUserPhone->value = $value;
$cmsUserPhone->cms_user_id = $this->id;
if (!$cmsUserPhone->save()) {
Expand Down Expand Up @@ -339,12 +341,12 @@ function ($attribute) {
$value = StringHelper::strtolower(trim($this->{$attribute}));

if ($this->isNewRecord) {
if (CmsUserPhone::find()->cmsSite()->andWhere(['value' => $value])->one()) {
if (CmsUserPhone::find()->cmsSite($this->cms_site_id)->andWhere(['value' => $value])->one()) {
$this->addError($attribute, "Этот телефон уже занят");
}
} else {
if (CmsUserPhone::find()
->cmsSite()
->cmsSite($this->cms_site_id)
->andWhere(['value' => $value])
->andWhere(['!=', 'cms_user_id', $this->id])
->one()) {
Expand Down Expand Up @@ -376,13 +378,13 @@ function ($attribute) {
$value = StringHelper::strtolower(trim($this->{$attribute}));

if ($this->isNewRecord) {
if (CmsUserEmail::find()->cmsSite()->andWhere(['value' => $value])->one()) {
if (CmsUserEmail::find()->cmsSite($this->cms_site_id)->andWhere(['value' => $value])->one()) {
$this->addError($attribute, "Этот email уже занят");
return false;
}
} else {
if (CmsUserEmail::find()
->cmsSite()
->cmsSite($this->cms_site_id)
->andWhere(['value' => $value])
->andWhere(['!=', 'cms_user_id', $this->id])
->one()) {
Expand Down
15 changes: 11 additions & 4 deletions src/query/CmsActiveQuery.php
Expand Up @@ -56,13 +56,20 @@ public function sort($order = SORT_ASC)

/**
* Фильтрация по сайту
* @param int|CmsSite $cmsSite
*
* @return $this
* @return CmsActiveQuery
*/
public function cmsSite($cmsSite = null)
{
if (!$cmsSite instanceof CmsSite) {
$cmsSite = \Yii::$app->skeeks->site;
$cms_site_id = null;

if (is_int($cmsSite)) {
$cms_site_id = $cmsSite;
} elseif ($cmsSite instanceof CmsSite) {
$cms_site_id = $cmsSite->id;
} else {
$cms_site_id = \Yii::$app->skeeks->site->id;
}

$alias = $this->getPrimaryTableName();
Expand All @@ -75,7 +82,7 @@ public function cmsSite($cmsSite = null)
}
}

return $this->andWhere([$alias.'.cms_site_id' => $cmsSite->id]);
return $this->andWhere([$alias.'.cms_site_id' => $cms_site_id]);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/views/admin-user/view.php
Expand Up @@ -195,7 +195,8 @@
color: #3a3a3a;
}
.sx-block {
margin-bottom: 10px;
margin-bottom: 20px;
padding: 10px;
}
.sx-block .sx-block-content {
padding: 10px;
Expand Down

0 comments on commit 55de523

Please sign in to comment.