| 1 |
<?php |
| 2 |
|
| 3 |
namespace WeDevs\ERP\HRM\API; |
| 4 |
|
| 5 |
use WP_REST_Server; |
| 6 |
use WP_REST_Response; |
| 7 |
use WP_Error; |
| 8 |
use WeDevs\ERP\API\REST_Controller; |
| 9 |
|
| 10 |
class Company_Controller extends REST_Controller { |
| 11 |
/** |
| 12 |
* Endpoint namespace. |
| 13 |
* |
| 14 |
* @var string |
| 15 |
*/ |
| 16 |
protected $namespace = 'erp/v1'; |
| 17 |
|
| 18 |
/** |
| 19 |
* Route base. |
| 20 |
* |
| 21 |
* @var string |
| 22 |
*/ |
| 23 |
protected $rest_base = 'hrm/company'; |
| 24 |
|
| 25 |
/** |
| 26 |
* Register the routes for the objects of the controller. |
| 27 |
*/ |
| 28 |
public function register_routes() { |
| 29 |
register_rest_route( $this->namespace, '/' . $this->rest_base . '/company-locations', [ |
| 30 |
[ |
| 31 |
'methods' => WP_REST_Server::READABLE, |
| 32 |
'callback' => [ $this, 'get_company_locations' ], |
| 33 |
'args' => $this->get_collection_params(), |
| 34 |
'permission_callback' => function ( $request ) { |
| 35 |
return current_user_can( 'erp_view_list' ); |
| 36 |
}, |
| 37 |
], |
| 38 |
'schema' => [ $this, 'get_public_item_schema' ], |
| 39 |
] ); |
| 40 |
|
| 41 |
register_rest_route( $this->namespace, '/' . $this->rest_base . '/employee-statuses', [ |
| 42 |
[ |
| 43 |
'methods' => WP_REST_Server::READABLE, |
| 44 |
'callback' => [ $this, 'get_employee_statuses' ], |
| 45 |
'args' => $this->get_collection_params(), |
| 46 |
'permission_callback' => function ( $request ) { |
| 47 |
return current_user_can( 'erp_list_employee' ); |
| 48 |
}, |
| 49 |
], |
| 50 |
'schema' => [ $this, 'get_public_item_schema' ], |
| 51 |
] ); |
| 52 |
|
| 53 |
register_rest_route( $this->namespace, '/' . $this->rest_base . '/employee-types', [ |
| 54 |
[ |
| 55 |
'methods' => WP_REST_Server::READABLE, |
| 56 |
'callback' => [ $this, 'get_employee_types' ], |
| 57 |
'args' => $this->get_collection_params(), |
| 58 |
'permission_callback' => function ( $request ) { |
| 59 |
return current_user_can( 'erp_view_list' ); |
| 60 |
}, |
| 61 |
], |
| 62 |
'schema' => [ $this, 'get_public_item_schema' ], |
| 63 |
] ); |
| 64 |
|
| 65 |
register_rest_route( $this->namespace, '/' . $this->rest_base . '/pay-types', [ |
| 66 |
[ |
| 67 |
'methods' => WP_REST_Server::READABLE, |
| 68 |
'callback' => [ $this, 'get_employee_pay_types' ], |
| 69 |
'args' => $this->get_collection_params(), |
| 70 |
'permission_callback' => function ( $request ) { |
| 71 |
return current_user_can( 'erp_view_list' ); |
| 72 |
}, |
| 73 |
], |
| 74 |
'schema' => [ $this, 'get_public_item_schema' ], |
| 75 |
] ); |
| 76 |
register_rest_route( $this->namespace, '/' . $this->rest_base . '/hiring-sources', [ |
| 77 |
[ |
| 78 |
'methods' => WP_REST_Server::READABLE, |
| 79 |
'callback' => [ $this, 'get_source_of_hire' ], |
| 80 |
'args' => $this->get_collection_params(), |
| 81 |
'permission_callback' => function ( $request ) { |
| 82 |
return current_user_can( 'erp_view_list' ); |
| 83 |
}, |
| 84 |
], |
| 85 |
'schema' => [ $this, 'get_public_item_schema' ], |
| 86 |
] ); |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* Get company locations |
| 91 |
* |
| 92 |
* @since 1.3.2 |
| 93 |
* |
| 94 |
* @param $request |
| 95 |
* |
| 96 |
* @return mixed|object|\WP_REST_Response |
| 97 |
*/ |
| 98 |
public function get_company_locations( $request ) { |
| 99 |
$locations = erp_company_get_locations(); |
| 100 |
$response = rest_ensure_response( $locations ); |
| 101 |
$response = $this->format_collection_response( $response, $request, count( $locations ) ); |
| 102 |
|
| 103 |
return $response; |
| 104 |
} |
| 105 |
|
| 106 |
/** |
| 107 |
* Get employee statuses |
| 108 |
* |
| 109 |
* @since 1.3.2 |
| 110 |
* |
| 111 |
* @param $request |
| 112 |
* |
| 113 |
* @return mixed|object|\WP_REST_Response |
| 114 |
*/ |
| 115 |
public function get_employee_statuses( $request ) { |
| 116 |
$statuses = erp_hr_get_employee_statuses(); |
| 117 |
$response = rest_ensure_response( $statuses ); |
| 118 |
$response = $this->format_collection_response( $response, $request, count( $statuses ) ); |
| 119 |
|
| 120 |
return $response; |
| 121 |
} |
| 122 |
|
| 123 |
/** |
| 124 |
* Get employee pay types |
| 125 |
* |
| 126 |
* @since 1.3.2 |
| 127 |
* |
| 128 |
* @param $request |
| 129 |
* |
| 130 |
* @return mixed|object|\WP_REST_Response |
| 131 |
*/ |
| 132 |
public function get_employee_pay_types( $request ) { |
| 133 |
$pay_types = erp_hr_get_pay_type(); |
| 134 |
$response = rest_ensure_response( $pay_types ); |
| 135 |
$response = $this->format_collection_response( $response, $request, count( $pay_types ) ); |
| 136 |
|
| 137 |
return $response; |
| 138 |
} |
| 139 |
|
| 140 |
/** |
| 141 |
* Get employee types |
| 142 |
* |
| 143 |
* @since 1.3.2 |
| 144 |
* |
| 145 |
* @param $request |
| 146 |
* |
| 147 |
* @return mixed|object|\WP_REST_Response |
| 148 |
*/ |
| 149 |
public function get_employee_types( $request ) { |
| 150 |
$employee_types = erp_hr_get_employee_types(); |
| 151 |
$response = rest_ensure_response( $employee_types ); |
| 152 |
$response = $this->format_collection_response( $response, $request, count( $employee_types ) ); |
| 153 |
|
| 154 |
return $response; |
| 155 |
} |
| 156 |
|
| 157 |
/** |
| 158 |
* Get hiring source |
| 159 |
* |
| 160 |
* @since 1.3.2 |
| 161 |
* |
| 162 |
* @param $request |
| 163 |
* |
| 164 |
* @return mixed|object|\WP_REST_Response |
| 165 |
*/ |
| 166 |
public function get_source_of_hire( $request ) { |
| 167 |
$sources = erp_hr_get_employee_sources(); |
| 168 |
$response = rest_ensure_response( $sources ); |
| 169 |
$response = $this->format_collection_response( $response, $request, count( $sources ) ); |
| 170 |
|
| 171 |
return $response; |
| 172 |
} |
| 173 |
|
| 174 |
} |
| 175 |
|