forked from doctrine/mongodb-odm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlogPost.php
70 lines (52 loc) · 1.89 KB
/
BlogPost.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace Documents;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use Documents\User;
/** @ODM\Document */
class BlogPost
{
/** @ODM\Id */
public $id;
/** @ODM\String */
public $name;
/** @ODM\ReferenceMany(targetDocument="Tag", inversedBy="blogPosts", cascade={"all"}) */
public $tags = array();
/** @ODM\ReferenceMany(targetDocument="Comment", mappedBy="parent", cascade={"all"}) */
public $comments = array();
/** @ODM\ReferenceOne(targetDocument="Comment", mappedBy="parent", sort={"date"="asc"}) */
public $firstComment;
/** @ODM\ReferenceOne(targetDocument="Comment", mappedBy="parent", sort={"date"="desc"}) */
public $latestComment;
/** @ODM\ReferenceMany(targetDocument="Comment", mappedBy="parent", sort={"date"="desc"}, limit=5) */
public $last5Comments = array();
/** @ODM\ReferenceMany(targetDocument="Comment", mappedBy="parent", criteria={"isByAdmin"=true}, sort={"date"="desc"}) */
public $adminComments = array();
/** @ODM\ReferenceOne(targetDocument="Comment", mappedBy="parent", repositoryMethod="findOneComment") */
public $repoComment;
/** @ODM\ReferenceMany(targetDocument="Comment", mappedBy="parent", repositoryMethod="findManyComments") */
public $repoComments;
/** @ODM\ReferenceOne(targetDocument="User", inversedBy="posts", nullable=true) */
public $user;
public function __construct($name = null)
{
$this->name = $name;
}
public function getName()
{
return $this->name;
}
public function addTag(Tag $tag)
{
$tag->addBlogPost($this); // synchronously updating inverse side
$this->tags[] = $tag;
}
public function addComment(Comment $comment)
{
$comment->parent = $this;
$this->comments[] = $comment;
}
public function setUser(User $user = null)
{
$this->user = $user;
}
}