RegistrationToken.php 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. namespace Muzich\CoreBundle\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Symfony\Component\Validator\Constraints as Assert;
  5. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  6. /**
  7. * Le RegistrationToken sert uniquement a contrôler les inscription durant
  8. * toute la phase fermé du site en production.
  9. *
  10. * @ORM\Entity
  11. * @UniqueEntity(fields="token")
  12. */
  13. class RegistrationToken
  14. {
  15. /**
  16. * @ORM\Id
  17. * @ORM\Column(type="integer")
  18. * @ORM\GeneratedValue(strategy="AUTO")
  19. * @var type int
  20. */
  21. protected $id;
  22. /**
  23. * Le token en question
  24. *
  25. * @ORM\Column(type="string", length=32, unique=true)
  26. * @Assert\NotBlank()
  27. * @Assert\Length(min = 3, max = 32)
  28. * @var type string
  29. */
  30. protected $token;
  31. /**
  32. * Si ce boolean est a vrai il n'est plus utilisable
  33. * @ORM\Column(type="boolean", nullable=true)
  34. * @var boolean
  35. */
  36. protected $used = false;
  37. /**
  38. * @ORM\Column(type="integer", nullable=true)
  39. * @var int
  40. */
  41. protected $count = 0;
  42. /**
  43. * @ORM\Column(type="integer", nullable=true)
  44. * @var int
  45. */
  46. protected $count_max = 1;
  47. public function __toString()
  48. {
  49. return $this->getToken();
  50. }
  51. /**
  52. * Get id
  53. *
  54. * @return integer
  55. */
  56. public function getId()
  57. {
  58. return $this->id;
  59. }
  60. /**
  61. * Set token
  62. *
  63. * @param string $token
  64. */
  65. public function setToken($token)
  66. {
  67. $this->token = $token;
  68. }
  69. /**
  70. * Get token
  71. *
  72. * @return string
  73. */
  74. public function getToken()
  75. {
  76. return $this->token;
  77. }
  78. /**
  79. * Set used
  80. *
  81. * @param boolean $used
  82. */
  83. public function setUsed($used)
  84. {
  85. $this->used = $used;
  86. }
  87. /**
  88. * Get used
  89. *
  90. * @return boolean
  91. */
  92. public function getUsed()
  93. {
  94. return $this->used;
  95. }
  96. public function getCount()
  97. {
  98. if (!$this->count)
  99. {
  100. return 0;
  101. }
  102. return $this->count;
  103. }
  104. public function setCount($count)
  105. {
  106. $this->count = $count;
  107. }
  108. public function addUseCount()
  109. {
  110. $this->setCount($this->getCount()+1);
  111. if ($this->getCount() >= $this->count_max)
  112. {
  113. $this->setUsed(true);
  114. }
  115. }
  116. public function getCountMax()
  117. {
  118. return $this->count_max;
  119. }
  120. public function setCountMax($count_max)
  121. {
  122. $this->count_max = $count_max;
  123. }
  124. }