|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Application; |
|
6
|
|
|
use WP_Error; |
|
7
|
|
|
use WP_REST_Post_Meta_Fields; |
|
8
|
|
|
use WP_REST_Posts_Controller as RestController; |
|
9
|
|
|
use WP_REST_Request as Request; |
|
10
|
|
|
use WP_REST_Response as Response; |
|
11
|
|
|
use WP_REST_Server as Server; |
|
12
|
|
|
|
|
13
|
|
|
class RestReviewController extends RestController |
|
14
|
|
|
{ |
|
15
|
|
|
public function __construct() |
|
16
|
|
|
{ |
|
17
|
|
|
$this->meta = new WP_REST_Post_Meta_Fields(Application::POST_TYPE); |
|
18
|
|
|
$this->namespace = Application::ID.'/v1'; |
|
19
|
|
|
$this->post_type = Application::POST_TYPE; |
|
20
|
|
|
$this->rest_base = 'reviews'; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @return void |
|
25
|
|
|
*/ |
|
26
|
|
|
public function register_routes() |
|
27
|
|
|
{ |
|
28
|
|
|
// register_rest_route( $this->namespace, '/'.$this->rest_base, [ |
|
29
|
|
|
// ['callback' => [$this, 'createReview'], 'methods' => Server::CREATABLE], |
|
30
|
|
|
// ['callback' => [$this, 'getReviews'], 'methods' => Server::READABLE], |
|
31
|
|
|
// ]); |
|
32
|
|
|
register_rest_route($this->namespace, '/types', [ |
|
33
|
|
|
['callback' => [$this, 'getReviewTypes'], 'methods' => Server::READABLE], |
|
34
|
|
|
]); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @return WP_Error|Response|mixed |
|
39
|
|
|
*/ |
|
40
|
|
|
public function createReview() |
|
41
|
|
|
{ |
|
42
|
|
|
$response = []; |
|
43
|
|
|
return rest_ensure_response($response); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return WP_Error|Response|mixed |
|
48
|
|
|
*/ |
|
49
|
|
|
public function getReviews() |
|
50
|
|
|
{ |
|
51
|
|
|
$response = []; |
|
52
|
|
|
return rest_ensure_response($response); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @return WP_Error|Response|mixed |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getReviewTypes() |
|
59
|
|
|
{ |
|
60
|
|
|
$response = []; |
|
61
|
|
|
foreach (glsr()->reviewTypes as $slug => $name) { |
|
62
|
|
|
$response[] = [ |
|
63
|
|
|
'name' => $name, |
|
64
|
|
|
'slug' => $slug, |
|
65
|
|
|
]; |
|
66
|
|
|
} |
|
67
|
|
|
return rest_ensure_response($response); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|