You are here

public function OpignoGroupManagerController::setPositions in Opigno group manager 8

Same name and namespace in other branches
  1. 3.x src/Controller/OpignoGroupManagerController.php \Drupal\opigno_group_manager\Controller\OpignoGroupManagerController::setPositions()

Called after each update on learning path structure (add/remove/move node).

It update the position of a content.

1 string reference to 'OpignoGroupManagerController::setPositions'
opigno_group_manager.routing.yml in ./opigno_group_manager.routing.yml
opigno_group_manager.routing.yml

File

src/Controller/OpignoGroupManagerController.php, line 497

Class

OpignoGroupManagerController
Controller for all the actions of the Opigno group manager app.

Namespace

Drupal\opigno_group_manager\Controller

Code

public function setPositions(Request $request) {

  // Get the data and check if it's correct.
  $datas = json_decode($request
    ->getContent());
  if (empty($datas->mainItemPositions)) {
    return new JsonResponse(NULL, Response::HTTP_BAD_REQUEST);
  }
  $content_positions = $datas->mainItemPositions;

  // Then, for each content, update the position in DB and return OK.
  foreach ($content_positions as $content_position) {
    $content = OpignoGroupManagedContent::load($content_position->cid);
    if (empty($content)) {
      continue;
    }
    $content
      ->setCoordinateX($content_position->col);
    $content
      ->setCoordinateY($content_position->row);
    $content
      ->save();
  }
  return new JsonResponse(NULL, Response::HTTP_OK);
}