You are here

public function application_manager::deny_application in Apply for role 8

Parameters

mixed $application: Pass either an AID to load an application, or an actual application object.

Return value

bool

File

src/application_manager.php, line 180
Contains two classes.

Class

application_manager
Application manager object used for performing any tasks relating to applications.

Namespace

Drupal\apply_for_role

Code

public function deny_application($application) {
  if (!is_object($application)) {
    $application = $this
      ->get_application($application);
  }

  // Check if the application has been denied/approved already, and do not proceed if so.
  if ($application
    ->get('status') != 0) {
    return FALSE;
  }
  else {
    if ($this->apply_for_role_config
      ->get('send_user_deny_email')) {

      // @TODO: Replace deprecated user_load function.
      $to = user_load($application
        ->get('uid'))
        ->getEmail();
      $subject = $this->apply_for_role_config
        ->get('send_user_deny_subject');
      $body = $this->apply_for_role_config
        ->get('send_user_deny_body');
      $replacements = array(
        '%URL' => \Drupal::request()
          ->getHost(),
        '%ROLE' => $this
          ->rids_to_text($application
          ->get('rids')),
      );
      $this
        ->send_email($to, $subject, $body, $replacements);
    }

    // Mark the application as approved.
    Database::getConnection()
      ->update('apply_for_role_applications')
      ->fields(array(
      'status' => 2,
    ))
      ->condition('aid', $application
      ->get('aid'))
      ->execute();
  }
}