You are here

public function HideNotificationController::hide in OptimizeDB 8

Page hide notification.

Return value

string Result hide notification.

1 string reference to 'HideNotificationController::hide'
optimizedb.routing.yml in ./optimizedb.routing.yml
optimizedb.routing.yml

File

src/Controller/HideNotificationController.php, line 70

Class

HideNotificationController
Page hide notification.

Namespace

Drupal\optimizedb\Controller

Code

public function hide() {
  $time = $this->time
    ->getRequestTime();
  $config = $this->configFactory
    ->getEditable('optimizedb.settings');
  $notify_optimize = $config
    ->get('notify_optimize');

  // There is a need to disable the notification?
  if ($notify_optimize) {
    $config
      ->set('notify_optimize', FALSE)
      ->set('last_optimization', $time)
      ->save();
    $optimization_period = (int) $config
      ->get('optimization_period');
    $time_next_optimization = strtotime('+ ' . $optimization_period . ' day', $time);
    $output = $this
      ->t('The following message on the need to perform optimization, you get - @date.', [
      '@date' => $this->dateFormatter
        ->format($time_next_optimization),
    ]);
  }
  else {
    $output = $this
      ->t('Alerts are not available.');
  }
  return [
    '#type' => 'markup',
    '#markup' => $output,
  ];
}