User.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. /*
  3. * This file is part of Packagist.
  4. *
  5. * (c) Jordi Boggiano <j.boggiano@seld.be>
  6. * Nils Adermann <naderman@naderman.de>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Packagist\WebBundle\Entity;
  12. use FOS\UserBundle\Entity\User as BaseUser;
  13. use Doctrine\ORM\Mapping as ORM;
  14. use Doctrine\Common\Collections\ArrayCollection;
  15. /**
  16. * @ORM\Entity(repositoryClass="Packagist\WebBundle\Entity\UserRepository")
  17. * @ORM\Table(name="fos_user")
  18. */
  19. class User extends BaseUser
  20. {
  21. /**
  22. * @ORM\Id
  23. * @ORM\Column(type="integer")
  24. * @ORM\GeneratedValue(strategy="AUTO")
  25. */
  26. protected $id;
  27. /**
  28. * @ORM\ManyToMany(targetEntity="Package", mappedBy="maintainers")
  29. */
  30. private $packages;
  31. /**
  32. * @ORM\OneToMany(targetEntity="Packagist\WebBundle\Entity\Author", mappedBy="owner")
  33. */
  34. private $authors;
  35. /**
  36. * @ORM\Column(type="datetime")
  37. */
  38. private $createdAt;
  39. /**
  40. * @ORM\Column(type="string", length=20, nullable=true)
  41. * @var string
  42. */
  43. private $apiToken;
  44. public function __construct()
  45. {
  46. $this->packages = new ArrayCollection();
  47. $this->authors = new ArrayCollection();
  48. $this->createdAt = new \DateTime();
  49. parent::__construct();
  50. }
  51. public function toArray()
  52. {
  53. return array(
  54. 'name' => $this->getUsername(),
  55. 'email' => $this->getEmail(),
  56. );
  57. }
  58. /**
  59. * Add packages
  60. *
  61. * @param Packagist\WebBundle\Entity\Package $packages
  62. */
  63. public function addPackages(Package $packages)
  64. {
  65. $this->packages[] = $packages;
  66. }
  67. /**
  68. * Get packages
  69. *
  70. * @return Doctrine\Common\Collections\Collection $packages
  71. */
  72. public function getPackages()
  73. {
  74. return $this->packages;
  75. }
  76. /**
  77. * Add authors
  78. *
  79. * @param Packagist\WebBundle\Entity\Author $authors
  80. */
  81. public function addAuthors(\Packagist\WebBundle\Entity\Author $authors)
  82. {
  83. $this->authors[] = $authors;
  84. }
  85. /**
  86. * Get authors
  87. *
  88. * @return Doctrine\Common\Collections\Collection
  89. */
  90. public function getAuthors()
  91. {
  92. return $this->authors;
  93. }
  94. /**
  95. * Set createdAt
  96. *
  97. * @param datetime $createdAt
  98. */
  99. public function setCreatedAt($createdAt)
  100. {
  101. $this->createdAt = $createdAt;
  102. }
  103. /**
  104. * Get createdAt
  105. *
  106. * @return datetime
  107. */
  108. public function getCreatedAt()
  109. {
  110. return $this->createdAt;
  111. }
  112. /**
  113. * Set apiToken
  114. *
  115. * @param string $apiToken
  116. */
  117. public function setApiToken($apiToken)
  118. {
  119. $this->apiToken = $apiToken;
  120. }
  121. /**
  122. * Get apiToken
  123. *
  124. * @return string
  125. */
  126. public function getApiToken()
  127. {
  128. return $this->apiToken;
  129. }
  130. }