PluginProbe
ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce / 1.17.4
ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce v1.17.4
1.17.9 1.17.8 1.17.7 1.17.6 1.17.5 1.17.4 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.3.0 1.3.1 1.3.11 1.3.12 1.3.13 1.3.14 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 All 143 releases
erp / includes / API / CompanyController.php

CompanyController.php in ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce 1.17.4, at includes/API/CompanyController.php

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