Guest User

Untitled

a guest
Jul 22nd, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.43 KB | None | 0 0
  1. /**
  2. * Creates a new profile entity.
  3. *
  4. * @Route("/new/{id}", name="profile_new")
  5. */
  6. public function newProfileAction(Request $request, User $user)
  7. {
  8.  
  9. $loggedAs = $this->getUser();
  10. $username = $loggedAs->getUsername();
  11.  
  12. $profile = new Profile();
  13. $form = $this->createForm(ProfileType::class, $profile);
  14. $form->handleRequest($request);
  15.  
  16. if ($form->isSubmitted() && $form->isValid()) {
  17. $profile->setLastConnexion(new DateTime('now'));
  18. $profile->setCreatedAccount(new DateTime('now'));
  19.  
  20. $em = $this->getDoctrine()->getManager();
  21. $em->persist($profile);
  22. $em->flush();
  23.  
  24. $user->setEnabled('1');
  25. $user->setIdLocation($profile->getId());
  26. $em = $this->getDoctrine()->getManager();
  27. $em->persist($user);
  28. $em->flush();
  29.  
  30.  
  31.  
  32. return $this->redirectToRoute('user_list');
  33. }
  34.  
  35. return $this->render('admin/user/new_profile.html.twig', array(
  36. 'profile' => $profile,
  37. 'form' => $form->createView(),
  38. 'username' => $username,
  39. ));
  40. }
  41.  
  42. <?php
  43.  
  44. namespace AppBundleEntity;
  45.  
  46. use DoctrineORMMapping as ORM;
  47. use JMSSerializerAnnotation as Serializer;
  48. use SymfonyBridgeDoctrineValidatorConstraintsUniqueEntity;
  49. use SymfonyComponentSecurityCoreUserUserInterface;
  50. use SymfonyComponentValidatorConstraints as Assert;
  51.  
  52. /**
  53. * User
  54. *
  55. * @ORMTable(name="user", uniqueConstraints=
  56. {@ORMUniqueConstraint(name="user_id_uindex", columns={"id"}),
  57. @ORMUniqueConstraint(name="user_username_uindex", columns=
  58. {"username"})}, indexes={@ORMIndex(name="user_profile_id_fk",
  59. columns={"id_profile"}), @ORMIndex(name="user_localisation_id_fk",
  60. columns={"id_location"})})
  61. * @ORMEntity(repositoryClass="AppBundleRepositoryUserRepository")
  62. * @UniqueEntity("username", groups={"Default", "Patch"})
  63. */
  64. class User implements UserInterface
  65. {
  66. const ROLE_USER = 'ROLE_USER';
  67. const ROLE_ADMIN = 'ROLE_ADMIN';
  68.  
  69. /**
  70. * @var integer
  71. *
  72. * @ORMColumn(name="id", type="integer")
  73. * @ORMId
  74. * @ORMGeneratedValue(strategy="IDENTITY")
  75. * @SerializerGroups({"Default", "Deserialize", "user_detail"})
  76. */
  77. protected $id;
  78.  
  79. /**
  80. * @var string
  81. *
  82. * @ORMColumn(name="username", type="string", length=32)
  83. * @SerializerGroups({"Default", "Deserialize", "user_detail"})
  84. */
  85. protected $username;
  86.  
  87. /**
  88. * @var string
  89. *
  90. * @ORMColumn(name="password", type="string", length=255)
  91. * @SerializerGroups({"Deserialize", "user_detail"})
  92. * @AssertRegex(
  93. * pattern="/(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]).{7,}/",
  94. * message="Password must be seven characters long and contain at least one digit code, upper case, and lower case letter!",
  95. * groups={"Default", "Patch"}
  96. * )
  97. */
  98. protected $password;
  99.  
  100. /**
  101. * @var boolean
  102. *
  103. * @ORMColumn(name="enabled", type="boolean", nullable=false)
  104. */
  105. protected $enabled = '1';
  106.  
  107. /**
  108. * @var AppBundleEntityLocalisation
  109. *
  110. * @ORMManyToOne(targetEntity="Localisation")
  111. * @ORMJoinColumns({
  112. * @ORMJoinColumn(name="id_location", referencedColumnName="id")
  113. * })
  114. */
  115. protected $idLocation;
  116.  
  117. /**
  118. * @var AppBundleEntityProfile
  119. *
  120. * @ORMManyToOne(targetEntity="Profile")
  121. * @ORMJoinColumns({
  122. * @ORMJoinColumn(name="id_profile", referencedColumnName="id")
  123. * })
  124. */
  125. protected $idProfile;
  126.  
  127. /**
  128. * @var DoctrineCommonCollectionsCollection
  129. *
  130. * @ORMManyToMany(targetEntity="User", inversedBy="idUserOne")
  131. * @ORMJoinTable(name="friend",
  132. * joinColumns={
  133. * @ORMJoinColumn(name="id_user_one", referencedColumnName="id")
  134. * },
  135. * inverseJoinColumns={
  136. * @ORMJoinColumn(name="id_user_two", referencedColumnName="id")
  137. * }
  138. * )
  139. */
  140. protected $idUserTwo;
  141.  
  142. /**
  143. * @var DoctrineCommonCollectionsCollection
  144. *
  145. * @ORMManyToMany(targetEntity="Place", inversedBy="idUserInvited")
  146. * @ORMJoinTable(name="list_invited",
  147. * joinColumns={
  148. * @ORMJoinColumn(name="id_user_invited", referencedColumnName="id")
  149. * },
  150. * inverseJoinColumns={
  151. * @ORMJoinColumn(name="id_place_invited", referencedColumnName="id")
  152. * }
  153. * )
  154. */
  155. protected $idPlaceInvited;
  156.  
  157. /**
  158. * @var DoctrineCommonCollectionsCollection
  159. *
  160. * @ORMManyToMany(targetEntity="Place", mappedBy="idUserPresent")
  161. */
  162. protected $idPlacePresent;
  163.  
  164. /**
  165. * @var DoctrineCommonCollectionsCollection
  166. *
  167. * @ORMManyToMany(targetEntity="Place", inversedBy="idUserPlace")
  168. * @ORMJoinTable(name="user_place",
  169. * joinColumns={
  170. * @ORMJoinColumn(name="id_user_place", referencedColumnName="id")
  171. * },
  172. * inverseJoinColumns={
  173. * @ORMJoinColumn(name="id_place_place", referencedColumnName="id")
  174. * }
  175. * )
  176. */
  177. protected $idPlacePlace;
  178.  
  179. /**
  180. * @var array
  181. * @ORMColumn(type="simple_array", length=200)
  182. * @SerializerExclude()
  183. */
  184. protected $roles;
  185.  
  186. /**
  187. * Constructor
  188. */
  189. public function __construct()
  190. {
  191. $this->idUserTwo = new DoctrineCommonCollectionsArrayCollection();
  192. $this->idPlaceInvited = new DoctrineCommonCollectionsArrayCollection();
  193. $this->idPlacePresent = new DoctrineCommonCollectionsArrayCollection();
  194. $this->idPlacePlace = new DoctrineCommonCollectionsArrayCollection();
  195. }
  196.  
  197. /**
  198. * @return int
  199. */
  200. public function getId()
  201. {
  202. return $this->id;
  203. }
  204.  
  205. /**
  206. * @param int $id
  207. */
  208. public function setId(int $id)
  209. {
  210. $this->id = $id;
  211. }
  212.  
  213. /**
  214. * @return string|null
  215. */
  216. public function getUsername()
  217. {
  218. return $this->username;
  219. }
  220.  
  221. /**
  222. * @param string $username
  223. */
  224. public function setUsername(string $username)
  225. {
  226. $this->username = $username;
  227. }
  228.  
  229. /**
  230. * @return string|null
  231. */
  232. public function getPassword()
  233. {
  234. return $this->password;
  235. }
  236.  
  237. /**
  238. * @param string $password
  239. */
  240. public function setPassword(string $password)
  241. {
  242. $this->password = $password;
  243. }
  244.  
  245. /**
  246. * @return bool
  247. */
  248. public function isEnabled()
  249. {
  250. return $this->enabled;
  251. }
  252.  
  253. /**
  254. * @param bool $enabled
  255. */
  256. public function setEnabled(bool $enabled)
  257. {
  258. $this->enabled = $enabled;
  259. }
  260.  
  261. /**
  262. * @return mixed
  263. */
  264. public function getIdLocation()
  265. {
  266. return $this->idLocation;
  267. }
  268.  
  269. /**
  270. * @param mixed $idLocation
  271. */
  272. public function setIdLocation($idLocation)
  273. {
  274. $this->idLocation = $idLocation;
  275. }
  276.  
  277. /**
  278. * @return mixed
  279. */
  280. public function getIdProfile()
  281. {
  282. return $this->idProfile;
  283. }
  284.  
  285. /**
  286. * @param mixed $idProfile
  287. */
  288. public function setIdProfile($idProfile)
  289. {
  290. $this->idProfile = $idProfile;
  291. }
  292.  
  293. /**
  294. * @return DoctrineCommonCollectionsCollection
  295. */
  296. public function getIdUserTwo()
  297. {
  298. return $this->idUserTwo;
  299. }
  300.  
  301. /**
  302. * @param DoctrineCommonCollectionsCollection $idUserTwo
  303. */
  304. public function setIdUserTwo(DoctrineCommonCollectionsCollection $idUserTwo)
  305. {
  306. $this->idUserTwo = $idUserTwo;
  307. }
  308.  
  309. /**
  310. * @return DoctrineCommonCollectionsCollection
  311. */
  312. public function getIdPlaceInvited()
  313. {
  314. return $this->idPlaceInvited;
  315. }
  316.  
  317. /**
  318. * @param DoctrineCommonCollectionsCollection $idPlaceInvited
  319. */
  320. public function setIdPlaceInvited(DoctrineCommonCollectionsCollection $idPlaceInvited)
  321. {
  322. $this->idPlaceInvited = $idPlaceInvited;
  323. }
  324.  
  325. /**
  326. * @return DoctrineCommonCollectionsCollection
  327. */
  328. public function getIdPlacePresent()
  329. {
  330. return $this->idPlacePresent;
  331. }
  332.  
  333. /**
  334. * @param DoctrineCommonCollectionsCollection $idPlacePresent
  335. */
  336. public function setIdPlacePresent(DoctrineCommonCollectionsCollection $idPlacePresent)
  337. {
  338. $this->idPlacePresent = $idPlacePresent;
  339. }
  340.  
  341. /**
  342. * @return DoctrineCommonCollectionsCollection
  343. */
  344. public function getIdPlacePlace()
  345. {
  346. return $this->idPlacePlace;
  347. }
  348.  
  349. /**
  350. * @param DoctrineCommonCollectionsCollection $idPlacePlace
  351. */
  352. public function setIdPlacePlace(DoctrineCommonCollectionsCollection $idPlacePlace)
  353. {
  354. $this->idPlacePlace = $idPlacePlace;
  355. }
  356.  
  357. /**
  358. * Returns the roles granted to the user.
  359. *
  360. * <code>
  361. * public function getRoles()
  362. * {
  363. * return array('ROLE_USER');
  364. * }
  365. * </code>
  366. *
  367. * Alternatively, the roles might be stored on a ``roles`` property,
  368. * and populated in any number of different ways when the user object
  369. * is created.
  370. *
  371. * @return (Role|string)[] The user roles
  372. */
  373. public function getRoles()
  374. {
  375. return $this->roles;
  376. }
  377.  
  378. /**
  379. * @param array $roles
  380. */
  381. public function setRoles(array $roles)
  382. {
  383. $this->roles = $roles;
  384. }
  385.  
  386. /**
  387. * Returns the salt that was originally used to encode the password.
  388. *
  389. * This can return null if the password was not encoded using a salt.
  390. *
  391. * @return string|null The salt
  392. */
  393. public function getSalt()
  394. {
  395. // TODO: Implement getSalt() method.
  396. }
  397.  
  398. /**
  399. * Removes sensitive data from the user.
  400. *
  401. * This is important if, at any given point, sensitive information like
  402. * the plain-text password is stored on this object.
  403. */
  404. public function eraseCredentials()
  405. {
  406. // TODO: Implement eraseCredentials() method.
  407. }
  408.  
  409. $user->setIdLocation($profile); //<-- set the entity
  410. $profil = $user->getIdLocation(); // get the profile not the id
Add Comment
Please, Sign In to add comment