2
2
3
3
class ResolverBlogPost extends Resolver
4
4
{
5
- public function get ($ args ) {
6
- $ this ->load ->model ('blog/post ' );
7
- $ post = $ this ->model_blog_post ->getPost ($ args ['id ' ]);
8
-
9
- if ($ post ->imageId ) {
10
- $ thumb = wp_get_attachment_image_src ($ post ->image_id , 'full ' );
11
- $ thumbLazy = wp_get_attachment_image_src ($ post ->image_id , array ( 10 , 10 ));
12
- } else {
13
- $ thumb = '' ;
14
- $ thumbLazy = '' ;
5
+ public function get ($ args )
6
+ {
7
+ $ this ->load ->model ('blog/post ' );
8
+ $ post = $ this ->model_blog_post ->getPost ($ args ['id ' ]);
9
+
10
+ if ($ post ->imageId ) {
11
+ $ thumb = wp_get_attachment_image_src ($ post ->image_id , 'full ' );
12
+ $ thumbLazy = wp_get_attachment_image_src ($ post ->image_id , array (10 , 10 ));
13
+ } else {
14
+ $ thumb = '' ;
15
+ $ thumbLazy = '' ;
15
16
}
16
-
17
+
17
18
$ keyword = str_replace (get_site_url (), '' , get_permalink ($ post ->ID ));
18
19
$ keyword = trim ($ keyword , '/? ' );
19
20
$ keyword = trim ($ keyword , '/ ' );
20
21
22
+ $ date_format = '%A %d %B %Y ' ;
23
+
21
24
return array (
22
25
'id ' => $ post ->ID ,
23
26
'name ' => $ post ->title ,
24
27
'title ' => $ post ->title ,
25
28
'shortDescription ' => $ post ->shortDescription ,
26
29
'description ' => $ post ->description ,
30
+ 'datePublished ' => iconv (mb_detect_encoding (strftime ($ date_format , strtotime ($ post ->dateAdded ))), "utf-8//IGNORE " , strftime ($ date_format , strtotime ($ post ->dateAdded ))),
27
31
'keyword ' => $ keyword ,
28
32
'image ' => $ thumb ,
29
33
'imageLazy ' => $ thumbLazy ,
30
- 'reviews ' => function ($ root , $ args ) {
34
+ 'prev ' => function ($ root , $ args ) {
35
+ return $ this ->load ->resolver ('blog/post/prev ' , array (
36
+ 'parent ' => $ root ,
37
+ 'args ' => $ args
38
+ ));
39
+ },
40
+ 'next ' => function ($ root , $ args ) {
41
+ return $ this ->load ->resolver ('blog/post/next ' , array (
42
+ 'parent ' => $ root ,
43
+ 'args ' => $ args
44
+ ));
45
+ },
46
+ 'reviews ' => function ($ root , $ args ) {
31
47
return $ this ->load ->resolver ('blog/review/get ' , array (
32
48
'parent ' => $ root ,
33
49
'args ' => $ args
@@ -36,27 +52,28 @@ public function get($args) {
36
52
);
37
53
}
38
54
39
- public function getList ($ args ) {
40
- $ this ->load ->model ('blog/post ' );
55
+ public function getList ($ args )
56
+ {
57
+ $ this ->load ->model ('blog/post ' );
41
58
$ filter_data = array (
42
59
'limit ' => $ args ['size ' ],
43
60
'start ' => ($ args ['page ' ] - 1 ) * $ args ['size ' ],
44
61
'sort ' => $ args ['sort ' ],
45
62
'order ' => $ args ['order ' ]
46
63
);
47
64
48
- if ($ args ['category_id ' ] !== 0 ) {
65
+ if ($ args ['category_id ' ] != 0 && $ args [ ' category_id ' ] != '' ) {
49
66
$ filter_data ['filter_category_id ' ] = $ args ['category_id ' ];
50
67
}
51
-
68
+
52
69
$ results = $ this ->model_blog_post ->getPosts ($ filter_data );
53
70
54
71
$ product_total = $ this ->model_blog_post ->getTotalPosts ($ filter_data );
55
72
56
73
$ posts = array ();
57
74
58
75
foreach ($ results as $ post ) {
59
- $ posts [] = $ this ->get (array ( 'id ' => $ post ->ID ));
76
+ $ posts [] = $ this ->get (array ('id ' => $ post ->ID ));
60
77
}
61
78
62
79
return array (
@@ -70,4 +87,32 @@ public function getList($args) {
70
87
'totalElements ' => (int ) $ product_total ,
71
88
);
72
89
}
73
- }
90
+
91
+ public function prev ($ args )
92
+ {
93
+ $ post_info = $ args ['parent ' ];
94
+ global $ post ;
95
+ $ post = get_post ($ post_info ['id ' ]);
96
+ $ previous_post = get_previous_post (false );
97
+
98
+ if (!$ previous_post ) {
99
+ return null ;
100
+ }
101
+
102
+ return $ this ->get (array ('id ' => $ previous_post ->ID ));
103
+ }
104
+
105
+ public function next ($ args )
106
+ {
107
+ $ post_info = $ args ['parent ' ];
108
+ global $ post ;
109
+ $ post = get_post ($ post_info ['id ' ]);
110
+ $ next_post = get_next_post (false );
111
+
112
+ if (!$ next_post ) {
113
+ return null ;
114
+ }
115
+
116
+ return $ this ->get (array ('id ' => $ next_post ->ID ));
117
+ }
118
+ }
0 commit comments