internal_service( $id ) ) { return false; } return parent::update( $id, $data ); } public function delete( int $id ): bool { if ( ( new ResourceBookingRepository() )->internal_service( $id ) ) { return false; } return parent::delete( $id ); } public function find_by_slug( string $slug ): ?array { return $this->find_by( 'slug', $slug ); } /** * Returns services with category names. * * @return array> */ public function list_for_admin(): array { global $wpdb; $rows = $wpdb->get_results( "SELECT s.*, c.name AS category_name, c.description AS category_description, c.image_id AS category_image_id, c.sort_order AS category_sort_order FROM {$wpdb->prefix}abientot_services s LEFT JOIN {$wpdb->prefix}abientot_service_categories c ON c.id = s.category_id ORDER BY COALESCE(c.sort_order, 999999) ASC, s.sort_order ASC, s.name ASC", ARRAY_A ); if ( ! is_array( $rows ) ) { return array(); } $retained = new ResourceBookingRepository(); return array_values( array_filter( $rows, static fn( array $row ): bool=> ! $retained->internal_service( (int) $row['id'] ) ) ); } public function link_to_staff( int $service_id, int $staff_id ): void { global $wpdb; if ( $service_id <= 0 || $staff_id <= 0 ) { return; } $table = $wpdb->prefix . 'abientot_staff_services'; $exists = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}abientot_staff_services WHERE service_id = %d AND staff_id = %d", $service_id, $staff_id ) ); if ( $exists ) { return; } $wpdb->insert( $table, array( 'staff_id' => $staff_id, 'service_id' => $service_id, 'created_at' => gmdate( 'Y-m-d H:i:s' ), ), array( '%d', '%d', '%s' ) ); } public function delete_staff_links( int $service_id ): void { global $wpdb; if ( ( new ResourceBookingRepository() )->internal_service( $service_id ) ) { return; } if ( $service_id <= 0 ) { return; } $table = $wpdb->prefix . 'abientot_staff_services'; $wpdb->delete( $table, array( 'service_id' => $service_id ), array( '%d' ) ); } public function update_all_currency( string $currency ): int { global $wpdb; $currency = strtoupper( sanitize_text_field( $currency ) ); if ( ! preg_match( '/^[A-Z]{3}$/', $currency ) ) { return 0; } $result = $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->prefix}abientot_services SET currency = %s, updated_at = %s", $currency, gmdate( 'Y-m-d H:i:s' ) ) ); return false === $result ? 0 : (int) $result; } }