Skip to content

Commit

Permalink
Merge pull request #24 from lingoda/10-avoid-sending-zero-content-id-…
Browse files Browse the repository at this point in the history
…in-soem-exercise-types

10 - (bugfix) Avoid inserting in ContentUserData without contentId
  • Loading branch information
jorisdugue committed Nov 6, 2020
2 parents e760175 + 5907a9e commit 97e35f1
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions Controller/H5PInteractionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,18 @@ public function setFinished(Request $request, $token)
*/
public function contentUserData(Request $request, $contentId, $dataType, $subContentId)
{
$response = [
'success' => TRUE
];
if (!$contentId) {
return new JsonResponse(['success' => false, 'message' => 'No content']);
}

$user = $this->getUser();
$data = $request->get("data");
$preload = $request->get("preload");
$invalidate = $request->get("invalidate");
$em = $this->getDoctrine()->getManager();
if ($data !== NULL && $preload !== NULL && $invalidate !== NULL) {
if(!\H5PCore::validToken('contentuserdata', $request->get("token"))){
$response->success = FALSE;
$response->message = 'Invalid security token.';
return new JsonResponse($response);
return new JsonResponse(['success' => false, 'message' => 'No content']);
}
//remove data if data = 0
if ($data === '0'){
Expand Down Expand Up @@ -119,7 +118,8 @@ public function contentUserData(Request $request, $contentId, $dataType, $subCon
$em->flush();
}
}
return new JsonResponse($response);

return new JsonResponse(['success' => true]);
}else{
$data = $em->getRepository("StuditH5PBundle:ContentUserData")->findOneBy(
[
Expand All @@ -129,11 +129,13 @@ public function contentUserData(Request $request, $contentId, $dataType, $subCon
'user' => $user->getId()
]
);
//decode for read the informations
$response['data'] = json_decode($this->get('serializer')->serialize($data,'json'));
}
return new JsonResponse($response);

//decode for read the information
return new JsonResponse([
'success' => true,
'data' => json_decode($this->get('serializer')->serialize($data, 'json')),
]);
}
}
/**
* @Route("/embed/{content}")
Expand Down

0 comments on commit 97e35f1

Please sign in to comment.