You are here

public function DashboardController::restoreToDefaultAll in Opigno dashboard 3.x

Same name and namespace in other branches
  1. 8 src/Controller/DashboardController.php \Drupal\opigno_dashboard\Controller\DashboardController::restoreToDefaultAll()

Restore dashboard settings to defaults for the current user.

Return value

\Symfony\Component\HttpFoundation\JsonResponse The JSON response.

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 224

Class

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

Namespace

Drupal\opigno_dashboard\Controller

Code

public function restoreToDefaultAll() : JsonResponse {
  $positioning = $this->blockService
    ->getPositioning(NULL, TRUE, TRUE);
  unset($positioning['positions'][0]);
  if (!$this->userEntityQuery instanceof QueryInterface) {
    return new JsonResponse(NULL, 400);
  }
  $uids = $this->userEntityQuery
    ->execute();
  unset($uids[0]);
  if (!$uids) {
    return new JsonResponse(NULL, 400);
  }
  foreach ($uids as $uid) {
    try {
      $this->database
        ->merge('opigno_dashboard_positioning')
        ->key([
        'uid' => $uid,
      ])
        ->fields([
        'columns' => (int) $positioning['columns'],
        'positions' => json_encode($positioning['positions']),
      ])
        ->execute();
    } catch (\Exception $e) {
      watchdog_exception('opigno_dashboard_exception', $e);
    }
  }
  return new JsonResponse();
}