catalog = $catalog; $this->groups = $groups; } /** * {@inheritdoc} */ protected function capability(): string { return Capabilities::MANAGE_ORDERS; } /** * {@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->groups->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->groups->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->catalog->create_group( $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->catalog->update_group( $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->catalog->delete_group( $id ); } /** * {@inheritdoc} */ protected function supports_reorder(): bool { return true; } /** * Implements the abstract method of the resource controller. * * @since 0.1.0 * * @param int[] $ids Ids in the wanted order. * @return void */ protected function reorder_resource( array $ids ): void { $this->catalog->reorder_groups( $ids ); } /** * {@inheritdoc} */ protected function not_found_message(): string { return __( 'Group 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'], 'slug' => $item['slug'], 'description' => $item['description'], 'status' => $item['status'], 'sort_order' => $item['sort_order'], 'product_count' => $item['product_count'], ); } }