/** * {@inheritDoc} */ public function load(ObjectManager $manager) { $adminClock = new Clock(); $adminClock->setUser($this->getReference('admin-user')); $manager->persist($adminClock); $manager->flush(); }
/** * Run tests to ensure the output is correct for set/getLastClock * * @return void */ public function testLastClock() { $clock = new Clock(); $lastClock = new \DateTime("4:30 pm", new \DateTimeZone("UTC")); $clock->setLastClock($lastClock); $this->assertEquals($lastClock->getTimestamp(), $clock->getLastClock()->getTimestamp()); }
/** * Creates a new User entity. * * @param Request $request The user's request object * * @return Symfony\Component\HttpFoundation\Response */ public function newAction(Request $request) { if (false === $this->get('security.context')->isGranted('ROLE_ADMIN')) { throw new AccessDeniedException(); } $entity = new User(); $form = $this->createForm(new UserType(), $entity, array('validation_groups' => array('Default', 'user_creation'))); if ($request->getMethod() == 'POST') { $form->bind($request); if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); $encoder = $this->get('security.encoder_factory')->getEncoder($entity); $plainPassword = $entity->getPassword(); $password = $encoder->encodePassword($plainPassword, $entity->getSalt()); $entity->setPassword($password); $em->persist($entity); $em->flush(); $clock = new Clock(); $clock->setUser($entity); $em->persist($clock); $em->flush(); $mailer = $this->container->get('notify_mailer'); $mailer->notifyUserCreation($entity, $plainPassword); $request->getSession()->getFlashBag()->add('success', $entity->getName() . '\'s account created successfully.'); return $this->redirect($this->generateUrl('users')); } $request->getSession()->getFlashBag()->add('error', 'User could not be created. Check for form errors below. If the issue persists, please report it to your friendly sysadmin.'); } return $this->render('OpenSkedgeBundle:User:new.html.twig', array('entity' => $entity, 'form' => $form->createView())); }