You are here

private function DeleteAchievementsForm::deleteAnswers in Opigno Learning path 8

Same name and namespace in other branches
  1. 3.x src/Form/DeleteAchievementsForm.php \Drupal\opigno_learning_path\Form\DeleteAchievementsForm::deleteAnswers()

Delete answers.

1 call to DeleteAchievementsForm::deleteAnswers()
DeleteAchievementsForm::submitForm in src/Form/DeleteAchievementsForm.php
Form submission handler.

File

src/Form/DeleteAchievementsForm.php, line 180

Class

DeleteAchievementsForm
Class LearningPathAdminSettingsForm.

Namespace

Drupal\opigno_learning_path\Form

Code

private function deleteAnswers(int $group_id, int $uid, array $modules) {
  foreach ($modules as $module) {
    if (!$module instanceof OpignoModule) {
      continue;
    }
    $user_module_statuses = \Drupal::entityTypeManager()
      ->getStorage('user_module_status')
      ->loadByProperties([
      'learning_path' => $group_id,
      'user_id' => $uid,
      'module' => $module
        ->id(),
    ]);
    foreach ($user_module_statuses as $status) {
      if (!$status instanceof UserModuleStatus) {
        continue;
      }
      $answers = $status
        ->getAnswers();
      foreach ($answers as $answer) {
        $answer
          ->delete();
      }
    }
  }
}