@@ -6,7 +6,8 @@ class ResolverBlogPost extends Resolver
66{
77 private $ blog = false ;
88
9- public function __construct ($ registry ) {
9+ public function __construct ($ registry )
10+ {
1011 parent ::__construct ($ registry );
1112 $ moduleManager = \Magento \Framework \App \ObjectManager::getInstance ()->get ('\Magento\Framework\Module\Manager ' );
1213
@@ -26,16 +27,42 @@ public function get($args)
2627 $ thumb = '' ;
2728 $ thumbLazy = '' ;
2829 }
29-
30+
31+ $ date_format = '%A %d %B %Y ' ;
3032
3133 return array (
3234 'id ' => $ post ['post_id ' ],
35+ 'name ' => $ post ['title ' ],
3336 'title ' => $ post ['title ' ],
3437 'shortDescription ' => $ post ['short_content ' ],
3538 'description ' => $ post ['content ' ],
3639 'keyword ' => $ post ['identifier ' ],
3740 'image ' => $ thumb ,
3841 'imageLazy ' => $ thumbLazy ,
42+ 'rating ' => null ,
43+ 'datePublished ' => iconv (
44+ mb_detect_encoding (strftime ($ date_format , strtotime ($ post ['publish_time ' ]))),
45+ "utf-8//IGNORE " ,
46+ strftime ($ date_format , strtotime ($ post ['publish_time ' ]))
47+ ),
48+ 'categories ' => function ($ root , $ args ) {
49+ return $ this ->load ->resolver ('blog/post/categories ' , array (
50+ 'parent ' => $ root ,
51+ 'args ' => $ args
52+ ));
53+ },
54+ 'next ' => function ($ root , $ args ) {
55+ return $ this ->load ->resolver ('blog/post/next ' , array (
56+ 'parent ' => $ root ,
57+ 'args ' => $ args
58+ ));
59+ },
60+ 'prev ' => function ($ root , $ args ) {
61+ return $ this ->load ->resolver ('blog/post/prev ' , array (
62+ 'parent ' => $ root ,
63+ 'args ' => $ args
64+ ));
65+ },
3966 'reviews ' => function ($ root , $ args ) {
4067 return $ this ->load ->resolver ('blog/review/get ' , array (
4168 'parent ' => $ root ,
@@ -88,4 +115,56 @@ public function getList($args)
88115 );
89116 }
90117 }
118+ public function categories ($ args )
119+ {
120+ if ($ this ->blog ) {
121+ $ this ->load ->model ('blog/category ' );
122+ $ post = $ args ['parent ' ];
123+
124+ $ result = $ this ->model_blog_category ->getCategoryByPostId ($ post ['id ' ]);
125+ $ categories = array ();
126+ foreach ($ result as $ category ) {
127+ $ categories [] =$ this ->load ->resolver (
128+ 'blog/category/get ' ,
129+ array ('id ' => $ category ['category_id ' ])
130+ );
131+ }
132+ return $ categories ;
133+ } else {
134+ return array ();
135+ }
136+ }
137+
138+
139+ public function prev ($ args )
140+ {
141+ if ($ this ->blog ) {
142+ $ this ->load ->model ('blog/post ' );
143+ $ post = $ args ['parent ' ];
144+ $ prev_post_info = $ this ->model_blog_post ->getPrevPost ($ post ['id ' ]);
145+ if (empty ($ prev_post_info )) {
146+ return null ;
147+ }
148+ return $ this ->get (array ('id ' => $ prev_post_info ['post_id ' ]));
149+ } else {
150+ return array ();
151+ }
152+ }
153+
154+ public function next ($ args )
155+ {
156+ if ($ this ->blog ) {
157+ $ this ->load ->model ('blog/post ' );
158+ $ post = $ args ['parent ' ];
159+
160+
161+ $ next_post_info = $ this ->model_blog_post ->getNextPost ($ post ['id ' ]);
162+ if (empty ($ next_post_info )) {
163+ return null ;
164+ }
165+ return $ this ->get (array ('id ' => $ next_post_info ['post_id ' ]));
166+ } else {
167+ return array ();
168+ }
169+ }
91170}
0 commit comments