11<?php
22
33namespace TapestryCloud \Database \Entities ;
4+
45use Doctrine \Common \Collections \ArrayCollection ;
56use Doctrine \Common \Collections \Collection ;
7+ use Tapestry \Modules \Content \FrontMatter as TapestryFrontMatter ;
68
79/**
810 * @Entity
@@ -12,12 +14,56 @@ class File
1214{
1315 /**
1416 * @var int
15- * @Id @Column(type="integer") @GeneratedValue */
17+ * @Id @Column(type="integer") @GeneratedValue
18+ */
1619 private $ id ;
1720
21+ /**
22+ * @var string
23+ * @Column(type="string")
24+ */
25+ private $ uid ;
26+
27+ /**
28+ * @var int
29+ * @Column(type="integer")
30+ */
31+ private $ lastModified ;
32+
33+ /**
34+ * @var string
35+ * @Column(type="string")
36+ */
37+ private $ filename ;
38+
39+ /**
40+ * @var string
41+ * @Column(type="string")
42+ */
43+ private $ ext ;
44+
45+ /**
46+ * @var string
47+ * @Column(type="string")
48+ */
49+ private $ path ;
50+
51+ /**
52+ * @var string
53+ * @Column(type="text")
54+ */
55+ private $ content ;
56+
57+ /**
58+ * @var bool
59+ * @Column(type="boolean")
60+ */
61+ private $ toCopy ;
62+
1863 /**
1964 * @var Environment
20- * @ManyToOne(targetEntity="Environment") */
65+ * @ManyToOne(targetEntity="Environment")
66+ */
2167 private $ environment ;
2268
2369 /**
@@ -37,16 +83,18 @@ class File
3783 private $ classifications ;
3884
3985 /**
40- * @var string
41- * @Column(type="string") */
42- private $ uid ;
86+ * @var Collection|FrontMatter[]
87+ * @OneToMany(targetEntity="FrontMatter", mappedBy="file_id")
88+ */
89+ private $ frontMatter ;
4390
4491 /**
4592 * File constructor.
4693 */
4794 public function __construct ()
4895 {
4996 $ this ->classifications = new ArrayCollection ();
97+ $ this ->frontMatter = new ArrayCollection ();
5098 }
5199
52100 /**
@@ -55,26 +103,34 @@ public function __construct()
55103 * @param \Tapestry\Entities\File $file
56104 * @param Environment|null $environment
57105 */
58- public function hydrate (\Tapestry \Entities \File $ file , Environment $ environment = null ) {
59- $ this ->uid = $ file ->getUid ();
106+ public function hydrate (\Tapestry \Entities \File $ file , Environment $ environment = null )
107+ {
108+ $ this ->setUid ($ file ->getUid ());
109+ $ this ->setLastModified ($ file ->getLastModified ());
110+ $ this ->setFilename ($ file ->getFilename ());
111+ $ this ->setExt ($ file ->getExt ());
112+ $ this ->setPath ($ file ->getPath ());
113+ $ this ->setToCopy ($ file ->isToCopy ());
114+
115+ if (! $ file ->isToCopy ()) {
116+ $ frontMatter = new TapestryFrontMatter ($ file ->getFileContent ());
117+ $ this ->setContent ($ frontMatter ->getContent ());
118+ foreach ($ frontMatter ->getData () as $ key => $ value ) {
119+ $ fmRecord = new FrontMatter ();
120+ $ fmRecord ->setName ($ key );
121+ $ fmRecord ->setValue ($ value );
122+ $ this ->addFrontMatter ($ fmRecord );
123+ }
124+ }
60125
61126 if (!is_null ($ environment )) {
62127 $ this ->setEnvironment ($ environment );
63128 }
64129 }
65130
66- /**
67- * @return string
68- */
69- public function getUid ()
70- {
71- return $ this ->uid ;
72- }
73-
74- public function setUid ($ uid )
75- {
76- $ this ->uid = $ uid ;
77- }
131+ //
132+ // Relationships
133+ //
78134
79135 /**
80136 * @return Environment
@@ -92,6 +148,14 @@ public function setEnvironment(Environment $environment)
92148 $ this ->environment = $ environment ;
93149 }
94150
151+ public function addFrontMatter (FrontMatter $ frontMatter ) {
152+ if ($ this ->frontMatter ->contains ($ frontMatter )) {
153+ return ;
154+ }
155+
156+ $ this ->frontMatter ->add ($ frontMatter );
157+ }
158+
95159 /**
96160 * @param Classification $classification
97161 */
@@ -115,4 +179,117 @@ public function removeClassification(Classification $classification)
115179
116180 $ this ->classifications ->removeElement ($ classification );
117181 }
182+
183+ //
184+ // Getters & Setters
185+ //
186+
187+ /**
188+ * @return string
189+ */
190+ public function getUid ()
191+ {
192+ return $ this ->uid ;
193+ }
194+
195+ public function setUid ($ uid )
196+ {
197+ $ this ->uid = $ uid ;
198+ }
199+
200+ /**
201+ * @return int
202+ */
203+ public function getLastModified ()
204+ {
205+ return $ this ->lastModified ;
206+ }
207+
208+ /**
209+ * @param int $lastModified
210+ */
211+ public function setLastModified ($ lastModified )
212+ {
213+ $ this ->lastModified = $ lastModified ;
214+ }
215+
216+ /**
217+ * @return bool
218+ */
219+ public function isToCopy ()
220+ {
221+ return $ this ->toCopy ;
222+ }
223+
224+ /**
225+ * @param bool $toCopy
226+ */
227+ public function setToCopy ($ toCopy )
228+ {
229+ $ this ->toCopy = $ toCopy ;
230+ }
231+
232+ /**
233+ * @return string
234+ */
235+ public function getFilename ()
236+ {
237+ return $ this ->filename ;
238+ }
239+
240+ /**
241+ * @param string $filename
242+ */
243+ public function setFilename ($ filename )
244+ {
245+ $ this ->filename = $ filename ;
246+ }
247+
248+ /**
249+ * @return string
250+ */
251+ public function getExt ()
252+ {
253+ return $ this ->ext ;
254+ }
255+
256+ /**
257+ * @param string $ext
258+ */
259+ public function setExt ($ ext )
260+ {
261+ $ this ->ext = $ ext ;
262+ }
263+
264+ /**
265+ * @return string
266+ */
267+ public function getPath ()
268+ {
269+ return $ this ->path ;
270+ }
271+
272+ /**
273+ * @param string $path
274+ */
275+ public function setPath ($ path )
276+ {
277+ $ this ->path = $ path ;
278+ }
279+
280+ /**
281+ * @return string
282+ */
283+ public function getContent ()
284+ {
285+ return $ this ->content ;
286+ }
287+
288+ /**
289+ * @param string $content
290+ */
291+ public function setContent ($ content )
292+ {
293+ $ this ->content = $ content ;
294+ }
118295}
0 commit comments