Advertisement
Guest User

Untitled

a guest
Jan 25th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.25 KB | None | 0 0
  1. <?php
  2.  
  3. // src/AppBundle/Entity/User.php
  4.  
  5. namespace AppBundleEntity;
  6.  
  7. use DoctrineORMMapping as ORM;
  8. use SymfonyComponentSecurityCoreUserUserInterface;
  9.  
  10. /**
  11. * @ORMTable(name="entity")
  12. * @ORMEntity(repositoryClass="AppBundleEntityUserRepository")
  13. */
  14. class Entity
  15. {
  16. /**
  17. * @ORMColumn(type="integer")
  18. * @ORMId
  19. * @ORMGeneratedValue(strategy="AUTO")
  20. */
  21. private $id;
  22.  
  23. /**
  24. * @ORMColumn(type="string", length=25, unique=true)
  25. */
  26. private $label;
  27.  
  28.  
  29. /**
  30. * @ORMColumn(type="string", length=4096, options={"default" = "DBQ="})
  31. */
  32. private $dsn;
  33.  
  34. /**
  35. * @ORMColumn(type="string", length=4096, options={"default" = ""})
  36. */
  37. private $entityName;
  38.  
  39.  
  40. /**
  41. * @ORMOneToMany(targetEntity="UserEntity", mappedBy="entity", cascade={"all"})
  42. * */
  43. protected $userEntities;
  44.  
  45.  
  46. /**
  47. * Get id
  48. *
  49. * @return integer
  50. */
  51. public function getId()
  52. {
  53. return $this->id;
  54. }
  55.  
  56. /**
  57. * Get label
  58. *
  59. * @return string
  60. */
  61. public function getLabel()
  62. {
  63. return $this->label;
  64. }
  65.  
  66. /**
  67. * Set label
  68. *
  69. * @param string label
  70. *
  71. * @return User
  72. */
  73. public function setLabel($label)
  74. {
  75. $this->label = $label;
  76. return $this;
  77. }
  78.  
  79. /**
  80. * Get dsn
  81. *
  82. * @return string
  83. */
  84. public function getDsn()
  85. {
  86. return $this->dsn;
  87. }
  88.  
  89. /**
  90. * Set dsn
  91. *
  92. * @param string dsn
  93. *
  94. * @return User
  95. */
  96. public function setDsn($dsn)
  97. {
  98. $this->dsn = $dsn;
  99. return $this;
  100. }
  101.  
  102. /**
  103. * @return mixed
  104. */
  105. public function getEntityName()
  106. {
  107. return $this->entityName;
  108. }
  109.  
  110. /**
  111. * @param mixed $entityName
  112. */
  113. public function setEntityName($entityName)
  114. {
  115. $this->entityName = $entityName;
  116. }
  117.  
  118.  
  119.  
  120. /** @see Serializable::serialize() */
  121. public function serialize()
  122. {
  123. return serialize(array(
  124. $this->id,
  125. $this->label
  126. ));
  127. }
  128.  
  129. /** @see Serializable::unserialize() */
  130. public function unserialize($serialized)
  131. {
  132. list (
  133. $this->id,
  134. $this->label
  135. ) = unserialize($serialized);
  136. }
  137.  
  138. public function __toString() {
  139. return $this->label;
  140. }
  141. /**
  142. * Constructor
  143. */
  144. public function __construct()
  145. {
  146. $this->userEntity = new DoctrineCommonCollectionsArrayCollection();
  147. }
  148. /**
  149. * Add userEntity
  150. *
  151. * @param AppBundleEntityUserEntity $userEntity
  152. *
  153. * @return User
  154. */
  155. public function addUserEntity(AppBundleEntityUserEntity $userEntity)
  156. {
  157. $this->userEntities[] = $userEntity;
  158.  
  159. return $this;
  160. }
  161.  
  162. /**
  163. * Remove userEntity
  164. *
  165. * @param AppBundleEntityUserEntity $userEntity
  166. */
  167. public function removeUserEntity(AppBundleEntityUserEntity $userEntity)
  168. {
  169. $this->userEntities->removeElement($userEntity);
  170. }
  171.  
  172. /**
  173. * Get userEntities
  174. *
  175. * @return DoctrineCommonCollectionsCollection
  176. */
  177. public function getUserEntities()
  178. {
  179. return $this->userEntities;
  180. }
  181. }
  182.  
  183. <?php
  184.  
  185. // src/AppBundle/Entity/User.php
  186.  
  187. namespace AppBundleEntity;
  188. use SymfonyComponentValidatorConstraints as Assert;
  189. use DoctrineORMMapping as ORM;
  190. use SymfonyComponentSecurityCoreUserUserInterface;
  191. use DoctrineCommonCollectionsArrayCollection;
  192.  
  193. /**
  194. * @ORMTable(name="user")
  195. * @ORMEntity(repositoryClass="AppBundleEntityUserRepository")
  196. */
  197. class User implements UserInterface, Serializable
  198. {
  199. /**
  200. * @ORMColumn(type="integer")
  201. * @ORMId
  202. * @ORMGeneratedValue(strategy="AUTO")
  203. */
  204. private $id;
  205.  
  206. /**
  207. * @ORMColumn(type="string", length=25, unique=true)
  208. */
  209. private $username;
  210.  
  211. /**
  212. * @ORMColumn(type="string", length=64)
  213. */
  214. private $password;
  215.  
  216. /**
  217. * @ORMColumn(type="string", length=60, unique=true)
  218. */
  219. private $email;
  220.  
  221. /**
  222. * @AssertLength(max = 4096)
  223. */
  224. private $plainPassword;
  225.  
  226. /**
  227. * @ORMOneToMany(targetEntity="UserEntity", mappedBy="user", cascade={"all"})
  228. * */
  229. protected $userEntities;
  230.  
  231. /**
  232. * @ORMManyToMany(targetEntity="Role")
  233. * @ORMJoinTable(name="users_roles",
  234. * joinColumns={@ORMJoinColumn(name="user_id", referencedColumnName="id")},
  235. * inverseJoinColumns={@ORMJoinColumn(name="role_id", referencedColumnName="id")}
  236. * )
  237. */
  238. private $roles;
  239.  
  240. /**
  241. * @ORMColumn(name="is_active", type="boolean")
  242. */
  243. private $isActive;
  244.  
  245. public function __construct()
  246. {
  247. $this->isActive = true;
  248. $this->entities = new ArrayCollection();
  249. $this->roles = new ArrayCollection();
  250. // may not be needed, see section on salt below
  251. // $this->salt = md5(uniqid(null, true));
  252. }
  253.  
  254. public function getUsername()
  255. {
  256. return $this->username;
  257. }
  258.  
  259. public function getSalt()
  260. {
  261. // you *may* need a real salt depending on your encoder
  262. // see section on salt below
  263. return null;
  264. }
  265.  
  266. public function getPassword()
  267. {
  268. return $this->password;
  269. }
  270.  
  271. public function getRoles()
  272. {
  273. return $this->roles->toArray();
  274. }
  275.  
  276. public function eraseCredentials()
  277. {
  278. }
  279.  
  280. /** @see Serializable::serialize() */
  281. public function serialize()
  282. {
  283. return serialize(array(
  284. $this->id,
  285. $this->username,
  286. $this->password,
  287. // see section on salt below
  288. // $this->salt,
  289. ));
  290. }
  291.  
  292. /** @see Serializable::unserialize() */
  293. public function unserialize($serialized)
  294. {
  295. list (
  296. $this->id,
  297. $this->username,
  298. $this->password,
  299. // see section on salt below
  300. // $this->salt
  301. ) = unserialize($serialized);
  302. }
  303.  
  304. /**
  305. * Get id
  306. *
  307. * @return integer
  308. */
  309. public function getId()
  310. {
  311. return $this->id;
  312. }
  313.  
  314. /**
  315. * Set username
  316. *
  317. * @param string $username
  318. *
  319. * @return User
  320. */
  321. public function setUsername($username)
  322. {
  323. $this->username = $username;
  324.  
  325. return $this;
  326. }
  327.  
  328.  
  329. public function getPlainPassword()
  330. {
  331. return $this->plainPassword;
  332. }
  333.  
  334. public function setPlainPassword($password)
  335. {
  336. $this->plainPassword = $password;
  337. }
  338.  
  339.  
  340. /**
  341. * Set password
  342. *
  343. * @param string $password
  344. *
  345. * @return User
  346. */
  347. public function setPassword($password)
  348. {
  349. if (!is_null($password)) {
  350. $this->password = $password;
  351. }
  352.  
  353. return $this;
  354. }
  355.  
  356. /**
  357. * Set email
  358. *
  359. * @param string $email
  360. *
  361. * @return User
  362. */
  363. public function setEmail($email)
  364. {
  365. $this->email = $email;
  366.  
  367. return $this;
  368. }
  369.  
  370. /**
  371. * Get email
  372. *
  373. * @return string
  374. */
  375. public function getEmail()
  376. {
  377. return $this->email;
  378. }
  379.  
  380. /**
  381. * Set isActive
  382. *
  383. * @param boolean $isActive
  384. *
  385. * @return User
  386. */
  387. public function setIsActive($isActive)
  388. {
  389. $this->isActive = $isActive;
  390.  
  391. return $this;
  392. }
  393.  
  394. /**
  395. * Get isActive
  396. *
  397. * @return boolean
  398. */
  399. public function getIsActive()
  400. {
  401. return $this->isActive;
  402. }
  403.  
  404. /**
  405. * Add role
  406. *
  407. * @param AppBundleEntityRole $role
  408. *
  409. * @return User
  410. */
  411. public function addRole(AppBundleEntityRole $role)
  412. {
  413. $this->roles[] = $role;
  414.  
  415. return $this;
  416. }
  417.  
  418. /**
  419. * Remove role
  420. *
  421. * @param AppBundleEntityRole $role
  422. */
  423. public function removeRole($role)
  424. {
  425. $this->roles->removeElement($role);
  426. }
  427.  
  428.  
  429. /**
  430. * Add userEntity
  431. *
  432. * @param AppBundleEntityUserEntity $userEntity
  433. *
  434. * @return User
  435. */
  436. public function addUserEntity(AppBundleEntityUserEntity $userEntity)
  437. {
  438. $this->userEntities[] = $userEntity;
  439.  
  440. return $this;
  441. }
  442.  
  443. /**
  444. * Remove userEntity
  445. *
  446. * @param AppBundleEntityUserEntity $userEntity
  447. */
  448. public function removeUserEntity(AppBundleEntityUserEntity $userEntity)
  449. {
  450. $this->userEntities->removeElement($userEntity);
  451. }
  452.  
  453. /**
  454. * Get userEntities
  455. *
  456. * @return DoctrineCommonCollectionsCollection
  457. */
  458. public function getUserEntities()
  459. {
  460. return $this->userEntities;
  461. }
  462. }
  463.  
  464. <?php
  465.  
  466. // src/AppBundle/Entity/User.php
  467.  
  468. namespace AppBundleEntity;
  469.  
  470. use DoctrineORMMapping as ORM;
  471. use SymfonyComponentSecurityCoreUserUserInterface;
  472.  
  473. /**
  474. * @ORMTable(name="user_entity")
  475. * @ORMEntity(repositoryClass="AppBundleEntityUserRepository")
  476. * @ORMHasLifecycleCallbacks()
  477. */
  478. class UserEntity
  479. {
  480. /**
  481. * @ORMColumn(type="integer")
  482. * @ORMId
  483. * @ORMGeneratedValue(strategy="AUTO")
  484. */
  485. private $id;
  486.  
  487. /**
  488. * @ORMManyToOne(targetEntity="User", inversedBy="userEntities")
  489. * @ORMJoinColumn(name="u_id", referencedColumnName="id")
  490. * */
  491. protected $user;
  492.  
  493. /**
  494. * @ORMManyToOne(targetEntity="Entity", inversedBy="userEntities")
  495. * @ORMJoinColumn(name="e_id", referencedColumnName="id")
  496. * */
  497. protected $entity;
  498.  
  499. /**
  500. * UserEntity constructor.
  501. * @param $user
  502. * @param $entity
  503. */
  504. public function __construct($user, $entity)
  505. {
  506. $this->user = $user;
  507. $this->entity = $entity;
  508. }
  509.  
  510.  
  511. /**
  512. * Get id
  513. *
  514. * @return integer
  515. */
  516. public function getId()
  517. {
  518. return $this->id;
  519. }
  520.  
  521. /**
  522. * Set user
  523. *
  524. * @param AppBundleEntityUser $user
  525. *
  526. * @return UserEntity
  527. */
  528. public function setUser(AppBundleEntityUser $user = null)
  529. {
  530. $this->user = $user;
  531.  
  532. return $this;
  533. }
  534.  
  535. /**
  536. * Get user
  537. *
  538. * @return AppBundleEntityUser
  539. */
  540. public function getUser()
  541. {
  542. return $this->user;
  543. }
  544.  
  545. /**
  546. * Set entity
  547. *
  548. * @param AppBundleEntityEntity $entity
  549. *
  550. * @return UserEntity
  551. */
  552. public function setEntity(AppBundleEntityEntity $entity = null)
  553. {
  554. $this->entity = $entity;
  555.  
  556. return $this;
  557. }
  558.  
  559. /**
  560. * Get entity
  561. *
  562. * @return AppBundleEntityEntity
  563. */
  564. public function getEntity()
  565. {
  566. return $this->entity;
  567. }
  568. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement