diff --git a/lib/GaletteObjectsLend/Controllers/Crud/CategoriesController.php b/lib/GaletteObjectsLend/Controllers/Crud/CategoriesController.php index 64428ba..1f3ccfc 100644 --- a/lib/GaletteObjectsLend/Controllers/Crud/CategoriesController.php +++ b/lib/GaletteObjectsLend/Controllers/Crud/CategoriesController.php @@ -242,7 +242,7 @@ public function doEdit(Request $request, Response $response, int $id = null, str $error_detected = []; $category->name = $post['name']; - $category->is_active = $post['is_active'] == true; + $category->is_active = ($post['is_active'] ?? false) == true; if ($category->store()) { // picture upload if (isset($_FILES['picture'])) { diff --git a/lib/GaletteObjectsLend/Controllers/Crud/ObjectsController.php b/lib/GaletteObjectsLend/Controllers/Crud/ObjectsController.php index 323eb7e..6502926 100644 --- a/lib/GaletteObjectsLend/Controllers/Crud/ObjectsController.php +++ b/lib/GaletteObjectsLend/Controllers/Crud/ObjectsController.php @@ -543,7 +543,7 @@ public function doClone(Request $request, Response $response, int $id): Response 'success_detected', str_replace( '%id', - $id, + (string)$id, _T('Successfully cloned from #%id.
You can now edit it.', 'objectslend') ) ); @@ -1005,7 +1005,7 @@ public function formUri(array $args): string protected function getIdsToRemove(array &$args, ?array $post): array|int|null { if (isset($args['id'])) { - return $args['id']; + return (int)$args['id']; } else { $filters = $this->session->objectslend_filter_objects; return $filters->selected; diff --git a/lib/GaletteObjectsLend/Entity/LendCategory.php b/lib/GaletteObjectsLend/Entity/LendCategory.php index b2048e8..6813f51 100644 --- a/lib/GaletteObjectsLend/Entity/LendCategory.php +++ b/lib/GaletteObjectsLend/Entity/LendCategory.php @@ -130,7 +130,7 @@ private function loadFromRS(ArrayObject $r): void } if (property_exists($r, 'objects_price_sum')) { - $this->objects_price_sum = $r->objects_price_sum; + $this->objects_price_sum = $r->objects_price_sum ?? 0.0; } @@ -154,7 +154,7 @@ public function store(): bool //Handle booleans for postgres ; bugs #18899 and #19354 $values[$k] = $this->zdb->isPostgres() ? 'false' : 0; } else { - $values[$k] = $this->$k; + $values[$k] = $this->$k ?? null; } } @@ -166,11 +166,11 @@ public function store(): bool if ($result->count() > 0) { if ($this->zdb->isPostgres()) { /** @phpstan-ignore-next-line */ - $this->category_id = $this->zdb->driver->getLastGeneratedValue( + $this->category_id = (int)$this->zdb->driver->getLastGeneratedValue( PREFIX_DB . 'lend_category_id_seq' ); } else { - $this->category_id = $this->zdb->driver->getLastGeneratedValue(); + $this->category_id = (int)$this->zdb->driver->getLastGeneratedValue(); } } else { throw new \RuntimeException('Unable to add category!'); @@ -268,11 +268,11 @@ public function __get(string $name): mixed * Global setter method * * @param string $name name of the property we want to assign a value to - * @param object $value a relevant value for the property + * @param mixed $value a relevant value for the property * * @return void */ - public function __set(string $name, object $value): void + public function __set(string $name, mixed $value): void { $this->$name = $value; } diff --git a/lib/GaletteObjectsLend/Entity/LendObject.php b/lib/GaletteObjectsLend/Entity/LendObject.php index 84f1525..f1291e2 100644 --- a/lib/GaletteObjectsLend/Entity/LendObject.php +++ b/lib/GaletteObjectsLend/Entity/LendObject.php @@ -337,11 +337,11 @@ public function store(): bool if ($result->count() > 0) { if ($this->zdb->isPostgres()) { /** @phpstan-ignore-next-line */ - $this->object_id = $this->zdb->driver->getLastGeneratedValue( + $this->object_id = (int)$this->zdb->driver->getLastGeneratedValue( PREFIX_DB . 'lend_objects_id_seq' ); } else { - $this->object_id = $this->zdb->driver->getLastGeneratedValue(); + $this->object_id = (int)$this->zdb->driver->getLastGeneratedValue(); } if ($this->deps['picture'] === true) { diff --git a/lib/GaletteObjectsLend/Entity/LendRent.php b/lib/GaletteObjectsLend/Entity/LendRent.php index 9e7baf7..5256939 100644 --- a/lib/GaletteObjectsLend/Entity/LendRent.php +++ b/lib/GaletteObjectsLend/Entity/LendRent.php @@ -70,7 +70,7 @@ class LendRent private string $date_begin; private ?string $date_forecast; private ?string $date_end; - private int $status_id; + private ?int $status_id; private ?int $adherent_id; private string $comments = ''; private bool $in_stock; @@ -157,11 +157,11 @@ public function store(): bool $result = $zdb->execute($insert); if ($result->count() > 0) { if ($zdb->isPostgres()) { - $this->rent_id = $zdb->driver->getLastGeneratedValue( + $this->rent_id = (int)$zdb->driver->getLastGeneratedValue( PREFIX_DB . 'lend_rents_id_seq' ); } else { - $this->rent_id = $zdb->driver->getLastGeneratedValue(); + $this->rent_id = (int)$zdb->driver->getLastGeneratedValue(); } Analog::log( 'Rent #' . $this->rent_id . ' added.', @@ -198,7 +198,7 @@ public function store(): bool } /** - * Get rent histroy for a given object sorted + * Get rent history for a given object sorted * * @param integer $object_id Object ID * @param boolean $only_last Only retrieve last rent (for list display) @@ -373,6 +373,11 @@ public function __set(string $name, mixed $value): void $this->$name = null; } break; + case 'status_id': + if ((int)$value > 0) { + $this->$name = (int)$value; + } + break; case 'date_forecast': case 'date_begin': case 'date_end': diff --git a/lib/GaletteObjectsLend/Entity/LendStatus.php b/lib/GaletteObjectsLend/Entity/LendStatus.php index b8ff953..af3fc2a 100644 --- a/lib/GaletteObjectsLend/Entity/LendStatus.php +++ b/lib/GaletteObjectsLend/Entity/LendStatus.php @@ -124,7 +124,7 @@ public function store(): bool //Handle booleans for postgres ; bugs #18899 and #19354 $values[$k] = $this->zdb->isPostgres() ? 'false' : 0; } else { - $values[$k] = $this->$k; + $values[$k] = $this->$k ?? null; } } @@ -136,11 +136,11 @@ public function store(): bool if ($result->count() > 0) { if ($this->zdb->isPostgres()) { /** @phpstan-ignore-next-line */ - $this->status_id = $this->zdb->driver->getLastGeneratedValue( + $this->status_id = (int)$this->zdb->driver->getLastGeneratedValue( PREFIX_DB . 'lend_status_id_seq' ); } else { - $this->status_id = $this->zdb->driver->getLastGeneratedValue(); + $this->status_id = (int)$this->zdb->driver->getLastGeneratedValue(); } } else { throw new \Exception(_T("Status has not been added :(", "objectslend")); @@ -285,11 +285,11 @@ public function __get(string $name): mixed * Global setter method * * @param string $name name of the property we want to assign a value to - * @param object $value a relevant value for the property + * @param mixed $value a relevant value for the property * * @return void */ - public function __set(string $name, object $value): void + public function __set(string $name, mixed $value): void { $this->$name = $value; } diff --git a/lib/GaletteObjectsLend/Entity/Picture.php b/lib/GaletteObjectsLend/Entity/Picture.php index 6fe6452..d4da1e7 100644 --- a/lib/GaletteObjectsLend/Entity/Picture.php +++ b/lib/GaletteObjectsLend/Entity/Picture.php @@ -239,8 +239,8 @@ private function createThumb(string $source, string $ext, string $dest = null): public function delete(bool $transaction = true): bool { //find and delete any thumb - $ext = strlen(pathinfo($this->file_path, PATHINFO_EXTENSION)) + 1; - $filename = substr($this->file_path, 0, strlen($this->file_path) - strlen($ext)); + $ext = pathinfo($this->file_path, PATHINFO_EXTENSION); + $filename = substr($this->file_path, 0, strlen($this->file_path) - strlen($ext) - 1); $thumb = $filename . '_th.' . $ext; @@ -262,8 +262,8 @@ public function delete(bool $transaction = true): bool */ public function store(array $file, bool $ajax = false, array $cropping = null): bool|int { - $ext = strlen(pathinfo($this->file_path, PATHINFO_EXTENSION)) + 1; - $filename = substr($this->file_path, 0, strlen($this->file_path) - strlen($ext)); + $ext = pathinfo($this->file_path, PATHINFO_EXTENSION); + $filename = substr($this->file_path, 0, strlen($this->file_path) - strlen($ext) - 1); $thumb = $filename . '_th.' . $ext; if (is_file($thumb)) { diff --git a/lib/GaletteObjectsLend/Entity/Preferences.php b/lib/GaletteObjectsLend/Entity/Preferences.php index 4b40e7a..dc846e1 100644 --- a/lib/GaletteObjectsLend/Entity/Preferences.php +++ b/lib/GaletteObjectsLend/Entity/Preferences.php @@ -189,9 +189,9 @@ public function getPreferences(): array * * @param string $name name of the property we want to retrieve * - * @return false|object the called property + * @return mixed the called property */ - public function __get(string $name): false|object + public function __get(string $name): mixed { $forbidden = array(); @@ -240,10 +240,8 @@ public function store(array $data, array &$errors): bool )->where->equalTo(self::PK, ':' . self::PK); $stmt = $this->zdb->sql->prepareStatementForSqlObject($update); + unset($data['csrf_value'], $data['csrf_name'], $data['GENERATED_CONTRIB_INFO_TEXT']); foreach ($data as $key => $value) { - if ($key === 'GENERATED_CONTRIB_INFO_TEXT') { - continue; - } $stmt->execute( [ 'value_numeric' => $value, @@ -305,7 +303,7 @@ public function load(): bool */ public function getThumbWidth(): int { - return $this->prefs['THUMB_MAX_WIDTH']; + return (int)$this->prefs['THUMB_MAX_WIDTH']; } /** @@ -315,7 +313,7 @@ public function getThumbWidth(): int */ public function getThumbHeight(): int { - return $this->prefs['THUMB_MAX_HEIGHT']; + return (int)$this->prefs['THUMB_MAX_HEIGHT']; } /** @@ -325,7 +323,7 @@ public function getThumbHeight(): int */ public function imagesInLists(): bool { - return $this->prefs['VIEW_THUMBNAIL']; + return (bool)$this->prefs['VIEW_THUMBNAIL']; } /** @@ -337,6 +335,6 @@ public function imagesInLists(): bool */ public function showFullsize(): bool { - return $this->prefs['VIEW_FULLSIZE']; + return (bool)$this->prefs['VIEW_FULLSIZE']; } } diff --git a/lib/GaletteObjectsLend/Filters/CategoriesList.php b/lib/GaletteObjectsLend/Filters/CategoriesList.php index 63352eb..70e29ce 100644 --- a/lib/GaletteObjectsLend/Filters/CategoriesList.php +++ b/lib/GaletteObjectsLend/Filters/CategoriesList.php @@ -147,7 +147,7 @@ public function __set(string $name, mixed $value): void case Categories::ALL_CATEGORIES: case Categories::ACTIVE_CATEGORIES: case Categories::INACTIVE_CATEGORIES: - $this->active_filter = $value; + $this->active_filter = (int)$value; break; default: Analog::log(