first commit
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
namespace Elementor\Modules\CloudKitLibrary\Data;
|
||||
|
||||
use Elementor\Modules\CloudKitLibrary\Connect\Cloud_Kits;
|
||||
use Elementor\Modules\CloudKitLibrary\Module as CloudKitLibrary;
|
||||
use Elementor\App\Modules\KitLibrary\Data\Base_Controller;
|
||||
use Elementor\Core\Utils\Collection;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class Controller extends Base_Controller {
|
||||
|
||||
public function get_name() {
|
||||
return 'cloud-kits';
|
||||
}
|
||||
|
||||
public function get_items( $request ) {
|
||||
$data = $this->get_app()->get_all();
|
||||
|
||||
if ( is_wp_error( $data ) ) {
|
||||
return [
|
||||
'data' => [],
|
||||
];
|
||||
}
|
||||
|
||||
$kits = ( new Collection( $data ) )->map( function ( $kit ) {
|
||||
return [
|
||||
'id' => $kit['id'],
|
||||
'title' => $kit['title'],
|
||||
'thumbnail_url' => $kit['thumbnailUrl'],
|
||||
'created_at' => $kit['createdAt'],
|
||||
'updated_at' => $kit['updatedAt'],
|
||||
];
|
||||
} );
|
||||
|
||||
return [
|
||||
'data' => $kits->values(),
|
||||
];
|
||||
}
|
||||
|
||||
public function delete_item( $request ) {
|
||||
return [
|
||||
'data' => $this->get_app()->delete_kit( $request->get_param( 'id' ) ),
|
||||
];
|
||||
}
|
||||
|
||||
public function get_item( $request ) {
|
||||
return [
|
||||
'data' => $this->get_app()->get_kit( [ 'id' => $request->get_param( 'id' ) ] ),
|
||||
];
|
||||
}
|
||||
|
||||
public function register_endpoints() {
|
||||
$this->index_endpoint->register_item_route( \WP_REST_Server::DELETABLE, [
|
||||
'id' => [
|
||||
'description' => 'Unique identifier for the object.',
|
||||
'type' => 'integer',
|
||||
'required' => true,
|
||||
],
|
||||
] );
|
||||
|
||||
$this->register_endpoint( new Endpoints\Eligibility( $this ) );
|
||||
}
|
||||
|
||||
public function get_permission_callback( $request ) {
|
||||
return current_user_can( 'manage_options' );
|
||||
}
|
||||
|
||||
protected function get_app(): Cloud_Kits {
|
||||
return CloudKitLibrary::get_app();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace Elementor\Modules\CloudKitLibrary\Data\Endpoints;
|
||||
|
||||
use Elementor\Modules\CloudKitLibrary\Data\Controller;
|
||||
use Elementor\Modules\CloudKitLibrary\Module as CloudKitLibrary;
|
||||
use Elementor\Data\V2\Base\Endpoint;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* @property Controller $controller
|
||||
*/
|
||||
class Eligibility extends Endpoint {
|
||||
public function get_name() {
|
||||
return 'eligibility';
|
||||
}
|
||||
|
||||
public function get_format() {
|
||||
return 'cloud-kits/eligibility';
|
||||
}
|
||||
|
||||
public function get_items( $request ) {
|
||||
return CloudKitLibrary::get_app()->check_eligibility();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user