/** * UserModel constructor. * * @param User $user */ public function __construct(User $user = null) { if ($user !== null) { $this->id = $user->getId(); $this->username = $user->getUsername(); $this->email = $user->getEmail(); $this->nombres = $user->getNombres(); $this->apellidos = $user->getApellidos(); if (count($user->getRoles()) > 0) { $this->roles = array(); foreach ($user->getRoles() as $role) { $this->roles[] = $role; } } if (count($user->getGroups()) > 0) { $this->groups = new ArrayCollection(); foreach ($user->getGroups() as $group) { $this->groups->add($group); } } if (count($user->getProyectos()) > 0) { $this->proyectos = new ArrayCollection(); foreach ($user->getProyectos() as $proyecto) { $this->proyectos->add($proyecto); } } } }
/** * {@inheritDoc} */ public function __toString() { $this->__initializer__ && $this->__initializer__->__invoke($this, '__toString', array()); return parent::__toString(); }
/** * Edits an existing Usuario entity. * * @Route("/{id}/update", name="security_usuario_update") * @Method({"POST", "PUT"}) */ public function updateAction(Request $request, Usuario $user) { $model = new UserModel($user); //$deleteForm = $this->createDeleteForm($id); $editForm = $this->createEditForm($model); $editForm->handleRequest($request); if ($editForm->isValid()) { $em = $this->get('doctrine.orm.entity_manager'); $userManager = $this->get('fos_user.user_manager'); $user->setNombres($model->getNombres()); $user->setApellidos($model->getApellidos()); $user->setEmail($model->getEmail()); $user->setRoles($model->getRoles()); if (0 !== strlen($model->getPlainPassword())) { $user->setPlainPassword($model->getPlainPassword()); $userManager->updatePassword($user); } if (0 !== strlen($model->getPin())) { $user->setPin($model->getPin()); } try { $userManager->updateUser($user); $this->get('session')->getFlashBag()->add('success', 'Se han editado los datos del usuario satisfactoriamente.'); return $this->redirect($this->generateUrl('security_usuario_edit', array('id' => $user->getId()))); } catch (\Exception $e) { $this->get('logger')->critical(sprintf('Ha ocurrido un error al editar los datos del usuario. Detalles: %s', $e->getMessage())); $this->get('session')->getFlashBag()->add('danger', 'Ha ocurrido un error al editar los datos del usuario.'); } } return $this->render('HatueySoftSecurityBundle:Usuario:edit.html.twig', array('entity' => $user, 'edit_form' => $editForm->createView())); }