public function currencyValidator($attr) { if (!$this->hasErrors($attr)) { $this->_currency = Currency::find()->active()->andWhere(['id' => $this->{$attr}])->limit(1)->one(); if (!$this->_currency) { $this->addError($attr, 'There is no such currency'); return false; } $user = $this->_currency->user; if (!$user) { $this->addError($attr, 'There is no such currency'); return false; } if (!$this->_user->isInSameGroup($user)) { $this->addError($attr, 'This currency belongs to another User'); return false; } } }
public function actionIndex() { $currency = Currency::find()->active()->forUsersInSameGroup($this->_user)->expand(Yii::$app->request->getQueryParams())->asArray()->all(); return ['status' => true, 'data' => $currency]; }