Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. <?php
  2.  
  3. namespace AppBundleDocument;
  4.  
  5. use DoctrineBundleMongoDBBundleValidatorConstraintsUnique as MongoDBUnique;
  6. use DoctrineODMMongoDBMappingAnnotations as MongoDB;
  7. use SymfonyComponentValidatorConstraints as Assert;
  8.  
  9. /**
  10. * @MongoDBDocument(collection="users")
  11. * @MongoDBUnique(fields="{id, email}")
  12. */
  13. class User
  14. {
  15. // ...
  16. /**
  17. * @MongoDBField(type="collection")
  18. */
  19. protected $loginLast90Days;
  20.  
  21. // ...
  22.  
  23. /**
  24. * Set loginLast90Days
  25. *
  26. * @param collection $loginLast90Days
  27. * @return $this
  28. */
  29. public function setLoginLast90Days($loginLast90Days)
  30. {
  31. $this->loginLast90Days = $loginLast90Days;
  32. return $this;
  33. }
  34.  
  35. /**
  36. * Get loginLast90Days
  37. *
  38. * @return collection $loginLast90Days
  39. */
  40. public function getLoginLast90Days()
  41. {
  42. return $this->loginLast90Days;
  43. }
  44.  
  45. public function addLoginLast90Days($login)
  46. {
  47. $this->loginLast90Days[] = $login;
  48. return $this;
  49. }
  50.  
  51. public function removeLoginLast90Days($login)
  52. {
  53. $this->loginLast90Days->removeElement($login);
  54. return $this;
  55. }
  56.  
  57. // ...
  58. }
  59.  
  60. $dm = $this->get('doctrine_mongodb');
  61.  
  62. $user = $dm->getRepository('AppBundle:User')->findOneBy(array('gmail' => $email));
  63.  
  64. $user->addLoginLast90Days(time());
  65.  
  66. $dm = $this->get('doctrine_mongodb')->getManager();
  67. $dm->persist($user);
  68. $dm->flush();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement