tax = $tax; $this->rates = $rates; } /** * {@inheritdoc} */ protected function capability(): string { return Capabilities::MANAGE_SETTINGS; } /** * {@inheritdoc} */ protected function collection_args(): array { return array(); } /** * Implements the abstract method of the resource controller. * * @since 0.1.0 * * @param WP_REST_Request $request Request. * @return array{items: array>, total: int} */ protected function query_items( WP_REST_Request $request ): array { $items = $this->rates->all(); return array( 'items' => $items, 'total' => count( $items ), ); } /** * Implements the abstract method of the resource controller. * * @since 0.1.0 * * @param int $id Item id. * @return array|null */ protected function find_item( int $id ): ?array { return $this->rates->find( $id ); } /** * Implements the abstract method of the resource controller. * * @since 0.1.0 * * @param array $body Request body. * @return array|\WP_Error */ protected function create_resource( array $body ) { return $this->tax->create( $body ); } /** * Implements the abstract method of the resource controller. * * @since 0.1.0 * * @param int $id Item id. * @param array $body Request body. * @return array|\WP_Error */ protected function update_resource( int $id, array $body ) { return $this->tax->update( $id, $body ); } /** * Implements the abstract method of the resource controller. * * @since 0.1.0 * * @param int $id Item id. * @return true|\WP_Error */ protected function delete_resource( int $id ) { return $this->tax->delete( $id ); } /** * {@inheritdoc} */ protected function not_found_message(): string { return __( 'Tax rate not found.', 'hostkhata' ); } /** * Implements the abstract method of the resource controller. * * @since 0.1.0 * * @param array $item Item from the repository. * @return array */ protected function present( array $item ): array { return array( 'id' => $item['id'], 'name' => $item['name'], 'tax_class' => $item['tax_class'], 'country' => $item['country'], 'rate_bp' => $item['rate_bp'], 'status' => $item['status'], 'sort_order' => $item['sort_order'], ); } }