| 1 |
<?php |
| 2 |
|
| 3 |
namespace Leadin\admin\api; |
| 4 |
|
| 5 |
use Leadin\api\Base_Api_Controller; |
| 6 |
use Leadin\admin\Connection; |
| 7 |
use Leadin\data\Portal_Options; |
| 8 |
|
| 9 |
/** |
| 10 |
* Portal Api, used to clean portal id and domain from the WordPress options. |
| 11 |
*/ |
| 12 |
class Portal_Api_Controller extends Base_Api_Controller { |
| 13 |
|
| 14 |
/** |
| 15 |
* Class constructor, register route. |
| 16 |
*/ |
| 17 |
public function __construct() { |
| 18 |
self::register_leadin_admin_route( |
| 19 |
'/business-unit', |
| 20 |
\WP_REST_Server::READABLE, |
| 21 |
array( $this, 'get_business_unit_option' ) |
| 22 |
); |
| 23 |
self::register_leadin_admin_route( |
| 24 |
'/business-unit', |
| 25 |
\WP_REST_Server::EDITABLE, |
| 26 |
array( $this, 'set_business_unit_option' ) |
| 27 |
); |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Get business unit id option. |
| 32 |
* |
| 33 |
* @return string Business Unit Id |
| 34 |
*/ |
| 35 |
public function get_business_unit_option() { |
| 36 |
return new \WP_REST_Response( Portal_Options::get_business_unit_id(), 200 ); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Set business unit id option. |
| 41 |
* |
| 42 |
* @param number $request Request body. |
| 43 |
* |
| 44 |
* @return string OK response message. |
| 45 |
*/ |
| 46 |
public function set_business_unit_option( $request ) { |
| 47 |
$data = json_decode( $request->get_body(), true ); |
| 48 |
$business_unit_id = $data['businessUnitId']; |
| 49 |
Portal_Options::set_business_unit_id( $business_unit_id ); |
| 50 |
return new \WP_REST_Response( 'OK', 200 ); |
| 51 |
} |
| 52 |
|
| 53 |
} |
| 54 |
|