| 1 |
<?php |
| 2 |
namespace Elementor\App\Modules\KitLibrary\Data\Kits; |
| 3 |
|
| 4 |
use Elementor\App\Modules\KitLibrary\Data\Base_Controller; |
| 5 |
use Elementor\Data\V2\Base\Exceptions\Error_404; |
| 6 |
|
| 7 |
if ( ! defined( 'ABSPATH' ) ) { |
| 8 |
exit; // Exit if accessed directly. |
| 9 |
} |
| 10 |
|
| 11 |
class Controller extends Base_Controller { |
| 12 |
|
| 13 |
public function get_name() { |
| 14 |
return 'kits'; |
| 15 |
} |
| 16 |
|
| 17 |
public function get_items( $request ) { |
| 18 |
$data = $this->get_repository()->get_all( $request->get_param( 'force' ) ); |
| 19 |
|
| 20 |
return [ |
| 21 |
'data' => $data->values(), |
| 22 |
]; |
| 23 |
} |
| 24 |
|
| 25 |
public function get_item( $request ) { |
| 26 |
$data = $this->get_repository()->find( $request->get_param( 'id' ) ); |
| 27 |
|
| 28 |
if ( ! $data ) { |
| 29 |
return new Error_404( esc_html__( 'Kit not exists.', 'elementor' ), 'kit_not_exists' ); |
| 30 |
} |
| 31 |
|
| 32 |
return [ |
| 33 |
'data' => $data, |
| 34 |
]; |
| 35 |
} |
| 36 |
|
| 37 |
public function get_collection_params() { |
| 38 |
return [ |
| 39 |
'force' => [ |
| 40 |
'description' => 'Force an API request and skip the cache.', |
| 41 |
'required' => false, |
| 42 |
'default' => false, |
| 43 |
'type' => 'boolean', |
| 44 |
], |
| 45 |
]; |
| 46 |
} |
| 47 |
|
| 48 |
public function register_endpoints() { |
| 49 |
$this->index_endpoint->register_item_route( \WP_REST_Server::READABLE, [ |
| 50 |
'id' => [ |
| 51 |
'description' => 'Unique identifier for the object.', |
| 52 |
'type' => 'string', |
| 53 |
'required' => true, |
| 54 |
], |
| 55 |
'id_arg_type_regex' => '[\w]+', |
| 56 |
] ); |
| 57 |
|
| 58 |
$this->register_endpoint( new Endpoints\Download_Link( $this ) ); |
| 59 |
$this->register_endpoint( new Endpoints\Favorites( $this ) ); |
| 60 |
} |
| 61 |
|
| 62 |
public function get_permission_callback( $request ) { |
| 63 |
return current_user_can( 'manage_options' ); |
| 64 |
} |
| 65 |
} |
| 66 |
|