Bump version to 1.17.8

- Feat: Verbrauchsauswertung – Ablesung korrigieren (Datum, Zählerstand,
  Korrekturnotiz) und löschen direkt aus der Tabelle (manage_kleingarten)
- Feat: Inventarverwaltung – Gegenstände erfassen, bearbeiten, löschen;
  Ausleihe und Rückgabe je Mitglied mit Notiz und Fälligkeitsdatum tracken;
  Export/Import integriert (InventoryRepository, Schema, Validator, DataTransfer)
- Feat: Jahresabrechnung Sperrstatus – Festschreiben/Freigeben mit
  serverseitiger Prüfung aller Schreibzugriffe auf Kosten und Preise
This commit is contained in:
2026-04-19 21:59:40 +02:00
parent bc89452b5e
commit 6aa31147df
27 changed files with 1219 additions and 21 deletions

85
includes/Validator.php Normal file → Executable file
View File

@@ -367,6 +367,91 @@ class Validator {
return $errors;
}
/**
* Sanitize one inventory item payload.
*
* @param array $data Raw request data.
* @return array
*/
public function sanitize_inventory_item( $data ) {
return array(
'name' => sanitize_text_field( wp_unslash( isset( $data['name'] ) ? $data['name'] : '' ) ),
'total_quantity' => absint( isset( $data['total_quantity'] ) ? $data['total_quantity'] : 0 ),
'available_quantity' => absint( isset( $data['available_quantity'] ) ? $data['available_quantity'] : 0 ),
'storage_location' => sanitize_text_field( wp_unslash( isset( $data['storage_location'] ) ? $data['storage_location'] : '' ) ),
'description' => sanitize_textarea_field( wp_unslash( isset( $data['description'] ) ? $data['description'] : '' ) ),
'is_active' => ! empty( $data['is_active'] ) ? 1 : 0,
);
}
/**
* Validate one inventory item payload.
*
* @param array $data Sanitized data.
* @return \WP_Error
*/
public function validate_inventory_item( $data ) {
$errors = new \WP_Error();
if ( '' === $data['name'] ) {
$errors->add( 'inventory_name_required', __( 'Bitte einen Namen für den Inventargegenstand eingeben.', KGVVM_TEXT_DOMAIN ) );
}
if ( (int) $data['total_quantity'] < 0 ) {
$errors->add( 'inventory_total_invalid', __( 'Die Gesamtmenge muss 0 oder größer sein.', KGVVM_TEXT_DOMAIN ) );
}
if ( (int) $data['available_quantity'] < 0 ) {
$errors->add( 'inventory_available_invalid', __( 'Die verfügbare Menge muss 0 oder größer sein.', KGVVM_TEXT_DOMAIN ) );
}
if ( (int) $data['available_quantity'] > (int) $data['total_quantity'] ) {
$errors->add( 'inventory_available_too_high', __( 'Die verfügbare Menge darf nicht größer als die Gesamtmenge sein.', KGVVM_TEXT_DOMAIN ) );
}
return $errors;
}
/**
* Sanitize one inventory borrow request.
*
* @param array $data Raw request data.
* @return array
*/
public function sanitize_inventory_loan( $data ) {
return array(
'item_id' => absint( isset( $data['item_id'] ) ? $data['item_id'] : 0 ),
'user_id' => absint( isset( $data['user_id'] ) ? $data['user_id'] : 0 ),
'quantity' => absint( isset( $data['quantity'] ) ? $data['quantity'] : 0 ),
'due_date' => $this->normalize_date( isset( $data['due_date'] ) ? $data['due_date'] : '' ),
'note' => sanitize_textarea_field( wp_unslash( isset( $data['note'] ) ? $data['note'] : '' ) ),
);
}
/**
* Validate one inventory borrow request.
*
* @param array $data Sanitized data.
* @return \WP_Error
*/
public function validate_inventory_loan( $data ) {
$errors = new \WP_Error();
if ( (int) $data['item_id'] < 1 ) {
$errors->add( 'inventory_item_required', __( 'Bitte einen Inventargegenstand auswählen.', KGVVM_TEXT_DOMAIN ) );
}
if ( (int) $data['user_id'] < 1 ) {
$errors->add( 'inventory_user_required', __( 'Bitte ein Mitglied auswählen.', KGVVM_TEXT_DOMAIN ) );
}
if ( (int) $data['quantity'] < 1 ) {
$errors->add( 'inventory_quantity_required', __( 'Bitte eine gültige Ausleihmenge eingeben.', KGVVM_TEXT_DOMAIN ) );
}
return $errors;
}
/**
* Normalize optional date fields to Y-m-d.
*