BlogPost.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace JMS\Serializer\Tests\Fixtures\DoctrinePHPCR;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
  5. use JMS\Serializer\Annotation\Groups;
  6. use JMS\Serializer\Annotation\SerializedName;
  7. use JMS\Serializer\Annotation\Type;
  8. use JMS\Serializer\Annotation\XmlAttribute;
  9. use JMS\Serializer\Annotation\XmlList;
  10. use JMS\Serializer\Annotation\XmlRoot;
  11. /**
  12. * @PHPCRODM\Document
  13. * @XmlRoot("blog-post")
  14. */
  15. class BlogPost
  16. {
  17. /**
  18. * @PHPCRODM\Id()
  19. */
  20. protected $id;
  21. /**
  22. * @PHPCRODM\Field(type="string")
  23. * @Groups({"comments","post"})
  24. */
  25. private $title;
  26. /**
  27. * @PHPCRODM\Field(type="string")
  28. */
  29. protected $slug;
  30. /**
  31. * @PHPCRODM\Field(type="date")
  32. * @XmlAttribute
  33. */
  34. private $createdAt;
  35. /**
  36. * @PHPCRODM\Field(type="boolean")
  37. * @Type("integer")
  38. * This boolean to integer conversion is one of the few changes between this
  39. * and the standard BlogPost class. It's used to test the override behavior
  40. * of the DoctrineTypeDriver so notice it, but please don't change it.
  41. *
  42. * @SerializedName("is_published")
  43. * @Groups({"post"})
  44. * @XmlAttribute
  45. */
  46. private $published;
  47. /**
  48. * @PHPCRODM\ReferenceMany(targetDocument="Comment", property="blogPost")
  49. * @XmlList(inline=true, entry="comment")
  50. * @Groups({"comments"})
  51. */
  52. private $comments;
  53. /**
  54. * @PHPCRODM\ReferenceOne(targetDocument="Author")
  55. * @Groups({"post"})
  56. */
  57. private $author;
  58. public function __construct($title, Author $author, \DateTime $createdAt)
  59. {
  60. $this->title = $title;
  61. $this->author = $author;
  62. $this->published = false;
  63. $this->comments = new ArrayCollection();
  64. $this->createdAt = $createdAt;
  65. }
  66. public function setPublished()
  67. {
  68. $this->published = true;
  69. }
  70. public function addComment(Comment $comment)
  71. {
  72. $this->comments->add($comment);
  73. }
  74. }