You are here

public function DashboardController::restoreToDefaultAll in Opigno dashboard 8

Same name and namespace in other branches
  1. 3.x src/Controller/DashboardController.php \Drupal\opigno_dashboard\Controller\DashboardController::restoreToDefaultAll()
1 string reference to 'DashboardController::restoreToDefaultAll'
opigno_dashboard.routing.yml in ./opigno_dashboard.routing.yml
opigno_dashboard.routing.yml

File

src/Controller/DashboardController.php, line 256

Class

DashboardController
Controller for all the actions of the Learning Path manager app.

Namespace

Drupal\opigno_dashboard\Controller

Code

public function restoreToDefaultAll() {
  $positioning = $this
    ->getPositioning(NULL, TRUE, TRUE);
  unset($positioning['positions'][0]);
  $connection = \Drupal::database();
  $uids = \Drupal::entityQuery('user')
    ->execute();
  unset($uids[0]);
  if ($uids) {
    foreach ($uids as $uid) {
      $connection
        ->merge('opigno_dashboard_positioning')
        ->key([
        'uid' => $uid,
      ])
        ->fields([
        'columns' => (int) $positioning['columns'],
        'positions' => json_encode($positioning['positions']),
      ])
        ->execute();
    }
  }
  return new JsonResponse(NULL, Response::HTTP_OK);
}