public function LearningPathManagerController::setPositions in Opigno Learning path 3.x
Same name and namespace in other branches
- 8 src/Controller/LearningPathManagerController.php \Drupal\opigno_learning_path\Controller\LearningPathManagerController::setPositions()
Called after each update on learning path structure (add/remove/move node).
It update the position of a content.
1 string reference to 'LearningPathManagerController::setPositions'
File
- src/
Controller/ LearningPathManagerController.php, line 268
Class
- LearningPathManagerController
- Controller for all the actions of the Learning Path manager app.
Namespace
Drupal\opigno_learning_path\ControllerCode
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 = LPManagedContent::load($content_position->cid);
$content
->setCoordinateX($content_position->col);
$content
->setCoordinateY($content_position->row);
$content
->save();
}
return new JsonResponse(NULL, Response::HTTP_OK);
}