public function requestAction(Request $request) { // Get the ID sent by the request $id = $request->get('id'); try { // Only SUPER_ADMIN can delete forums if ($this->get('security.context')->isGranted('ROLE_USER')) { // This deletes the given forum $em = $this->getDoctrine()->getEntityManager(); // A new certificate entity $certificate = new CertificateRequest(); // Find the user that sent the request $user = $this->get('security.context')->getToken()->getUser(); // Add the user to the certificate $certificate->setUser($user); // Store it in the database $em->persist($certificate); $em->flush(); // Send a response back to AJAX $response['success'] = true; } else { // Send a response back to AJAX $response['success'] = false; $response['cause'] = 'Du har ikke tilstrekkelige rettigheter.'; } } catch (\Exception $e) { // Send a response back to AJAX $response['success'] = false; $response['cause'] = 'Kunne ikke lage en ny forespørsel.'; //$response['cause'] = $e->getMessage(); // if you want to see the exception message. return new JsonResponse($response); } // Send a respons to ajax return new JsonResponse($response); }
public function load(ObjectManager $manager) { $cr1 = new CertificateRequest(); $cr1->setUser($this->getReference('user-14')); $manager->persist($cr1); $manager->flush(); }
public function testSetUser() { // new entity $cr = new CertificateRequest(); // dummy entity $user = new User(); $user->setFirstName("Thomas"); // Use the setUser method $cr->setUser($user); // Assert the result $this->assertEquals($user, $cr->getUser()); }