You are here

public function LockrAdminController::getStatus in Lockr 8.2

Same name and namespace in other branches
  1. 8.4 src/Controller/LockrAdminController.php \Drupal\lockr\Controller\LockrAdminController::getStatus()
  2. 8.3 src/Controller/LockrAdminController.php \Drupal\lockr\Controller\LockrAdminController::getStatus()
  3. 4.x src/Controller/LockrAdminController.php \Drupal\lockr\Controller\LockrAdminController::getStatus()
1 call to LockrAdminController::getStatus()
LockrAdminController::overview in src/Controller/LockrAdminController.php

File

src/Controller/LockrAdminController.php, line 110

Class

LockrAdminController

Namespace

Drupal\lockr\Controller

Code

public function getStatus($status) {
  require_once "{$this->drupalRoot}/core/includes/install.inc";
  $text_config = $this->configFactory
    ->get('lockr.ui_text');
  $cert_valid = $status['cert_valid'];
  $exists = $status['exists'];
  $created = isset($status['created']) ? $status['created'] : FALSE;
  $reqs[] = [
    'title' => 'Certificate Valid',
    'value' => $cert_valid ? 'Yes' : 'No',
    'description' => $cert_valid ? $text_config
      ->get('admin_page.status.cert.valid') : $text_config
      ->get('admin_page.status.cert.not_valid'),
    'severity' => $cert_valid ? REQUIREMENT_OK : REQUIREMENT_ERROR,
  ];
  if ($cert_valid) {
    $reqs[] = [
      'title' => 'Environment',
      'value' => $status['info']['env'],
      'severity' => REQUIREMENT_INFO,
    ];
  }
  else {
    $private_path = PrivateStream::basepath();
    $default_text = $private_path ? $text_config
      ->get('admin_page.status.path.invalid') : $text_config
      ->get('admin_page.status.path.unknown');
    $is_dir = is_dir($private_path);
    $req = [
      'title' => 'Private Directory',
      'value' => $private_path ?: 'Unknown',
      'description' => $is_dir ? $text_config
        ->get('admin_page.status.path.exists') : $default_text,
      'severity' => $is_dir ? REQUIREMENT_OK : REQUIREMENT_ERROR,
    ];
    array_unshift($reqs, $req);
  }
  $reqs[] = [
    'title' => 'Site Registered',
    'value' => $exists ? 'Yes' : 'No',
    'description' => $exists ? $text_config
      ->get('admin_page.status.registered') : $text_config
      ->get('admin_page.status.not_registered'),
    'severity' => $exists ? REQUIREMENT_OK : REQUIREMENT_ERROR,
  ];
  if ($cert_valid) {
    $has_cc = $status['has_cc'];
    if ($created) {
      $expires = (new \DateTime())
        ->setTimestamp($created)
        ->add(new \DateInterval('P14D'));
      if ($expires > new \DateTime()) {
        $reqs[] = [
          'title' => 'Trial Expiration Date',
          'value' => $expires
            ->format('M jS, Y'),
          'severity' => REQUIREMENT_INFO,
        ];
      }
      elseif (!$has_cc) {
        $reqs[] = [
          'title' => 'Trial Expiration Date',
          'value' => $expires
            ->format('M jS, Y'),
          'severity' => REQUIREMENT_ERROR,
        ];
      }
    }
    $partner = $status['info']['partner'];
    $is_custom = in_array($partner, [
      'custom',
      'lockr',
    ]);
    $default = $is_custom ? REQUIREMENT_ERROR : REQUIREMENT_WARNING;
    $default_text = $is_custom ? $text_config
      ->get('admin_page.status.cc.missing.required') : $text_config
      ->get('admin_page.status.cc.missing.partner');
    $reqs[] = [
      'title' => 'Credit Card on File',
      'value' => $has_cc ? 'Yes' : 'No',
      'description' => $has_cc ? $text_config
        ->get('admin_page.status.cc.has') : $default_text,
      'severity' => $has_cc ? REQUIREMENT_OK : $default,
    ];
  }
  lockr_preprocess_status_report($reqs);
  return [
    '#theme' => 'status_report',
    '#requirements' => $reqs,
  ];
}