You are here

public function ModuleResultForm::sendEmailToManager in Opigno module 8

Same name and namespace in other branches
  1. 3.x src/Form/ModuleResultForm.php \Drupal\opigno_module\Form\ModuleResultForm::sendEmailToManager()

Send Email to user.

1 call to ModuleResultForm::sendEmailToManager()
ModuleResultForm::submitForm in src/Form/ModuleResultForm.php
Form submission handler.

File

src/Form/ModuleResultForm.php, line 226

Class

ModuleResultForm
Class ModuleResultForm.

Namespace

Drupal\opigno_module\Form

Code

public function sendEmailToManager($module, $user_status, $answer) {
  if (!$module instanceof OpignoModule || !$user_status instanceof UserModuleStatus || !$answer instanceof OpignoAnswer) {
    return;
  }
  $student = $user_status
    ->get('user_id')->entity;
  $manager = \Drupal::currentUser();
  $global_config = \Drupal::config('system.site');
  $sitename = $global_config
    ->get('name');
  $config = \Drupal::config('opigno_learning_path.learning_path_settings');
  $student_activity_notify = $config
    ->get('opigno_learning_path_students_answer_is_reviewed_notify');
  $student_activity = $config
    ->get('opigno_learning_path_students_answer_is_reviewed');
  if (empty($student_activity_notify) || empty($student_activity) || !$student instanceof UserInterface) {
    return;
  }

  // Send email to student.
  $email = $student
    ->getEmail();
  $lang = $student
    ->getPreferredLangcode();
  $params = [];
  $params['subject'] = t('@sitename Module review', [
    '@sitename' => $sitename,
  ]);
  $student_activity = str_replace('[sitename]', $sitename, $student_activity);
  $student_activity = str_replace('[user]', $student
    ->getAccountName(), $student_activity);
  $student_activity = str_replace('[manager]', $manager
    ->getAccountName(), $student_activity);
  $student_activity = str_replace('[module]', $module
    ->getName(), $student_activity);
  $params['message'] = $student_activity;
  \Drupal::service('plugin.manager.mail')
    ->mail('opigno_learning_path', 'opigno_learning_path_user_notify', $email, $lang, $params);
}