You are here

public function LearningPathManagerController::getPositions in Opigno Learning path 8

Same name and namespace in other branches
  1. 3.x src/Controller/LearningPathManagerController.php \Drupal\opigno_learning_path\Controller\LearningPathManagerController::getPositions()

This function is called on learning path load.

It return the coordinates of every steps.

1 string reference to 'LearningPathManagerController::getPositions'
opigno_learning_path.routing.yml in ./opigno_learning_path.routing.yml
opigno_learning_path.routing.yml

File

src/Controller/LearningPathManagerController.php, line 242

Class

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

Namespace

Drupal\opigno_learning_path\Controller

Code

public function getPositions(Group $group) {

  // Get the positions from DB.
  $entityPositions = [];
  try {
    $managed_contents = LPManagedContent::loadByProperties([
      'learning_path_id' => $group
        ->id(),
    ]);
  } catch (InvalidPluginDefinitionException $e) {
    return new JsonResponse(NULL, Response::HTTP_INTERNAL_SERVER_ERROR);
  }

  // Then, create a big array with the positions and return OK.
  foreach ($managed_contents as $managed_content) {
    $entityPositions[] = [
      'cid' => $managed_content
        ->id(),
      'col' => $managed_content
        ->getCoordinateX(),
      'row' => $managed_content
        ->getCoordinateY(),
    ];
  }
  return new JsonResponse($entityPositions, Response::HTTP_OK);
}