| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPDeveloper\BetterDocs\REST; |
| 4 |
|
| 5 |
use WPDeveloper\BetterDocs\Core\BaseAPI; |
| 6 |
|
| 7 |
class CategoryField extends BaseAPI { |
| 8 |
/** |
| 9 |
* @return mixed |
| 10 |
*/ |
| 11 |
public function register() { |
| 12 |
$this->register_field( |
| 13 |
'doc_category', |
| 14 |
'doc_category_order', |
| 15 |
[ |
| 16 |
'get_callback' => [ $this, 'doc_category_order' ] |
| 17 |
] |
| 18 |
); |
| 19 |
$this->register_field( |
| 20 |
'doc_category', |
| 21 |
'thumbnail', |
| 22 |
[ |
| 23 |
'get_callback' => [ $this, 'thumbnail_image' ] |
| 24 |
] |
| 25 |
); |
| 26 |
$this->register_field( |
| 27 |
'doc_category', |
| 28 |
'handbookthumbnail', |
| 29 |
[ |
| 30 |
'get_callback' => [ $this, 'handbook_thumbnail_image' ] |
| 31 |
] |
| 32 |
); |
| 33 |
$this->register_field( |
| 34 |
'doc_category', |
| 35 |
'subcategories_count', |
| 36 |
[ |
| 37 |
'get_callback' => [ $this, 'get_subcategory_count' ] |
| 38 |
] |
| 39 |
); |
| 40 |
$this->register_field( |
| 41 |
'doc_category', |
| 42 |
'total_docs_count', |
| 43 |
[ |
| 44 |
'get_callback' => [ $this, 'total_docs_count' ] |
| 45 |
] |
| 46 |
); |
| 47 |
$this->register_field( |
| 48 |
'doc_category', |
| 49 |
'last_updated_time', |
| 50 |
[ |
| 51 |
'get_callback' => [ $this, 'last_updated_time' ] |
| 52 |
] |
| 53 |
); |
| 54 |
} |
| 55 |
|
| 56 |
public function last_updated_time( $object ) { |
| 57 |
$date = betterdocs()->query->latest_updated_date( $object['taxonomy'], $object['slug'] ); |
| 58 |
return $date; |
| 59 |
} |
| 60 |
|
| 61 |
public function doc_category_order( $object ) { |
| 62 |
$doc_category_order = get_term_meta( $object['id'], 'doc_category_order', true ); |
| 63 |
if ( ! $doc_category_order ) { |
| 64 |
return; |
| 65 |
} |
| 66 |
|
| 67 |
return $doc_category_order; |
| 68 |
} |
| 69 |
|
| 70 |
public function thumbnail_image( $object ) { |
| 71 |
$attachment_id = get_term_meta( $object['id'], 'doc_category_image-id', true ); |
| 72 |
if ( ! $attachment_id ) { |
| 73 |
return; |
| 74 |
} |
| 75 |
|
| 76 |
return wp_get_attachment_url( $attachment_id ); |
| 77 |
} |
| 78 |
|
| 79 |
public function handbook_thumbnail_image( $object ) { |
| 80 |
$handbook_img_id = get_term_meta( $object['id'], 'doc_category_thumb-id', true ); |
| 81 |
|
| 82 |
if ( ! $handbook_img_id ) { |
| 83 |
return; |
| 84 |
} |
| 85 |
|
| 86 |
return wp_get_attachment_url( $handbook_img_id ); |
| 87 |
} |
| 88 |
|
| 89 |
public function get_subcategory_count( $object ) { |
| 90 |
$sub_terms_count = count( betterdocs()->query->get_all_child_term_ids( 'doc_category', $object['id'] ) ); |
| 91 |
|
| 92 |
return $sub_terms_count; |
| 93 |
} |
| 94 |
|
| 95 |
public function total_docs_count( $object ) { |
| 96 |
$docs_count = betterdocs()->query->get_docs_count( (object) $object, false ); |
| 97 |
return $docs_count; |
| 98 |
} |
| 99 |
} |
| 100 |
|