| 1 |
<?php |
| 2 |
/** |
| 3 |
* Controls Tasks |
| 4 |
*/ |
| 5 |
|
| 6 |
namespace Extendify\Assist\Controllers; |
| 7 |
|
| 8 |
use Extendify\Http; |
| 9 |
|
| 10 |
if (!defined('ABSPATH')) { |
| 11 |
die('No direct access.'); |
| 12 |
} |
| 13 |
|
| 14 |
/** |
| 15 |
* The controller for plugin dependency checking, etc |
| 16 |
*/ |
| 17 |
class TasksController |
| 18 |
{ |
| 19 |
|
| 20 |
/** |
| 21 |
* Return tasks from either database or source. |
| 22 |
* |
| 23 |
* @return \WP_REST_Response |
| 24 |
*/ |
| 25 |
public static function fetchTasks() |
| 26 |
{ |
| 27 |
$response = Http::get('/tasks'); |
| 28 |
return new \WP_REST_Response( |
| 29 |
$response, |
| 30 |
wp_remote_retrieve_response_code($response) |
| 31 |
); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Return the data |
| 36 |
* |
| 37 |
* @return \WP_REST_Response |
| 38 |
*/ |
| 39 |
public static function get() |
| 40 |
{ |
| 41 |
$data = get_option('extendify_assist_tasks', []); |
| 42 |
return new \WP_REST_Response($data); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Persist the data |
| 47 |
* |
| 48 |
* @param \WP_REST_Request $request - The request. |
| 49 |
* @return \WP_REST_Response |
| 50 |
*/ |
| 51 |
public static function store($request) |
| 52 |
{ |
| 53 |
$data = json_decode($request->get_param('data'), true); |
| 54 |
update_option('extendify_assist_tasks', $data); |
| 55 |
return new \WP_REST_Response($data); |
| 56 |
} |
| 57 |
} |
| 58 |
|