You are here

public function LearningPathManagerController::updateItemMinScore in Opigno Learning path 3.x

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

Method called when an item success score is set or not.

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

File

src/Controller/LearningPathManagerController.php, line 190

Class

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

Namespace

Drupal\opigno_learning_path\Controller

Code

public function updateItemMinScore(Group $group, Request $request) {

  // Ensure all data are okay.
  $datas = json_decode($request
    ->getContent());
  if (empty($datas->cid)) {
    return new JsonResponse(NULL, Response::HTTP_BAD_REQUEST);
  }
  $cid = $datas->cid;
  $success_score_min = empty($datas->successScoreMin) ? 0 : $datas->successScoreMin;

  // Update the item.
  $content = LPManagedContent::load($cid);
  $content
    ->setSuccessScoreMin($success_score_min);
  $content
    ->save();

  // Return the JSON response.
  return new JsonResponse(NULL, Response::HTTP_OK);
}