PluginProbe
ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce / 1.6.7
ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce v1.6.7
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 / modules / accounting / api / class-rest-api-vendors.php

class-rest-api-vendors.php in ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce 1.6.7, at modules/accounting/api/class-rest-api-vendors.php

831 lines 28.9 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\Accounting\API;
4
5 use WP_Error;
6 use WP_REST_Response;
7 use WP_REST_Server;
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly
11 }
12
13 class Vendors_Controller extends \WeDevs\ERP\API\REST_Controller {
14
15 /**
16 * Endpoint namespace.
17 *
18 * @var string
19 */
20 protected $namespace = 'erp/v1';
21
22 /**
23 * Route base.
24 *
25 * @var string
26 */
27 protected $rest_base = 'accounting/v1/vendors';
28
29 /**
30 * Register the routes for the objects of the controller.
31 */
32 public function register_routes() {
33 register_rest_route(
34 $this->namespace,
35 '/' . $this->rest_base,
36 [
37 [
38 'methods' => WP_REST_Server::READABLE,
39 'callback' => [ $this, 'get_vendors' ],
40 'args' => $this->get_collection_params(),
41 'permission_callback' => function ( $request ) {
42 return current_user_can( 'erp_ac_view_vendor' );
43 },
44 ],
45 [
46 'methods' => WP_REST_Server::CREATABLE,
47 'callback' => [ $this, 'create_vendor' ],
48 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),
49 'permission_callback' => function ( $request ) {
50 return current_user_can( 'erp_ac_create_vendor' );
51 },
52 ],
53 'schema' => [ $this, 'get_item_schema' ],
54 ]
55 );
56
57 register_rest_route(
58 $this->namespace,
59 '/' . $this->rest_base . '/(?P<id>[\d]+)',
60 [
61 [
62 'methods' => WP_REST_Server::READABLE,
63 'callback' => [ $this, 'get_vendor' ],
64 'args' => [
65 'context' => $this->get_context_param( [ 'default' => 'view' ] ),
66 ],
67 'permission_callback' => function ( $request ) {
68 return current_user_can( 'erp_ac_view_vendor' );
69 },
70 ],
71 [
72 'methods' => WP_REST_Server::EDITABLE,
73 'callback' => [ $this, 'update_vendor' ],
74 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
75 'permission_callback' => function ( $request ) {
76 return current_user_can( 'erp_ac_edit_vendor' );
77 },
78 ],
79 [
80 'methods' => WP_REST_Server::DELETABLE,
81 'callback' => [ $this, 'delete_vendor' ],
82 'permission_callback' => function ( $request ) {
83 return current_user_can( 'erp_ac_delete_vendor' );
84 },
85 ],
86 'schema' => [ $this, 'get_item_schema' ],
87 ]
88 );
89
90 register_rest_route(
91 $this->namespace,
92 '/' . $this->rest_base . '/delete/(?P<ids>[\d,?]+)',
93 [
94 [
95 'methods' => WP_REST_Server::DELETABLE,
96 'callback' => [ $this, 'bulk_delete_vendors' ],
97 'args' => [
98 'ids' => [ 'required' => true ],
99 ],
100 'permission_callback' => function ( $request ) {
101 return current_user_can( 'erp_ac_delete_vendor' );
102 },
103 ],
104 'schema' => [ $this, 'get_item_schema' ],
105 ]
106 );
107
108 register_rest_route(
109 $this->namespace,
110 '/' . $this->rest_base . '/(?P<id>[\d]+)' . '/transactions',
111 [
112 [
113 'methods' => WP_REST_Server::READABLE,
114 'callback' => [ $this, 'get_transactions' ],
115 'args' => $this->get_collection_params(),
116 'permission_callback' => function ( $request ) {
117 return current_user_can( 'erp_ac_view_vendor' );
118 },
119 ],
120 ]
121 );
122
123 register_rest_route(
124 $this->namespace,
125 '/' . $this->rest_base . '/(?P<id>[\d]+)' . '/transactions/filter',
126 [
127 [
128 'methods' => WP_REST_Server::READABLE,
129 'callback' => [ $this, 'filter_transactions' ],
130 'args' => $this->get_collection_params(),
131 'permission_callback' => function ( $request ) {
132 return current_user_can( 'erp_ac_view_customer' );
133 },
134 ],
135 ]
136 );
137
138 register_rest_route(
139 $this->namespace,
140 '/' . $this->rest_base . '/(?P<id>[\d]+)' . '/products',
141 [
142 [
143 'methods' => WP_REST_Server::READABLE,
144 'callback' => [ $this, 'get_vendor_products' ],
145 'args' => $this->get_collection_params(),
146 'permission_callback' => function ( $request ) {
147 return current_user_can( 'erp_ac_view_customer' );
148 },
149 ],
150 ]
151 );
152 }
153
154 /**
155 * Get a collection of vendors
156 *
157 * @param WP_REST_Request $request
158 *
159 * @return WP_Error|WP_REST_Response
160 */
161 public function get_vendors( $request ) {
162 $args = [
163 'number' => $request['per_page'],
164 'offset' => ( $request['per_page'] * ( $request['page'] - 1 ) ),
165 'type' => 'vendor',
166 's' => ! empty( $request['search'] ) ? $request['search'] : '',
167 ];
168
169 $items = erp_acct_get_accounting_people( $args );
170 $total_items = erp_acct_get_accounting_people(
171 [ 'type' => 'vendor', 's' => $args['s'], 'count' => true ]
172 );
173 $total_items = is_array( $total_items ) ? count( $total_items ) : $total_items;
174
175 $formatted_items = [];
176 $additional_fields = [];
177
178 $additional_fields['namespace'] = $this->namespace;
179 $additional_fields['rest_base'] = $this->rest_base;
180
181 foreach ( $items as $item ) {
182 $photo_id = erp_people_get_meta( $item->id, 'photo_id', true );
183
184 $item->{'photo_id'} = $photo_id;
185 $item->{'photo'} = wp_get_attachment_thumb_url( $photo_id );
186
187 if ( isset( $request['include'] ) ) {
188 $include_params = explode( ',', str_replace( ' ', '', $request['include'] ) );
189
190 if ( in_array( 'owner', $include_params, true ) ) {
191 $vendor_owner_id = ( $item->user_id ) ? get_user_meta( $item->user_id, 'contact_owner', true ) : erp_people_get_meta( $item->id, 'contact_owner', true );
192
193 $item->owner = $this->get_user( $vendor_owner_id );
194 $additional_fields = [ 'owner' => $item->owner ];
195 }
196 }
197
198 $data = $this->prepare_item_for_response( $item, $request, $additional_fields );
199 $formatted_items[] = $this->prepare_response_for_collection( $data );
200 }
201
202 $response = rest_ensure_response( $formatted_items );
203 $response = $this->format_collection_response( $response, $request, $total_items );
204 $response->set_status( 200 );
205
206 return $response;
207 }
208
209 /**
210 * Get a specific vendor
211 *
212 * @param WP_REST_Request $request
213 *
214 * @return WP_Error|WP_REST_Response
215 */
216 public function get_vendor( $request ) {
217 $id = (int) $request['id'];
218 $item = erp_get_people( $id );
219 $item = (array) $item;
220
221 if ( empty( $id ) || empty( $item['id'] ) ) {
222 return new WP_Error( 'rest_vendor_invalid_id', __( 'Invalid resource id.' ), [ 'status' => 404 ] );
223 }
224
225 $photo_id = erp_people_get_meta( $id, 'photo_id', true );
226
227 $item['photo_id'] = $photo_id;
228 $item['photo'] = wp_get_attachment_thumb_url( $photo_id );
229
230 $additional_fields = [];
231
232 if ( isset( $request['include'] ) ) {
233 $include_params = explode( ',', str_replace( ' ', '', $request['include'] ) );
234
235 if ( in_array( 'owner', $include_params, true ) ) {
236 $vendor_owner_id = ( $item->user_id ) ? get_user_meta( $item->user_id, 'contact_owner', true ) : erp_people_get_meta( $item->id, 'contact_owner', true );
237
238 $item->owner = $this->get_user( $vendor_owner_id );
239 $additional_fields = [ 'owner' => $item->owner ];
240 }
241 }
242
243 $additional_fields['namespace'] = $this->namespace;
244 $additional_fields['rest_base'] = $this->rest_base;
245 $item = $this->prepare_item_for_response( $item, $request, $additional_fields );
246 $response = rest_ensure_response( $item );
247
248 $response->set_status( 200 );
249
250 return $response;
251 }
252
253 /**
254 * Create a vendor
255 *
256 * @param WP_REST_Request $request
257 *
258 * @return WP_Error|WP_REST_Request
259 */
260 public function create_vendor( $request ) {
261 if ( erp_acct_check_people_exists( $request['email'] ) ) {
262 return new WP_Error( 'rest_customer_invalid_id', __( 'Email already exists!' ), [ 'status' => 400 ] );
263 }
264
265 $item = $this->prepare_item_for_database( $request );
266
267 $id = erp_insert_people( $item );
268
269 $vendor = (array) erp_get_people( $id );
270 $vendor['id'] = $id;
271
272 $this->add_log( $vendor, 'add' );
273
274 $additional_fields['namespace'] = $this->namespace;
275 $additional_fields['rest_base'] = $this->rest_base;
276
277 $response = $this->prepare_item_for_response( $vendor, $request, $additional_fields );
278 $response = rest_ensure_response( $response );
279 $response->set_status( 201 );
280
281 return $response;
282 }
283
284 /**
285 * Update a vendor
286 *
287 * @param WP_REST_Request $request
288 *
289 * @return WP_Error|WP_REST_Request
290 */
291 public function update_vendor( $request ) {
292 $id = (int) $request['id'];
293
294 $item = erp_get_people( $id );
295
296 if ( ! $item ) {
297 return new WP_Error( 'rest_vendor_invalid_id', __( 'Invalid resource id.' ), [ 'status' => 400 ] );
298 }
299
300 $item = $this->prepare_item_for_database( $request );
301
302 $id = erp_insert_people( $item );
303
304 $vendor = (array) erp_get_people( $id );
305 $vendor['id'] = $id;
306
307 $this->add_log( $vendor, 'add' );
308
309 $additional_fields['namespace'] = $this->namespace;
310 $additional_fields['rest_base'] = $this->rest_base;
311
312 $vendor = erp_get_people( $id );
313 $response = $this->prepare_item_for_response( $vendor, $request, $additional_fields );
314 $response = rest_ensure_response( $response );
315 $response->set_status( 200 );
316
317 return $response;
318 }
319
320 /**
321 * Delete a vendor
322 *
323 * @param WP_REST_Request $request
324 *
325 * @return WP_Error|WP_REST_Request
326 */
327 public function delete_vendor( $request ) {
328 $id = (int) $request['id'];
329
330 $exist = erp_acct_check_associated_tranasaction( $id );
331
332 if ( $exist ) {
333 $error = new WP_Error( 'rest_customer_has_trans', __( 'Can not remove! Customer has transactions.' ) );
334
335 wp_send_json_error( $error );
336 }
337
338 $data = [
339 'id' => $id,
340 'hard' => true,
341 'type' => 'vendor',
342 ];
343
344 erp_delete_people( $data );
345
346 return new WP_REST_Response( true, 204 );
347 }
348
349 /**
350 * Delete Selected vendors
351 *
352 * @param WP_REST_Request $request
353 *
354 * @return WP_Error|WP_REST_Request
355 */
356 public function bulk_delete_vendors( $request ) {
357 $ids = (string) $request['ids'];
358
359 $data = [
360 'id' => explode( ',', $ids ),
361 'hard' => true,
362 'type' => 'vendor',
363 ];
364
365 foreach ( $data['id'] as $id ) {
366 $exist = erp_acct_check_associated_tranasaction( $id );
367
368 if ( $exist ) {
369 $error = new WP_Error( 'rest_customer_has_trans', __( 'Can not remove! Customer has transactions.' ) );
370
371 wp_send_json_error( $error );
372 }
373 }
374
375 erp_delete_people( $data );
376
377 return new WP_REST_Response( true, 204 );
378 }
379
380 /**
381 * Get a collection of transactions
382 *
383 * @param WP_REST_Request $request
384 *
385 * @return WP_Error|WP_REST_Response
386 */
387 public function get_transactions( $request ) {
388 $id = (int) $request['id'];
389 $args['people_id'] = $id;
390
391 $transactions = erp_acct_get_people_transactions( $args );
392
393 return new WP_REST_Response( $transactions, 200 );
394 }
395
396 /**
397 * Get transaction by date
398 *
399 * @param object $request
400 *
401 * @return array
402 */
403 public function filter_transactions( $request ) {
404 $id = $request['id'];
405 $start_date = $request['start_date'];
406 $end_date = $request['end_date'];
407 $args = [
408 'people_id' => $id,
409 'start_date' => $start_date,
410 'end_date' => $end_date,
411 ];
412 $transactions = erp_acct_get_people_transactions( $args );
413 $response = rest_ensure_response( $transactions );
414
415 return $response;
416 }
417
418 /**
419 * Get products of a vendor
420 *
421 * @param WP_REST_Request $request
422 *
423 * @return WP_Error|WP_REST_Response
424 */
425 public function get_vendor_products( $request ) {
426 $args = [
427 'number' => ! empty( $request['number'] ) ? (int) $request['number'] : 20,
428 'offset' => ( $request['per_page'] * ( $request['page'] - 1 ) ),
429 'vendor' => ! empty( $request['id'] ) ? $request['id'] : 0,
430 ];
431
432 $formatted_items = [];
433 $additional_fields = [];
434
435 $additional_fields['namespace'] = $this->namespace;
436 $additional_fields['rest_base'] = $this->rest_base;
437
438 $product_data = erp_acct_get_vendor_products( $args );
439 $total_items = erp_acct_get_vendor_products(
440 [
441 'count' => true,
442 'number' => -1,
443 ]
444 );
445
446 foreach ( $product_data as $item ) {
447 $data = $this->prepare_product_item_for_response( $item, $request, $additional_fields );
448 $formatted_items[] = $this->prepare_response_for_collection( $data );
449 }
450
451 $response = rest_ensure_response( $formatted_items );
452 $response = $this->format_collection_response( $response, $request, $total_items );
453 $response->set_status( 200 );
454
455 return $response;
456 }
457
458 /**
459 * Log when vendor insert or update
460 *
461 * @param $data
462 * @param $action
463 */
464 public function add_log( $data, $action ) {
465 erp_log()->add(
466 [
467 'component' => 'Accounting',
468 'sub_component' => __( 'Vendor', 'erp' ),
469 'old_value' => '',
470 'new_value' => '',
471 'message' => $data['first_name'] . ' ' . $data['last_name'] . __( ' vendor has been created', 'erp' ),
472 'changetype' => $action,
473 'created_by' => get_current_user_id(),
474 ]
475 );
476 }
477
478 /**
479 * Prepare a single item for create or update
480 *
481 * @param WP_REST_Request $request request object
482 *
483 * @return array $prepared_item
484 */
485 protected function prepare_item_for_database( $request ) {
486 $prepared_item = [];
487
488 if ( isset( $request['first_name'] ) ) {
489 $prepared_item['first_name'] = $request['first_name'];
490 }
491
492 if ( isset( $request['last_name'] ) ) {
493 $prepared_item['last_name'] = $request['last_name'];
494 }
495
496 if ( isset( $request['email'] ) ) {
497 $prepared_item['email'] = $request['email'];
498 }
499
500 // optional arguments.
501 if ( isset( $request['id'] ) ) {
502 $prepared_item['id'] = absint( $request['id'] );
503 }
504
505 if ( isset( $request['photo_id'] ) ) {
506 $prepared_item['photo_id'] = $request['photo_id'];
507 }
508
509 if ( isset( $request['company'] ) ) {
510 $prepared_item['company'] = $request['company'];
511 }
512
513 if ( isset( $request['phone'] ) ) {
514 $prepared_item['phone'] = $request['phone'];
515 }
516
517 if ( isset( $request['mobile'] ) ) {
518 $prepared_item['mobile'] = $request['mobile'];
519 }
520
521 if ( isset( $request['other'] ) ) {
522 $prepared_item['other'] = $request['other'];
523 }
524
525 if ( isset( $request['website'] ) ) {
526 $prepared_item['website'] = $request['website'];
527 }
528
529 if ( isset( $request['fax'] ) ) {
530 $prepared_item['fax'] = $request['fax'];
531 }
532
533 if ( isset( $request['notes'] ) ) {
534 $prepared_item['notes'] = $request['notes'];
535 }
536
537 if ( isset( $request['street_1'] ) ) {
538 $prepared_item['street_1'] = $request['street_1'];
539 }
540
541 if ( isset( $request['street_2'] ) ) {
542 $prepared_item['street_2'] = $request['street_2'];
543 }
544
545 if ( isset( $request['city'] ) ) {
546 $prepared_item['city'] = $request['city'];
547 }
548
549 if ( ! empty( $request['state'] ) ) {
550 $prepared_item['state'] = $request['state']['id'];
551 }
552
553 if ( isset( $request['postal_code'] ) ) {
554 $prepared_item['postal_code'] = $request['postal_code'];
555 }
556
557 if ( ! empty( $request['country'] ) ) {
558 $prepared_item['country'] = $request['country']['id'];
559 }
560
561 if ( isset( $request['currency'] ) ) {
562 $prepared_item['currency'] = $request['currency'];
563 }
564
565 $prepared_item['raw_data'] = json_decode( $request->get_body(), true );
566 $prepared_item['type'] = 'vendor';
567
568 return $prepared_item;
569 }
570
571 /**
572 * Prepare a single user output for response
573 *
574 * @param array | object $item
575 * @param WP_REST_Request $request request object
576 * @param array $additional_fields (optional)
577 *
578 * @return WP_REST_Response $response response data
579 */
580 public function prepare_item_for_response( $item, $request, $additional_fields = [] ) {
581 $item = (object) $item;
582
583 $data = [
584 'id' => (int) $item->id,
585 'first_name' => $item->first_name,
586 'last_name' => $item->last_name,
587 'email' => $item->email,
588 'company' => $item->company,
589 'phone' => $item->phone,
590 'website' => $item->website,
591 'notes' => $item->notes,
592 'mobile' => $item->mobile,
593 'fax' => $item->fax,
594 'other' => $item->other,
595 'photo_id' => !empty( $item->photo_id ) ? $item->photo_id : null,
596 'photo' => !empty( $item->photo ) ? $item->photo : null,
597 'billing' => [
598 'first_name' => $item->first_name,
599 'last_name' => $item->last_name,
600 'street_1' => $item->street_1,
601 'street_2' => $item->street_2,
602 'city' => $item->city,
603 'state' => $item->state,
604 'postal_code' => $item->postal_code,
605 'country' => $item->country,
606 'email' => $item->email,
607 'phone' => $item->phone,
608 ],
609 ];
610
611 $data = array_merge( $data, $additional_fields );
612
613 // Wrap the data in a response object
614 $response = rest_ensure_response( $data );
615
616 $response = $this->add_links( $response, $item, $additional_fields );
617
618 return $response;
619 }
620
621 /**
622 * Prepare a single user output for response
623 *
624 * @param array|object $item
625 * @param WP_REST_Request $request request object
626 * @param array $additional_fields (optional)
627 *
628 * @return WP_REST_Response $response response data
629 */
630 public function prepare_product_item_for_response( $item, $request, $additional_fields = [] ) {
631 $item = (object) $item;
632
633 $data = [
634 'id' => $item->id,
635 'name' => $item->name,
636 'product_type_id' => $item->product_type_id,
637 'product_type_name' => $item->product_type_name,
638 'category_id' => $item->category_id,
639 'tax_cat_id' => $item->tax_cat_id,
640 'vendor' => $item->vendor,
641 'cost_price' => $item->cost_price,
642 'sale_price' => $item->sale_price,
643 'vendor_name' => $item->vendor_name,
644 'cat_name' => $item->cat_name,
645 'tax_cat_name' => erp_acct_get_tax_category_by_id( $item->tax_cat_id ),
646 ];
647
648 $data = array_merge( $data, $additional_fields );
649
650 // Wrap the data in a response object
651 $response = rest_ensure_response( $data );
652
653 $response = $this->add_links( $response, $item, $additional_fields );
654
655 return $response;
656 }
657
658 /**
659 * Get the User's schema, conforming to JSON Schema
660 *
661 * @return array
662 */
663 public function get_item_schema() {
664 $schema = [
665 '$schema' => 'http://json-schema.org/draft-04/schema#',
666 'title' => 'vendor',
667 'type' => 'object',
668 'properties' => [
669 'id' => [
670 'description' => __( 'Unique identifier for the resource.' ),
671 'type' => 'integer',
672 'context' => [ 'embed', 'view', 'edit' ],
673 'readonly' => true,
674 ],
675 'first_name' => [
676 'description' => __( 'First name for the resource.' ),
677 'type' => 'string',
678 'context' => [ 'view', 'edit' ],
679 'arg_options' => [
680 'sanitize_callback' => 'sanitize_text_field',
681 ],
682 'required' => true,
683 ],
684 'last_name' => [
685 'description' => __( 'Last name for the resource.' ),
686 'type' => 'string',
687 'context' => [ 'view', 'edit' ],
688 'arg_options' => [
689 'sanitize_callback' => 'sanitize_text_field',
690 ],
691 'required' => true,
692 ],
693 'email' => [
694 'description' => __( 'The email address for the resource.' ),
695 'type' => 'string',
696 'format' => 'email',
697 'context' => [ 'view', 'edit' ],
698 'required' => true,
699 ],
700 'mobile' => [
701 'description' => __( 'Mobile number for the resource.' ),
702 'type' => 'string',
703 'context' => [ 'view', 'edit' ],
704 'arg_options' => [
705 'sanitize_callback' => 'sanitize_text_field',
706 ],
707 ],
708 'company' => [
709 'description' => __( 'Company name for the resource.' ),
710 'type' => 'string',
711 'context' => [ 'view', 'edit' ],
712 'arg_options' => [
713 'sanitize_callback' => 'sanitize_text_field',
714 ],
715 ],
716 'phone' => [
717 'description' => __( 'Phone number for the resource.' ),
718 'type' => 'string',
719 'context' => [ 'view', 'edit' ],
720 'arg_options' => [
721 'sanitize_callback' => 'sanitize_text_field',
722 ],
723 ],
724 'website' => [
725 'description' => __( 'Website link of the resource.' ),
726 'type' => 'string',
727 'format' => 'uri',
728 'context' => [ 'embed', 'view', 'edit' ],
729 ],
730 'notes' => [
731 'description' => __( 'Notes of the resource.' ),
732 'type' => 'string',
733 'context' => [ 'view', 'edit' ],
734 'arg_options' => [
735 'sanitize_callback' => 'sanitize_text_field',
736 ],
737 ],
738 'fax' => [
739 'description' => __( 'Fax of the resource.' ),
740 'type' => 'string',
741 'context' => [ 'view', 'edit' ],
742 'arg_options' => [
743 'sanitize_callback' => 'sanitize_text_field',
744 ],
745 ],
746 'street_1' => [
747 'description' => __( 'Stree 1 for the resource.' ),
748 'type' => 'string',
749 'context' => [ 'view', 'edit' ],
750 'arg_options' => [
751 'sanitize_callback' => 'sanitize_text_field',
752 ],
753 ],
754 'street_2' => [
755 'description' => __( 'Stree 2 for the resource.' ),
756 'type' => 'string',
757 'context' => [ 'view', 'edit' ],
758 'arg_options' => [
759 'sanitize_callback' => 'sanitize_text_field',
760 ],
761 ],
762 'city' => [
763 'description' => __( 'City for the resource.' ),
764 'type' => 'string',
765 'context' => [ 'view', 'edit' ],
766 'arg_options' => [
767 'sanitize_callback' => 'sanitize_text_field',
768 ],
769 ],
770 'postal_code' => [
771 'description' => __( 'Zip code for the resource.' ),
772 'type' => 'string',
773 'context' => [ 'view', 'edit' ],
774 'arg_options' => [
775 'sanitize_callback' => 'sanitize_text_field',
776 ],
777 ],
778 'photo_id' => [
779 'description' => __( 'Photo ID for the resource.' ),
780 'type' => 'integer',
781 'context' => [ 'view', 'edit' ],
782 ],
783 'photo' => [
784 'description' => __( 'Photo for the resource.' ),
785 'type' => 'string',
786 'context' => [ 'view', 'edit' ],
787 'arg_options' => [
788 'sanitize_callback' => 'sanitize_text_field',
789 ],
790 ],
791 'country' => [
792 'description' => __( 'List of countries data.', 'erp' ),
793 'type' => [ 'array', 'object' ],
794 'context' => [ 'view', 'edit' ],
795 'properties' => [
796 'id' => [
797 'description' => __( 'Unique identifier for the resource.', 'erp' ),
798 'type' => 'string',
799 'context' => [ 'view', 'edit' ],
800 ],
801 'name' => [
802 'description' => __( 'Country name for the resource.', 'erp' ),
803 'type' => 'string',
804 'context' => [ 'view', 'edit' ],
805 ],
806 ],
807 ],
808 'state' => [
809 'description' => __( 'State for the resource.', 'erp' ),
810 'type' => [ 'array', 'object' ],
811 'context' => [ 'view', 'edit' ],
812 'properties' => [
813 'id' => [
814 'description' => __( 'Unique identifier for the resource.', 'erp' ),
815 'type' => 'integer',
816 'context' => [ 'view', 'edit' ],
817 ],
818 'name' => [
819 'description' => __( 'State name for the resource.', 'erp' ),
820 'type' => 'string',
821 'context' => [ 'view', 'edit' ],
822 ],
823 ],
824 ],
825 ],
826 ];
827
828 return $schema;
829 }
830 }
831