File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88use DateTimeInterface ;
99use DOMDocument ;
1010use DOMElement ;
11- use Light \Blog \Enum \PostStatusEnum ;
1211use Light \Blog \Repository \PostRepository ;
1312use RuntimeException ;
1413
@@ -37,10 +36,7 @@ public function getFeedFile(): string
3736
3837 public function write (): int
3938 {
40- $ posts = $ this ->postRepository ->findBy (
41- ['status ' => PostStatusEnum::Published],
42- ['postDate ' => 'DESC ' ]
43- );
39+ $ posts = $ this ->postRepository ->getPublishedPosts ();
4440
4541 $ dom = new DOMDocument ('1.0 ' , 'UTF-8 ' );
4642 $ dom ->formatOutput = true ;
Original file line number Diff line number Diff line change @@ -100,6 +100,21 @@ public function getAdjacentPosts(Post $post): array
100100 return ['previous ' => $ previous , 'next ' => $ next ];
101101 }
102102
103+ /**
104+ * @return array<int, Post>
105+ */
106+ public function getPublishedPosts (): array
107+ {
108+ return $ this ->getQueryBuilder ()
109+ ->select ('articles ' )
110+ ->from (Post::class, 'articles ' )
111+ ->where ('articles.status = :published ' )
112+ ->setParameter ('published ' , PostStatusEnum::Published)
113+ ->orderBy ('articles.postDate ' , 'DESC ' )
114+ ->getQuery ()
115+ ->getResult ();
116+ }
117+
103118 /**
104119 * @return array<int, Post>
105120 */
You can’t perform that action at this time.
0 commit comments