| 1 |
<?php |
| 2 |
namespace Elementor\Modules\Checklist\Data\Endpoints; |
| 3 |
|
| 4 |
use Elementor\Data\V2\Base\Endpoint as Endpoint_Base; |
| 5 |
use Elementor\Modules\Checklist\Module as Checklist_Module; |
| 6 |
|
| 7 |
if ( ! defined( 'ABSPATH' ) ) { |
| 8 |
exit; // Exit if accessed directly. |
| 9 |
} |
| 10 |
|
| 11 |
class User_Progress extends Endpoint_Base { |
| 12 |
protected function register() { |
| 13 |
parent::register(); |
| 14 |
|
| 15 |
$this->register_items_route( \WP_REST_Server::EDITABLE ); |
| 16 |
} |
| 17 |
|
| 18 |
public function get_name(): string { |
| 19 |
return 'user-progress'; |
| 20 |
} |
| 21 |
|
| 22 |
public function get_format(): string { |
| 23 |
return 'checklist'; |
| 24 |
} |
| 25 |
|
| 26 |
public function get_items( $request ) { |
| 27 |
return $this->get_checklist_data(); |
| 28 |
} |
| 29 |
|
| 30 |
public function update_items( $request ) { |
| 31 |
Checklist_Module::instance()->update_user_progress( $request->get_json_params() ); |
| 32 |
|
| 33 |
return [ |
| 34 |
'data' => 'success', |
| 35 |
]; |
| 36 |
} |
| 37 |
|
| 38 |
private function get_checklist_data(): array { |
| 39 |
$checklist_module = Checklist_Module::instance(); |
| 40 |
$progress_data = $checklist_module->get_user_progress_from_db(); |
| 41 |
|
| 42 |
return [ |
| 43 |
'data' => $progress_data, |
| 44 |
]; |
| 45 |
} |
| 46 |
} |
| 47 |
|