| 1 |
<?php |
| 2 |
class LP_REST_Orders_Controller extends LP_Abstract_REST_Controller { |
| 3 |
public function __construct() { |
| 4 |
$this->namespace = 'lp/v1'; |
| 5 |
$this->rest_base = 'orders'; |
| 6 |
|
| 7 |
parent::__construct(); |
| 8 |
} |
| 9 |
|
| 10 |
public function register_routes() { |
| 11 |
$this->routes = array( |
| 12 |
'statistic' => array( |
| 13 |
array( |
| 14 |
'methods' => WP_REST_Server::READABLE, |
| 15 |
'callback' => array( $this, 'statistic' ), |
| 16 |
'permission_callback' => '__return_true', |
| 17 |
), |
| 18 |
), |
| 19 |
); |
| 20 |
|
| 21 |
parent::register_routes(); |
| 22 |
} |
| 23 |
|
| 24 |
public function statistic( WP_REST_Request $request ) { |
| 25 |
|
| 26 |
$response = new LP_REST_Response(); |
| 27 |
$response->data = ''; |
| 28 |
|
| 29 |
$order_statuses = learn_press_get_order_statuses( true, true ); |
| 30 |
$specific_statuses = array( 'lp-completed', 'lp-failed' ); |
| 31 |
|
| 32 |
foreach ( $order_statuses as $status ) { |
| 33 |
if ( ! in_array( $status, $specific_statuses ) ) { |
| 34 |
$specific_statuses[] = $status; |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
try { |
| 39 |
$response->data = learn_press_get_template_content( 'admin/views/dashboard/html-orders', compact( 'specific_statuses' ), '', LP_PLUGIN_PATH . 'inc/' ); |
| 40 |
$response->status = 'success'; |
| 41 |
|
| 42 |
} catch ( Exception $e ) { |
| 43 |
$response->message = $e->getMessage(); |
| 44 |
} |
| 45 |
|
| 46 |
return rest_ensure_response( $response ); |
| 47 |
} |
| 48 |
|
| 49 |
} |
| 50 |
|