Пример #1
0
 /**
  * @return array
  * @throws \Exception
  * @throws \yii\web\BadRequestHttpException
  * @throws \yii\web\NotFoundHttpException
  */
 public function actionDelete()
 {
     $result = ['result' => false, 'message' => \Yii::t('account', 'Unknown error')];
     $account_id = (int) Request()->get('account_id');
     $key = str_clean(Request()->get('key'));
     if (empty($account_id)) {
         throw new \yii\web\BadRequestHttpException('Empty account id');
     }
     /** @var \cookyii\modules\Account\resources\AccountProperty $AccountPropertyModel */
     $AccountPropertyModel = \Yii::createObject(\cookyii\modules\Account\resources\AccountProperty::className());
     $Property = $AccountPropertyModel::find()->byAccountId($account_id)->byKey($key)->one();
     if (empty($Property)) {
         throw new \yii\web\NotFoundHttpException('Property not found');
     }
     if ($Property->delete() === false) {
         $result = ['result' => false, 'message' => \Yii::t('account', 'Unable to remove a property')];
     } else {
         $result = ['result' => true, 'message' => \Yii::t('account', 'Property was successfully removed')];
     }
     return $result;
 }
Пример #2
0
 /**
  * @return \cookyii\modules\Account\resources\queries\AccountQuery
  */
 public function getProperties()
 {
     /** @var \cookyii\modules\Account\resources\AccountProperty $AccountPropertyModel */
     $AccountPropertyModel = \Yii::createObject(\cookyii\modules\Account\resources\AccountProperty::className());
     return $this->hasMany($AccountPropertyModel::className(), ['account_id' => 'id']);
 }