|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* For licensing terms, see /license.txt */ |
|
4
|
|
|
|
|
5
|
|
|
namespace Chamilo\CourseBundle\Entity; |
|
6
|
|
|
|
|
7
|
|
|
use Chamilo\CoreBundle\Entity\Course; |
|
8
|
|
|
use Chamilo\CoreBundle\Entity\Session; |
|
9
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
10
|
|
|
use Doctrine\Common\Collections\Collection; |
|
11
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
12
|
|
|
use Gedmo\Mapping\Annotation as Gedmo; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @Gedmo\Tree(type="nested") |
|
16
|
|
|
* @ORM\Table(name="c_wiki_category") |
|
17
|
|
|
* Add @ to the next line if api_get_configuration_value('wiki_categories_enabled') is true |
|
18
|
|
|
* ORM\Entity(repositoryClass="Chamilo\CourseBundle\Entity\Repository\CWikiCategoryRepository") |
|
19
|
|
|
*/ |
|
20
|
|
|
class CWikiCategory |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @var int |
|
24
|
|
|
* @ORM\Id() |
|
25
|
|
|
* @ORM\GeneratedValue() |
|
26
|
|
|
* @ORM\Column(name="id", type="integer") |
|
27
|
|
|
*/ |
|
28
|
|
|
private $id; |
|
29
|
|
|
/** |
|
30
|
|
|
* @var string |
|
31
|
|
|
* @ORM\Column(name="name", type="string") |
|
32
|
|
|
*/ |
|
33
|
|
|
private $name; |
|
34
|
|
|
/** |
|
35
|
|
|
* @var Collection<int, CWiki> |
|
36
|
|
|
* @ORM\ManyToMany(targetEntity="Chamilo\CourseBundle\Entity\CWiki", mappedBy="categories") |
|
37
|
|
|
*/ |
|
38
|
|
|
private $wikiPages; |
|
39
|
|
|
/** |
|
40
|
|
|
* @var Course |
|
41
|
|
|
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course") |
|
42
|
|
|
* @ORM\JoinColumn(name="c_id", referencedColumnName="id", nullable=false, onDelete="CASCADE") |
|
43
|
|
|
*/ |
|
44
|
|
|
private $course; |
|
45
|
|
|
/** |
|
46
|
|
|
* @var Session|null |
|
47
|
|
|
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Session") |
|
48
|
|
|
* @ORM\JoinColumn(name="session_id", referencedColumnName="id", onDelete="CASCADE") |
|
49
|
|
|
*/ |
|
50
|
|
|
private $session; |
|
51
|
|
|
/** |
|
52
|
|
|
* @var int|null |
|
53
|
|
|
* @Gedmo\TreeLeft() |
|
54
|
|
|
* @ORM\Column(name="lft", type="integer") |
|
55
|
|
|
*/ |
|
56
|
|
|
private $lft; |
|
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @var int|null |
|
59
|
|
|
* @Gedmo\TreeLevel() |
|
60
|
|
|
* @ORM\Column(name="lvl", type="integer") |
|
61
|
|
|
*/ |
|
62
|
|
|
private $lvl; |
|
63
|
|
|
/** |
|
64
|
|
|
* @var int|null |
|
65
|
|
|
* @Gedmo\TreeRight() |
|
66
|
|
|
* @ORM\Column(name="rgt", type="integer") |
|
67
|
|
|
*/ |
|
68
|
|
|
private $rgt; |
|
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @var CWikiCategory|null |
|
71
|
|
|
* @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CWikiCategory") |
|
72
|
|
|
* @ORM\JoinColumn(name="tree_root", referencedColumnName="id", onDelete="CASCADE") |
|
73
|
|
|
*/ |
|
74
|
|
|
private $root; |
|
75
|
|
|
/** |
|
76
|
|
|
* @var CWikiCategory|null |
|
77
|
|
|
* @Gedmo\TreeParent() |
|
78
|
|
|
* @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CWikiCategory", inversedBy="children") |
|
79
|
|
|
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE") |
|
80
|
|
|
*/ |
|
81
|
|
|
private $parent; |
|
82
|
|
|
/** |
|
83
|
|
|
* @var Collection<int, CWikiCategory> |
|
84
|
|
|
* @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CWikiCategory", mappedBy="parent") |
|
85
|
|
|
* @ORM\OrderBy({"lft"="ASC"}) |
|
86
|
|
|
*/ |
|
87
|
|
|
private $children; |
|
88
|
|
|
|
|
89
|
|
|
public function __construct() |
|
90
|
|
|
{ |
|
91
|
|
|
$this->parent = null; |
|
92
|
|
|
$this->children = new ArrayCollection(); |
|
93
|
|
|
$this->wikiPages = new ArrayCollection(); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function __toString() |
|
97
|
|
|
{ |
|
98
|
|
|
return $this->name; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
public function getId(): int |
|
102
|
|
|
{ |
|
103
|
|
|
return $this->id; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function getName(): string |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->name; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function getNodeName(): string |
|
112
|
|
|
{ |
|
113
|
|
|
return str_repeat(' ', $this->lvl).$this->name; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
public function setName(string $name): CWikiCategory |
|
117
|
|
|
{ |
|
118
|
|
|
$this->name = $name; |
|
119
|
|
|
|
|
120
|
|
|
return $this; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
public function getCourse(): Course |
|
124
|
|
|
{ |
|
125
|
|
|
return $this->course; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
public function setCourse(Course $course): CWikiCategory |
|
129
|
|
|
{ |
|
130
|
|
|
$this->course = $course; |
|
131
|
|
|
|
|
132
|
|
|
return $this; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
public function getSession(): ?Session |
|
136
|
|
|
{ |
|
137
|
|
|
return $this->session; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
public function setSession(?Session $session): CWikiCategory |
|
141
|
|
|
{ |
|
142
|
|
|
$this->session = $session; |
|
143
|
|
|
|
|
144
|
|
|
return $this; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
public function getRoot(): ?CWikiCategory |
|
148
|
|
|
{ |
|
149
|
|
|
return $this->root; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
public function getParent(): ?CWikiCategory |
|
153
|
|
|
{ |
|
154
|
|
|
return $this->parent; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
public function setParent(?CWikiCategory $parent): CWikiCategory |
|
158
|
|
|
{ |
|
159
|
|
|
$this->parent = $parent; |
|
160
|
|
|
|
|
161
|
|
|
return $this; |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
public function getChildren(): Collection |
|
165
|
|
|
{ |
|
166
|
|
|
return $this->children; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
public function setChildren(Collection $children): CWikiCategory |
|
170
|
|
|
{ |
|
171
|
|
|
$this->children = $children; |
|
172
|
|
|
|
|
173
|
|
|
return $this; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
public function addWikiPage(CWiki $page): CWikiCategory |
|
177
|
|
|
{ |
|
178
|
|
|
$this->wikiPages->add($page); |
|
179
|
|
|
|
|
180
|
|
|
return $this; |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
public function getWikiPages(): Collection |
|
184
|
|
|
{ |
|
185
|
|
|
return $this->wikiPages; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
public function getLvl(): ?int |
|
189
|
|
|
{ |
|
190
|
|
|
return $this->lvl; |
|
191
|
|
|
} |
|
192
|
|
|
} |
|
193
|
|
|
|