| 1 |
<?php |
| 2 |
|
| 3 |
namespace IvyForms\Routes\Entry; |
| 4 |
|
| 5 |
use IvyForms\Vendor\DI\Container; |
| 6 |
use IvyForms\Vendor\DI\DependencyException; |
| 7 |
use IvyForms\Vendor\DI\NotFoundException; |
| 8 |
use IvyForms\Controllers\Entry\AddEntryController; |
| 9 |
use IvyForms\Controllers\Entry\BulkUpdateEntryController; |
| 10 |
use IvyForms\Controllers\Entry\DeleteEntriesController; |
| 11 |
use IvyForms\Controllers\Entry\DeleteEntryController; |
| 12 |
use IvyForms\Controllers\Entry\GetEntryController; |
| 13 |
use IvyForms\Controllers\Entry\GetEntryCountController; |
| 14 |
use IvyForms\Controllers\Entry\SearchEntriesController; |
| 15 |
use IvyForms\Controllers\Entry\UpdateEntryStarredController; |
| 16 |
use IvyForms\Controllers\Entry\UpdateEntryStatusController; |
| 17 |
use WP_REST_Server; |
| 18 |
|
| 19 |
class Entry |
| 20 |
{ |
| 21 |
/** |
| 22 |
* @throws DependencyException |
| 23 |
* @throws NotFoundException |
| 24 |
*/ |
| 25 |
public static function registerRoutes(Container $container, string $routeNamespace): void |
| 26 |
{ |
| 27 |
// TODO - Add IvyForms capability - Admin only for now |
| 28 |
register_rest_route( |
| 29 |
$routeNamespace, |
| 30 |
'/entry/(?P<id>\d+)', |
| 31 |
[ |
| 32 |
'methods' => WP_REST_Server::READABLE, |
| 33 |
'callback' => $container->get(GetEntryController::class), |
| 34 |
'permission_callback' => function () { |
| 35 |
return current_user_can('manage_options'); |
| 36 |
} |
| 37 |
] |
| 38 |
); |
| 39 |
|
| 40 |
register_rest_route( |
| 41 |
$routeNamespace, |
| 42 |
'/entry/add/', |
| 43 |
[ |
| 44 |
'methods' => WP_REST_Server::CREATABLE, |
| 45 |
'callback' => $container->get(AddEntryController::class), |
| 46 |
'permission_callback' => function () { |
| 47 |
return current_user_can('manage_options'); |
| 48 |
} |
| 49 |
] |
| 50 |
); |
| 51 |
|
| 52 |
register_rest_route( |
| 53 |
$routeNamespace, |
| 54 |
'/entries/search', |
| 55 |
[ |
| 56 |
'methods' => WP_REST_Server::READABLE, |
| 57 |
'callback' => $container->get(SearchEntriesController::class), |
| 58 |
'permission_callback' => function () { |
| 59 |
return current_user_can('manage_options'); |
| 60 |
} |
| 61 |
] |
| 62 |
); |
| 63 |
|
| 64 |
register_rest_route( |
| 65 |
$routeNamespace, |
| 66 |
'/entries/delete', |
| 67 |
[ |
| 68 |
'methods' => WP_REST_Server::CREATABLE, |
| 69 |
'callback' => $container->get(DeleteEntriesController::class), |
| 70 |
'permission_callback' => function () { |
| 71 |
return current_user_can('manage_options'); |
| 72 |
} |
| 73 |
] |
| 74 |
); |
| 75 |
register_rest_route( |
| 76 |
$routeNamespace, |
| 77 |
'/entry/delete/(?P<id>\d+)', |
| 78 |
[ |
| 79 |
'methods' => WP_REST_Server::CREATABLE, |
| 80 |
'callback' => $container->get(DeleteEntryController::class), |
| 81 |
'permission_callback' => function () { |
| 82 |
return current_user_can('manage_options'); |
| 83 |
} |
| 84 |
] |
| 85 |
); |
| 86 |
|
| 87 |
register_rest_route( |
| 88 |
$routeNamespace, |
| 89 |
'/entry/update/starred/(?P<id>\d+)', |
| 90 |
[ |
| 91 |
'methods' => WP_REST_Server::CREATABLE, |
| 92 |
'callback' => $container->get(UpdateEntryStarredController::class), |
| 93 |
'permission_callback' => function () { |
| 94 |
return current_user_can('manage_options'); |
| 95 |
} |
| 96 |
] |
| 97 |
); |
| 98 |
|
| 99 |
register_rest_route( |
| 100 |
$routeNamespace, |
| 101 |
'/entry/update/status/(?P<id>\d+)', |
| 102 |
[ |
| 103 |
'methods' => WP_REST_Server::CREATABLE, |
| 104 |
'callback' => $container->get(UpdateEntryStatusController::class), |
| 105 |
'permission_callback' => function () { |
| 106 |
return current_user_can('manage_options'); |
| 107 |
} |
| 108 |
] |
| 109 |
); |
| 110 |
|
| 111 |
register_rest_route( |
| 112 |
$routeNamespace, |
| 113 |
'/entries/count', |
| 114 |
[ |
| 115 |
'methods' => WP_REST_Server::READABLE, |
| 116 |
'callback' => $container->get(GetEntryCountController::class), |
| 117 |
'permission_callback' => function () { |
| 118 |
return current_user_can('manage_options'); |
| 119 |
} |
| 120 |
] |
| 121 |
); |
| 122 |
|
| 123 |
register_rest_route( |
| 124 |
$routeNamespace, |
| 125 |
'/entries/batch-actions', |
| 126 |
[ |
| 127 |
'methods' => WP_REST_Server::CREATABLE, |
| 128 |
'callback' => [$container->get(BulkUpdateEntryController::class), 'handle'], |
| 129 |
'permission_callback' => function () { |
| 130 |
return current_user_can('manage_options'); |
| 131 |
} |
| 132 |
] |
| 133 |
); |
| 134 |
} |
| 135 |
} |
| 136 |
|