Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Creates a new profile entity.
- *
- * @Route("/new/{id}", name="profile_new")
- */
- public function newProfileAction(Request $request, User $user)
- {
- $loggedAs = $this->getUser();
- $username = $loggedAs->getUsername();
- $profile = new Profile();
- $form = $this->createForm(ProfileType::class, $profile);
- $form->handleRequest($request);
- if ($form->isSubmitted() && $form->isValid()) {
- $profile->setLastConnexion(new DateTime('now'));
- $profile->setCreatedAccount(new DateTime('now'));
- $em = $this->getDoctrine()->getManager();
- $em->persist($profile);
- $em->flush();
- $user->setEnabled('1');
- $user->setIdLocation($profile->getId());
- $em = $this->getDoctrine()->getManager();
- $em->persist($user);
- $em->flush();
- return $this->redirectToRoute('user_list');
- }
- return $this->render('admin/user/new_profile.html.twig', array(
- 'profile' => $profile,
- 'form' => $form->createView(),
- 'username' => $username,
- ));
- }
- <?php
- namespace AppBundleEntity;
- use DoctrineORMMapping as ORM;
- use JMSSerializerAnnotation as Serializer;
- use SymfonyBridgeDoctrineValidatorConstraintsUniqueEntity;
- use SymfonyComponentSecurityCoreUserUserInterface;
- use SymfonyComponentValidatorConstraints as Assert;
- /**
- * User
- *
- * @ORMTable(name="user", uniqueConstraints=
- {@ORMUniqueConstraint(name="user_id_uindex", columns={"id"}),
- @ORMUniqueConstraint(name="user_username_uindex", columns=
- {"username"})}, indexes={@ORMIndex(name="user_profile_id_fk",
- columns={"id_profile"}), @ORMIndex(name="user_localisation_id_fk",
- columns={"id_location"})})
- * @ORMEntity(repositoryClass="AppBundleRepositoryUserRepository")
- * @UniqueEntity("username", groups={"Default", "Patch"})
- */
- class User implements UserInterface
- {
- const ROLE_USER = 'ROLE_USER';
- const ROLE_ADMIN = 'ROLE_ADMIN';
- /**
- * @var integer
- *
- * @ORMColumn(name="id", type="integer")
- * @ORMId
- * @ORMGeneratedValue(strategy="IDENTITY")
- * @SerializerGroups({"Default", "Deserialize", "user_detail"})
- */
- protected $id;
- /**
- * @var string
- *
- * @ORMColumn(name="username", type="string", length=32)
- * @SerializerGroups({"Default", "Deserialize", "user_detail"})
- */
- protected $username;
- /**
- * @var string
- *
- * @ORMColumn(name="password", type="string", length=255)
- * @SerializerGroups({"Deserialize", "user_detail"})
- * @AssertRegex(
- * pattern="/(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]).{7,}/",
- * message="Password must be seven characters long and contain at least one digit code, upper case, and lower case letter!",
- * groups={"Default", "Patch"}
- * )
- */
- protected $password;
- /**
- * @var boolean
- *
- * @ORMColumn(name="enabled", type="boolean", nullable=false)
- */
- protected $enabled = '1';
- /**
- * @var AppBundleEntityLocalisation
- *
- * @ORMManyToOne(targetEntity="Localisation")
- * @ORMJoinColumns({
- * @ORMJoinColumn(name="id_location", referencedColumnName="id")
- * })
- */
- protected $idLocation;
- /**
- * @var AppBundleEntityProfile
- *
- * @ORMManyToOne(targetEntity="Profile")
- * @ORMJoinColumns({
- * @ORMJoinColumn(name="id_profile", referencedColumnName="id")
- * })
- */
- protected $idProfile;
- /**
- * @var DoctrineCommonCollectionsCollection
- *
- * @ORMManyToMany(targetEntity="User", inversedBy="idUserOne")
- * @ORMJoinTable(name="friend",
- * joinColumns={
- * @ORMJoinColumn(name="id_user_one", referencedColumnName="id")
- * },
- * inverseJoinColumns={
- * @ORMJoinColumn(name="id_user_two", referencedColumnName="id")
- * }
- * )
- */
- protected $idUserTwo;
- /**
- * @var DoctrineCommonCollectionsCollection
- *
- * @ORMManyToMany(targetEntity="Place", inversedBy="idUserInvited")
- * @ORMJoinTable(name="list_invited",
- * joinColumns={
- * @ORMJoinColumn(name="id_user_invited", referencedColumnName="id")
- * },
- * inverseJoinColumns={
- * @ORMJoinColumn(name="id_place_invited", referencedColumnName="id")
- * }
- * )
- */
- protected $idPlaceInvited;
- /**
- * @var DoctrineCommonCollectionsCollection
- *
- * @ORMManyToMany(targetEntity="Place", mappedBy="idUserPresent")
- */
- protected $idPlacePresent;
- /**
- * @var DoctrineCommonCollectionsCollection
- *
- * @ORMManyToMany(targetEntity="Place", inversedBy="idUserPlace")
- * @ORMJoinTable(name="user_place",
- * joinColumns={
- * @ORMJoinColumn(name="id_user_place", referencedColumnName="id")
- * },
- * inverseJoinColumns={
- * @ORMJoinColumn(name="id_place_place", referencedColumnName="id")
- * }
- * )
- */
- protected $idPlacePlace;
- /**
- * @var array
- * @ORMColumn(type="simple_array", length=200)
- * @SerializerExclude()
- */
- protected $roles;
- /**
- * Constructor
- */
- public function __construct()
- {
- $this->idUserTwo = new DoctrineCommonCollectionsArrayCollection();
- $this->idPlaceInvited = new DoctrineCommonCollectionsArrayCollection();
- $this->idPlacePresent = new DoctrineCommonCollectionsArrayCollection();
- $this->idPlacePlace = new DoctrineCommonCollectionsArrayCollection();
- }
- /**
- * @return int
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * @param int $id
- */
- public function setId(int $id)
- {
- $this->id = $id;
- }
- /**
- * @return string|null
- */
- public function getUsername()
- {
- return $this->username;
- }
- /**
- * @param string $username
- */
- public function setUsername(string $username)
- {
- $this->username = $username;
- }
- /**
- * @return string|null
- */
- public function getPassword()
- {
- return $this->password;
- }
- /**
- * @param string $password
- */
- public function setPassword(string $password)
- {
- $this->password = $password;
- }
- /**
- * @return bool
- */
- public function isEnabled()
- {
- return $this->enabled;
- }
- /**
- * @param bool $enabled
- */
- public function setEnabled(bool $enabled)
- {
- $this->enabled = $enabled;
- }
- /**
- * @return mixed
- */
- public function getIdLocation()
- {
- return $this->idLocation;
- }
- /**
- * @param mixed $idLocation
- */
- public function setIdLocation($idLocation)
- {
- $this->idLocation = $idLocation;
- }
- /**
- * @return mixed
- */
- public function getIdProfile()
- {
- return $this->idProfile;
- }
- /**
- * @param mixed $idProfile
- */
- public function setIdProfile($idProfile)
- {
- $this->idProfile = $idProfile;
- }
- /**
- * @return DoctrineCommonCollectionsCollection
- */
- public function getIdUserTwo()
- {
- return $this->idUserTwo;
- }
- /**
- * @param DoctrineCommonCollectionsCollection $idUserTwo
- */
- public function setIdUserTwo(DoctrineCommonCollectionsCollection $idUserTwo)
- {
- $this->idUserTwo = $idUserTwo;
- }
- /**
- * @return DoctrineCommonCollectionsCollection
- */
- public function getIdPlaceInvited()
- {
- return $this->idPlaceInvited;
- }
- /**
- * @param DoctrineCommonCollectionsCollection $idPlaceInvited
- */
- public function setIdPlaceInvited(DoctrineCommonCollectionsCollection $idPlaceInvited)
- {
- $this->idPlaceInvited = $idPlaceInvited;
- }
- /**
- * @return DoctrineCommonCollectionsCollection
- */
- public function getIdPlacePresent()
- {
- return $this->idPlacePresent;
- }
- /**
- * @param DoctrineCommonCollectionsCollection $idPlacePresent
- */
- public function setIdPlacePresent(DoctrineCommonCollectionsCollection $idPlacePresent)
- {
- $this->idPlacePresent = $idPlacePresent;
- }
- /**
- * @return DoctrineCommonCollectionsCollection
- */
- public function getIdPlacePlace()
- {
- return $this->idPlacePlace;
- }
- /**
- * @param DoctrineCommonCollectionsCollection $idPlacePlace
- */
- public function setIdPlacePlace(DoctrineCommonCollectionsCollection $idPlacePlace)
- {
- $this->idPlacePlace = $idPlacePlace;
- }
- /**
- * Returns the roles granted to the user.
- *
- * <code>
- * public function getRoles()
- * {
- * return array('ROLE_USER');
- * }
- * </code>
- *
- * Alternatively, the roles might be stored on a ``roles`` property,
- * and populated in any number of different ways when the user object
- * is created.
- *
- * @return (Role|string)[] The user roles
- */
- public function getRoles()
- {
- return $this->roles;
- }
- /**
- * @param array $roles
- */
- public function setRoles(array $roles)
- {
- $this->roles = $roles;
- }
- /**
- * Returns the salt that was originally used to encode the password.
- *
- * This can return null if the password was not encoded using a salt.
- *
- * @return string|null The salt
- */
- public function getSalt()
- {
- // TODO: Implement getSalt() method.
- }
- /**
- * Removes sensitive data from the user.
- *
- * This is important if, at any given point, sensitive information like
- * the plain-text password is stored on this object.
- */
- public function eraseCredentials()
- {
- // TODO: Implement eraseCredentials() method.
- }
- $user->setIdLocation($profile); //<-- set the entity
- $profil = $user->getIdLocation(); // get the profile not the id
Add Comment
Please, Sign In to add comment