public function actionFirstform()
 {
     if (Yii::$app->request->isAjax) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         $FormUser = new FormUser();
         $FormUser->load(Yii::$app->request->post());
         die(print json_encode(ActiveForm::validate($FormUser)));
     } else {
         return $this->goHome();
     }
 }
Example #2
0
 /**
  * @inheritdoc
  */
 public function beforeDelete()
 {
     if (parent::beforeDelete()) {
         // Delete related Models
         $this->formData->delete();
         $this->ui->delete();
         $this->formConfirmation->delete();
         $this->formEmail->delete();
         // Delete all Charts, Submissions and Files related to this form
         // We use deleteAll for performance reason
         FormUser::deleteAll(["form_id" => $this->id]);
         FormRule::deleteAll(["form_id" => $this->id]);
         FormChart::deleteAll(["form_id" => $this->id]);
         FormSubmissionFile::deleteAll(["form_id" => $this->id]);
         FormSubmission::deleteAll(["form_id" => $this->id]);
         // Delete all Stats related to this form
         Event::deleteAll(["app_id" => $this->id]);
         StatsPerformance::deleteAll(["app_id" => $this->id]);
         StatsSubmissions::deleteAll(["app_id" => $this->id]);
         // Removes files directory (and all its content)
         // of this form (if exists)
         FileHelper::removeDirectory($this::FILES_DIRECTORY . DIRECTORY_SEPARATOR . $this->id);
         return true;
     } else {
         return false;
     }
 }
Example #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUserForms()
 {
     return $this->hasMany(FormUser::className(), ['user_id' => 'id']);
 }
 /**
  * Delete an existing User model. If deletion is successful, the browser
  * will be redirected to the 'index' page.
  *
  * @param string $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     // delete profile and userkeys first to handle foreign key constraint
     $user = $this->findModel($id);
     // If user has admin role, check if the one
     if ($user->role->id === Role::ROLE_ADMIN && User::find()->where(['role_id' => Role::ROLE_ADMIN])->count() < 2) {
         Yii::$app->session->setFlash('danger', Yii::t('app', "You need to create another user with 'Admin' role in order to delete your account."));
     } else {
         $profile = $user->profile;
         UserKey::deleteAll(['user_id' => $user->id]);
         UserAuth::deleteAll(['user_id' => $user->id]);
         FormUser::deleteAll(["user_id" => $user->id]);
         $profile->delete();
         $user->delete();
         Yii::$app->getSession()->setFlash('success', Yii::t('app', 'The user has been successfully deleted.'));
     }
     return $this->redirect(['index']);
 }