diff --git a/lib/GaletteObjectsLend/Controllers/Crud/CategoriesController.php b/lib/GaletteObjectsLend/Controllers/Crud/CategoriesController.php index 678b84a..bc1413d 100644 --- a/lib/GaletteObjectsLend/Controllers/Crud/CategoriesController.php +++ b/lib/GaletteObjectsLend/Controllers/Crud/CategoriesController.php @@ -25,6 +25,7 @@ use Analog\Analog; use DI\Attribute\Inject; +use GaletteObjectsLend\Entity\CategoryPicture; use GaletteObjectsLend\Filters\CategoriesList; use GaletteObjectsLend\Repository\Categories; use GaletteObjectsLend\Entity\LendCategory; @@ -107,7 +108,7 @@ public function list(Request $request, Response $response, ?string $option = nul } } - $categories = new Categories($this->zdb, $this->login, $this->plugins, $filters); + $categories = new Categories($this->zdb, $this->login, $filters); $list = $categories->getCategoriesList(true); $this->session->objectslend_filter_categories = $filters; @@ -198,7 +199,7 @@ public function edit(Request $request, Response $response, ?int $id = null, stri $category = $this->session->objectslend_category; $this->session->objectslend_category = null; } else { - $category = new LendCategory($this->zdb, $this->plugins, $id); + $category = new LendCategory($this->zdb, $id); } if ($category->category_id !== null) { @@ -208,12 +209,14 @@ public function edit(Request $request, Response $response, ?int $id = null, stri } $lendsprefs = new Preferences($this->zdb); + $picture = new CategoryPicture($category->category_id); $params = [ 'page_title' => $title, 'category' => $category, 'time' => time(), 'action' => $action, - 'olendsprefs' => $lendsprefs + 'olendsprefs' => $lendsprefs, + 'picture' => $picture ]; // display page @@ -238,36 +241,20 @@ public function edit(Request $request, Response $response, ?int $id = null, stri public function doEdit(Request $request, Response $response, ?int $id = null, string $action = 'edit'): Response { $post = $request->getParsedBody(); - $category = new LendCategory($this->zdb, $this->plugins, $id); + $category = new LendCategory($this->zdb, $id); $error_detected = []; $category->name = $post['name']; $category->is_active = ($post['is_active'] ?? false) == true; if ($category->store()) { // picture upload - if (isset($_FILES['picture'])) { - if ($_FILES['picture']['error'] === UPLOAD_ERR_OK) { - if ($_FILES['picture']['tmp_name'] != '') { - if (is_uploaded_file($_FILES['picture']['tmp_name'])) { - $res = $category->picture->store($_FILES['picture']); - if ($res < 0) { - $error_detected[] = $category->picture->getErrorMessage($res); - } - } - } - } elseif ($_FILES['picture']['error'] !== UPLOAD_ERR_NO_FILE) { - Analog::log( - $category->picture->getPhpErrorMessage($_FILES['picture']['error']), - Analog::WARNING - ); - $error_detected[] = $category->picture->getPhpErrorMessage( - $_FILES['picture']['error'] - ); - } + $picture = new CategoryPicture($category->category_id); + if (!$picture->upload($request->getUploadedFiles(), 'picture')) { + $error_detected = $picture->uploadErrors(); } - if (isset($post['del_picture'])) { - if (!$category->picture->delete($category->category_id)) { + if (isset($post['del_photo'])) { + if (!$picture->delete()) { $error_detected[] = _T("Delete failed", "objectslend"); Analog::log( 'Unable to delete picture for category ' . $category->name, @@ -350,7 +337,7 @@ public function formUri(array $args): string */ public function confirmRemoveTitle(array $args): string { - $category = new LendCategory($this->zdb, $this->plugins, (int)$args['id']); + $category = new LendCategory($this->zdb, (int)$args['id']); return sprintf( _T('Remove category %1$s', 'objectslend'), $category->name @@ -367,7 +354,7 @@ public function confirmRemoveTitle(array $args): string */ protected function doDelete(array $args, array $post): bool { - $category = new LendCategory($this->zdb, $this->plugins, (int)$args['id']); + $category = new LendCategory($this->zdb, (int)$args['id']); return $category->delete(); } diff --git a/lib/GaletteObjectsLend/Controllers/Crud/ObjectsController.php b/lib/GaletteObjectsLend/Controllers/Crud/ObjectsController.php index 593d949..05ea435 100644 --- a/lib/GaletteObjectsLend/Controllers/Crud/ObjectsController.php +++ b/lib/GaletteObjectsLend/Controllers/Crud/ObjectsController.php @@ -25,6 +25,7 @@ use Analog\Analog; use DI\Attribute\Inject; +use GaletteObjectsLend\Entity\ObjectPicture; use GaletteObjectsLend\Filters\CategoriesList; use GaletteObjectsLend\Filters\ObjectsList; use GaletteObjectsLend\Filters\StatusList; @@ -124,7 +125,7 @@ public function list(Request $request, Response $response, ?string $option = nul } $lendsprefs = new Preferences($this->zdb); - $objects = new Objects($this->zdb, $this->plugins, $lendsprefs, $filters); + $objects = new Objects($this->zdb, $lendsprefs, $filters); $list = $objects->getObjectsList(true); $this->session->objectslend_filter_objects = $filters; @@ -137,7 +138,7 @@ public function list(Request $request, Response $response, ?string $option = nul $cat_filters->active_filter = Categories::ACTIVE_CATEGORIES; //retrieve only active categories $cat_filters->not_empty = true; //retrieve only categories with objects $cat_filters->setObjectsFilter($filters); //search for categories corresponding to filtered objects - $categories = new Categories($this->zdb, $this->login, $this->plugins, $cat_filters); + $categories = new Categories($this->zdb, $this->login, $cat_filters); $categories_list = $categories->getCategoriesList(true, null, false); // display page @@ -226,7 +227,6 @@ public function show(Request $request, Response $response, int $id): Response ]; $object = new LendObject( $this->zdb, - $this->plugins, $id, $deps ); @@ -315,10 +315,10 @@ public function edit(Request $request, Response $response, ?int $id = null, stri $this->session->objectslend_object = null; } else { $deps = ['rents' => true]; - $object = new LendObject($this->zdb, $this->plugins, $id, $deps); + $object = new LendObject($this->zdb, $id, $deps); } - $categories = new Categories($this->zdb, $this->login, $this->plugins); + $categories = new Categories($this->zdb, $this->login); $categories_list = $categories->getCategoriesList(true); if ($object->object_id !== null) { @@ -333,6 +333,7 @@ public function edit(Request $request, Response $response, ?int $id = null, stri $slist = $statuses->getStatusList(true); $lendsprefs = new Preferences($this->zdb); + $picture = new ObjectPicture($object->object_id); $params = [ 'page_title' => $title, 'object' => $object, @@ -341,7 +342,8 @@ public function edit(Request $request, Response $response, ?int $id = null, stri 'lendsprefs' => $lendsprefs->getPreferences(), 'olendsprefs' => $lendsprefs, 'categories' => $categories_list, - 'statuses' => $slist + 'statuses' => $slist, + 'picture' => $picture ]; // members @@ -384,7 +386,7 @@ public function doEdit(Request $request, Response $response, ?int $id = null, st { $post = $request->getParsedBody(); - $object = new LendObject($this->zdb, $this->plugins, $id); + $object = new LendObject($this->zdb, $id); $error_detected = []; $object->name = $post['name']; @@ -417,29 +419,12 @@ public function doEdit(Request $request, Response $response, ?int $id = null, st } // picture upload - if (isset($_FILES['picture'])) { - if ($_FILES['picture']['error'] === UPLOAD_ERR_OK) { - if ($_FILES['picture']['tmp_name'] != '') { - if (is_uploaded_file($_FILES['picture']['tmp_name'])) { - $res = $object->picture->store($_FILES['picture']); - if ($res < 0) { - $error_detected[] = $object->picture->getErrorMessage($res); - } - } - } - } elseif ($_FILES['picture']['error'] !== UPLOAD_ERR_NO_FILE) { - Analog::log( - $object->picture->getPhpErrorMessage($_FILES['picture']['error']), - Analog::WARNING - ); - $error_detected[] = $object->picture->getPhpErrorMessage( - $_FILES['picture']['error'] - ); - } + if (!$object->picture->upload($request->getUploadedFiles(), 'picture')) { + $error_detected = $object->picture->uploadErrors(); } if (isset($post['del_picture'])) { - if (!$object->picture->delete($object->object_id)) { + if (!$object->picture->delete()) { $error_detected[] = _T("Delete failed", "objectslend"); Analog::log( 'Unable to delete picture for object ' . $object->name, @@ -500,7 +485,7 @@ public function doUpdateStatus(Request $request, Response $response, ?int $id = { $post = $request->getParsedBody(); - $object = new LendObject($this->zdb, $this->plugins, $id); + $object = new LendObject($this->zdb, $id); LendRent::closeAllRentsForObject($object->getId(), $post['new_comment']); @@ -537,7 +522,7 @@ public function doUpdateStatus(Request $request, Response $response, ?int $id = */ public function doClone(Request $request, Response $response, int $id): Response { - $object = new LendObject($this->zdb, $this->plugins, $id); + $object = new LendObject($this->zdb, $id); if ($object->clone()) { $this->flash->addMessage( @@ -606,7 +591,6 @@ public function lend(Request $request, Response $response, string $action, int $ ]; $object = new LendObject( $this->zdb, - $this->plugins, $id, $deps ); @@ -774,7 +758,6 @@ public function doTake(Request $request, Response $response, int $id): Response //retrieve object information $object = new LendObject( $this->zdb, - $this->plugins, $object_id ); @@ -896,7 +879,6 @@ public function doReturn(Request $request, Response $response, int $id): Respons //retrieve object information $object = new LendObject( $this->zdb, - $this->plugins, $object_id, $deps ); @@ -1024,7 +1006,7 @@ public function confirmRemoveTitle(array $args): string { if (isset($args['id'])) { //one object removal - $object = new LendObject($this->zdb, $this->plugins, (int)$args['id']); + $object = new LendObject($this->zdb, (int)$args['id']); return sprintf( _T('Remove object %1$s', 'objectslend'), $object->name @@ -1056,7 +1038,7 @@ protected function doDelete(array $args, array $post): bool $filters = new ObjectsList(); } $lendsprefs = new Preferences($this->zdb); - $objects = new Objects($this->zdb, $this->plugins, $lendsprefs, $filters); + $objects = new Objects($this->zdb, $lendsprefs, $filters); if (!is_array($post['id'])) { $ids = (array)$post['id']; diff --git a/lib/GaletteObjectsLend/Controllers/ImagesController.php b/lib/GaletteObjectsLend/Controllers/ImagesController.php index f8c047f..5149985 100644 --- a/lib/GaletteObjectsLend/Controllers/ImagesController.php +++ b/lib/GaletteObjectsLend/Controllers/ImagesController.php @@ -53,7 +53,7 @@ public function lendPicture(Request $request, Response $response, string $type, { $class = '\GaletteObjectsLend\Entity\\' . ($type == 'category' ? 'CategoryPicture' : 'ObjectPicture'); - $picture = new $class($this->plugins, $id); + $picture = new $class($id); $this->lendsprefs = new Preferences($this->zdb); $thumb = false; diff --git a/lib/GaletteObjectsLend/Controllers/PdfController.php b/lib/GaletteObjectsLend/Controllers/PdfController.php index 9941274..413b3df 100644 --- a/lib/GaletteObjectsLend/Controllers/PdfController.php +++ b/lib/GaletteObjectsLend/Controllers/PdfController.php @@ -62,7 +62,6 @@ public function printObject(Request $request, Response $response, int $id): Resp ]; $object = new LendObject( $this->zdb, - $this->plugins, $id, $deps ); @@ -98,7 +97,7 @@ public function printObjects(Request $request, Response $response): Response if ($filters->orderby !== Objects::ORDERBY_CATEGORY) { $filters->orderby = Objects::ORDERBY_CATEGORY; } - $objects = new Objects($this->zdb, $this->plugins, $lendsprefs, $filters); + $objects = new Objects($this->zdb, $lendsprefs, $filters); $list = $objects->getObjectsList(true, null, true, false); $pdf = new PdfObjects( @@ -106,8 +105,7 @@ public function printObjects(Request $request, Response $response): Response $this->preferences, $lendsprefs, $filters, - $this->login, - $this->plugins + $this->login ); $pdf->drawList($list); diff --git a/lib/GaletteObjectsLend/Entity/CategoryPicture.php b/lib/GaletteObjectsLend/Entity/CategoryPicture.php index 57e3507..128f907 100644 --- a/lib/GaletteObjectsLend/Entity/CategoryPicture.php +++ b/lib/GaletteObjectsLend/Entity/CategoryPicture.php @@ -23,8 +23,6 @@ namespace GaletteObjectsLend\Entity; -use Galette\Core\Plugins; - /** * Picture for category * @@ -39,12 +37,11 @@ class CategoryPicture extends Picture /** * Default constructor. * - * @param Plugins $plugins Plugins * @param mixed|null $objectid Object id */ - public function __construct(Plugins $plugins, mixed $objectid = null) + public function __construct(mixed $objectid = null) { $this->store_path = GALETTE_PHOTOS_PATH . 'objectslend/categories/'; - parent::__construct($plugins, $objectid); + parent::__construct($objectid); } } diff --git a/lib/GaletteObjectsLend/Entity/LendCategory.php b/lib/GaletteObjectsLend/Entity/LendCategory.php index 7149b5b..f86a5c0 100644 --- a/lib/GaletteObjectsLend/Entity/LendCategory.php +++ b/lib/GaletteObjectsLend/Entity/LendCategory.php @@ -26,7 +26,6 @@ use Analog\Analog; use ArrayObject; use Galette\Core\Db; -use Galette\Core\Plugins; use Laminas\Db\Sql\Predicate; /** @@ -66,20 +65,17 @@ class LendCategory ]; private Db $zdb; - private Plugins $plugins; /** * Default constructor * - * @param Db $zdb Database instance - * @param Plugins $plugins Plugins instance - * @param int|ArrayObject|null $args Maybe null, an RS object or an id from database - * @param ?array $deps Dependencies configuration, see LendCategory::$deps + * @param Db $zdb Database instance + * @param int|ArrayObject|null $args Maybe null, an RS object or an id from database + * @param ?array $deps Dependencies configuration, see LendCategory::$deps */ - public function __construct(Db $zdb, Plugins $plugins, int|ArrayObject|null $args = null, ?array $deps = null) + public function __construct(Db $zdb, int|ArrayObject|null $args = null, ?array $deps = null) { $this->zdb = $zdb; - $this->plugins = $plugins; if ($deps !== null) { $this->deps = array_merge( @@ -89,7 +85,7 @@ public function __construct(Db $zdb, Plugins $plugins, int|ArrayObject|null $arg } if ($this->deps['picture'] === true) { - $this->picture = new CategoryPicture($this->plugins); + $this->picture = new CategoryPicture(); } if (is_int($args)) { @@ -134,7 +130,7 @@ private function loadFromRS(ArrayObject $r): void } if ($this->deps['picture'] === true) { - $this->picture = new CategoryPicture($this->plugins, (int)$this->category_id); + $this->picture = new CategoryPicture((int)$this->category_id); } } diff --git a/lib/GaletteObjectsLend/Entity/LendObject.php b/lib/GaletteObjectsLend/Entity/LendObject.php index 64ff129..ab5af7d 100644 --- a/lib/GaletteObjectsLend/Entity/LendObject.php +++ b/lib/GaletteObjectsLend/Entity/LendObject.php @@ -26,7 +26,6 @@ use Analog\Analog; use ArrayObject; use Galette\Core\Db; -use Galette\Core\Plugins; use Galette\Entity\Adherent; use GaletteObjectsLend\Filters\ObjectsList; use GaletteObjectsLend\Repository\Objects; @@ -124,7 +123,6 @@ class LendObject ]; private Db $zdb; - private Plugins $plugins; /** * @var LendRent[] @@ -135,15 +133,13 @@ class LendObject /** * Default constructor * - * @param Db $zdb Database instance - * @param Plugins $plugins Plugins instance - * @param int|ArrayObject|null $args Maybe null, an RS object or an id from database - * @param ?array $deps Dependencies configuration, see LendOb::$deps + * @param Db $zdb Database instance + * @param int|ArrayObject|null $args Maybe null, an RS object or an id from database + * @param ?array $deps Dependencies configuration, see LendOb::$deps */ - public function __construct(Db $zdb, Plugins $plugins, int|ArrayObject|null $args = null, ?array $deps = null) + public function __construct(Db $zdb, int|ArrayObject|null $args = null, ?array $deps = null) { $this->zdb = $zdb; - $this->plugins = $plugins; if ($deps !== null) { $this->deps = array_merge( @@ -153,7 +149,7 @@ public function __construct(Db $zdb, Plugins $plugins, int|ArrayObject|null $arg } if ($this->deps['picture'] === true) { - $this->picture = new ObjectPicture($this->plugins); + $this->picture = new ObjectPicture(); } if (is_int($args)) { @@ -289,7 +285,7 @@ private function loadFromRS(ArrayObject $r): void } if ($this->deps['picture'] === true) { - $this->picture = new ObjectPicture($this->plugins, (int)$this->object_id); + $this->picture = new ObjectPicture((int)$this->object_id); } if ($this->deps['member'] === true) { @@ -343,7 +339,7 @@ public function store(): bool } if ($this->deps['picture'] === true) { - $this->picture = new ObjectPicture($this->plugins, (int)$this->object_id); + $this->picture = new ObjectPicture((int)$this->object_id); } } else { throw new \Exception(_T("Object has not been added :(", "objectslend")); @@ -590,7 +586,7 @@ public function clone(): bool //unset id so this is considered as new object unset($this->object_id); //unset image - $this->picture = new ObjectPicture($this->plugins); + $this->picture = new ObjectPicture(); return $this->store(); } diff --git a/lib/GaletteObjectsLend/Entity/ObjectPicture.php b/lib/GaletteObjectsLend/Entity/ObjectPicture.php index fc862c7..7b7449d 100644 --- a/lib/GaletteObjectsLend/Entity/ObjectPicture.php +++ b/lib/GaletteObjectsLend/Entity/ObjectPicture.php @@ -23,8 +23,6 @@ namespace GaletteObjectsLend\Entity; -use Galette\Core\Plugins; - /** * Picture for objects * @@ -39,12 +37,11 @@ class ObjectPicture extends Picture /** * Default constructor. * - * @param Plugins $plugins Plugins * @param mixed|null $objectid Object id */ - public function __construct(Plugins $plugins, mixed $objectid = null) + public function __construct(mixed $objectid = null) { $this->store_path = GALETTE_PHOTOS_PATH . 'objectslend/objects/'; - parent::__construct($plugins, $objectid); + parent::__construct($objectid); } } diff --git a/lib/GaletteObjectsLend/Entity/Picture.php b/lib/GaletteObjectsLend/Entity/Picture.php index c9dbd95..9ea3ec7 100644 --- a/lib/GaletteObjectsLend/Entity/Picture.php +++ b/lib/GaletteObjectsLend/Entity/Picture.php @@ -24,7 +24,7 @@ namespace GaletteObjectsLend\Entity; use Analog\Analog; -use Galette\Core\Plugins; +use Psr\Http\Message\UploadedFileInterface; use Slim\Psr7\Response; use Slim\Psr7\Stream; @@ -45,18 +45,14 @@ class Picture extends \Galette\Core\Picture protected int $thumb_optimal_height; protected int $thumb_optimal_width; - protected Plugins $plugins; - /** * Default constructor. * - * @param Plugins $plugins Plugins * @param mixed|null $objectid Object id */ - public function __construct(Plugins $plugins, mixed $objectid = null) + public function __construct(mixed $objectid = null) { $this->tbl_prefix = LEND_PREFIX; - $this->plugins = $plugins; if (!file_exists($this->store_path)) { if (!mkdir($this->store_path, 0o755, true)) { @@ -91,8 +87,7 @@ public function __construct(Plugins $plugins, mixed $objectid = null) protected function getDefaultPicture(): void { $this->file_path = (string)realpath( - $this->plugins->getTemplatesPathFromName('Galette Objects Lend') - . '/../../webroot/images/1f5bc.png' + __DIR__ . '/../../../webroot/images/1f5bc.png' ); $this->format = 'png'; $this->mime = 'image/png'; @@ -254,13 +249,12 @@ public function delete(bool $transaction = true): bool /** * Stores an image on the disk and in the database * - * @param array $file The uploaded file - * @param boolean $ajax If the image comes from an ajax call (dnd) + * @param UploadedFileInterface $file The uploaded file * @param ?array $cropping Cropping properties * - * @return bool|int + * @return true|int */ - public function store(array $file, bool $ajax = false, ?array $cropping = null): bool|int + public function storeFile(UploadedFileInterface $file, ?array $cropping = null): bool|int { $ext = pathinfo($this->file_path, PATHINFO_EXTENSION); $filename = substr($this->file_path, 0, strlen($this->file_path) - strlen($ext) - 1); @@ -270,7 +264,7 @@ public function store(array $file, bool $ajax = false, ?array $cropping = null): unlink($thumb); } - return parent::store($file); + return parent::storeFile($file, $cropping); } /** @@ -290,7 +284,7 @@ public function restorePictures(array &$success, array &$error): void $results = $zdb->execute($select_all); $success[] = str_replace( '%count', - count($results), + (string)count($results), _T("Found %count pictures in database") ); foreach ($results as $picture) { diff --git a/lib/GaletteObjectsLend/IO/PdfObjects.php b/lib/GaletteObjectsLend/IO/PdfObjects.php index 0642185..ba2a935 100644 --- a/lib/GaletteObjectsLend/IO/PdfObjects.php +++ b/lib/GaletteObjectsLend/IO/PdfObjects.php @@ -24,7 +24,6 @@ namespace GaletteObjectsLend\IO; use Galette\Core\Db; -use Galette\Core\Plugins; use Galette\IO\Pdf; use Galette\Core\Preferences; use Galette\Core\Login; @@ -46,7 +45,6 @@ class PdfObjects extends Pdf private LendPreferences $lendsprefs; private ObjectsList $filters; private Login $login; - private Plugins $plugins; /** * Main constructor, set creator and author @@ -56,7 +54,6 @@ class PdfObjects extends Pdf * @param LendPreferences $lendsprefs Plugin preferences * @param ObjectsList $filters Current filters * @param Login $login Login instance - * @param Plugins $plugins Plugins instance */ public function __construct( Db $zdb, @@ -64,7 +61,6 @@ public function __construct( LendPreferences $lendsprefs, ObjectsList $filters, Login $login, - Plugins $plugins ) { parent::__construct($prefs); // Enable Auto Page breaks @@ -76,7 +72,6 @@ public function __construct( $this->lendsprefs = $lendsprefs; $this->filters = $filters; $this->login = $login; - $this->plugins = $plugins; } /** @@ -196,7 +191,7 @@ public function drawList(array $objects): void } if (!empty($object->category_id) && !in_array($object->category_id, $existing_categories)) { - $category = new LendCategory($this->zdb, $this->plugins, (int)$object->category_id); + $category = new LendCategory($this->zdb, (int)$object->category_id); $text = str_replace( '%category', $category->name, diff --git a/lib/GaletteObjectsLend/Repository/Categories.php b/lib/GaletteObjectsLend/Repository/Categories.php index df3c20f..ee9de31 100644 --- a/lib/GaletteObjectsLend/Repository/Categories.php +++ b/lib/GaletteObjectsLend/Repository/Categories.php @@ -33,7 +33,6 @@ use GaletteObjectsLend\Entity\LendCategory; use GaletteObjectsLend\Entity\LendObject; use Galette\Core\Login; -use Galette\Core\Plugins; use Laminas\Db\Sql\Select; /** @@ -61,7 +60,6 @@ class Categories private array $errors = []; private Db $zdb; - private Plugins $plugins; private Login $login; /** @@ -69,14 +67,12 @@ class Categories * * @param Db $zdb Database instance * @param Login $login Logged in instance - * @param Plugins $plugins Plugins instance * @param ?CategoriesList $filters Filtering */ - public function __construct(Db $zdb, Login $login, Plugins $plugins, ?CategoriesList $filters = null) + public function __construct(Db $zdb, Login $login, ?CategoriesList $filters = null) { $this->zdb = $zdb; $this->login = $login; - $this->plugins = $plugins; if ($filters === null) { $this->filters = new CategoriesList(); @@ -119,7 +115,7 @@ public function getCategoriesList( $categories = []; if ($as_cat) { foreach ($rows as $row) { - $categories[] = new LendCategory($this->zdb, $this->plugins, $row); + $categories[] = new LendCategory($this->zdb, $row); } } else { $categories = $rows; @@ -293,7 +289,6 @@ private function buildWhereClause(Select $select): void if ($this->filters->objects_filters instanceof ObjectsList) { $objects = new Objects( $this->zdb, - $this->plugins, new \GaletteObjectsLend\Entity\Preferences($this->zdb), $this->filters->objects_filters ); diff --git a/lib/GaletteObjectsLend/Repository/Objects.php b/lib/GaletteObjectsLend/Repository/Objects.php index 50739bc..e697c56 100644 --- a/lib/GaletteObjectsLend/Repository/Objects.php +++ b/lib/GaletteObjectsLend/Repository/Objects.php @@ -34,7 +34,6 @@ use GaletteObjectsLend\Entity\LendCategory; use GaletteObjectsLend\Entity\LendRent; use GaletteObjectsLend\Entity\LendStatus; -use Galette\Core\Plugins; use Laminas\Db\Sql\Select; /** @@ -74,20 +73,17 @@ class Objects /** @var array */ private array $errors = []; private Preferences $prefs; - private Plugins $plugins; /** * Default constructor * * @param Db $zdb Database instance - * @param Plugins $plugins Plugins instance * @param Preferences $lprefs Lends preferences instance * @param ?ObjectsList $filters Filtering */ - public function __construct(Db $zdb, Plugins $plugins, Preferences $lprefs, ?ObjectsList $filters = null) + public function __construct(Db $zdb, Preferences $lprefs, ?ObjectsList $filters = null) { $this->zdb = $zdb; - $this->plugins = $plugins; $this->prefs = $lprefs; if ($filters === null) { @@ -134,7 +130,7 @@ public function getObjectsList( if ($all_rents === true) { $deps['rents'] = true; } - $objects[] = new LendObject($this->zdb, $this->plugins, $row, $deps); + $objects[] = new LendObject($this->zdb, $row, $deps); } } else { $objects = $rows; diff --git a/templates/default/category_edit.html.twig b/templates/default/category_edit.html.twig index 035e55f..4ec1928 100644 --- a/templates/default/category_edit.html.twig +++ b/templates/default/category_edit.html.twig @@ -47,11 +47,11 @@ {{ _T(
- {% if category.picture.hasPicture() %} + {% if picture.hasPicture() %} {% include "components/forms/checkbox.html.twig" with { id: 'del_photo', value: 1, diff --git a/templates/default/objects_edit.html.twig b/templates/default/objects_edit.html.twig index cbc9832..5d5f214 100644 --- a/templates/default/objects_edit.html.twig +++ b/templates/default/objects_edit.html.twig @@ -131,11 +131,11 @@ {{ _T(
- {% if object.picture.hasPicture() %} + {% if picture.hasPicture() %} {% include "components/forms/checkbox.html.twig" with { id: 'del_picture', value: 1, @@ -147,7 +147,7 @@ diff --git a/tests/GaletteObjectsLend/Entity/tests/units/LendCategory.php b/tests/GaletteObjectsLend/Entity/tests/units/LendCategory.php index 2fe0152..2610a81 100644 --- a/tests/GaletteObjectsLend/Entity/tests/units/LendCategory.php +++ b/tests/GaletteObjectsLend/Entity/tests/units/LendCategory.php @@ -32,19 +32,6 @@ class LendCategory extends GaletteTestCase { protected int $seed = 20240521212536; - protected \Galette\Core\Plugins $plugins; - - /** - * Set up tests - * - * @return void - */ - public function setUp(): void - { - parent::setUp(); - $this->plugins = $this->container->get('plugins'); - } - /** * Cleanup after each test method * @@ -64,7 +51,7 @@ public function tearDown(): void */ public function testEmpty(): void { - $category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb, $this->plugins); + $category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb); $this->assertSame('No category (0)', $category->getName()); $this->assertSame('No category', $category->getName(false)); $this->assertInstanceOf(\GaletteObjectsLend\Entity\CategoryPicture::class, $category->getPicture()); @@ -77,7 +64,6 @@ public function testEmpty(): void $category = new \GaletteObjectsLend\Entity\LendCategory( $this->zdb, - $this->plugins, null, ['picture' => false] ); @@ -91,7 +77,7 @@ public function testEmpty(): void */ public function testCrud(): void { - $category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb, $this->plugins); + $category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb); $category->name = 'Test category'; $category->is_active = false; @@ -100,17 +86,17 @@ public function testCrud(): void $cid = $category->getId(); $this->assertGreaterThan(0, $cid); - $category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb, $this->plugins, $cid); + $category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb, $cid); $this->assertSame('Test category (0)', $category->getName()); $this->assertFalse($category->isActive()); $category->name = 'Test category (edited)'; $this->assertTrue($category->store()); - $category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb, $this->plugins, $cid); + $category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb, $cid); $this->assertSame('Test category (edited) (0)', $category->getName()); $this->assertTrue($category->delete()); - new \GaletteObjectsLend\Entity\LendCategory($this->zdb, $this->plugins, $cid); + new \GaletteObjectsLend\Entity\LendCategory($this->zdb, $cid); } } diff --git a/tests/GaletteObjectsLend/Entity/tests/units/LendObject.php b/tests/GaletteObjectsLend/Entity/tests/units/LendObject.php index 9bd0af9..12b0fb1 100644 --- a/tests/GaletteObjectsLend/Entity/tests/units/LendObject.php +++ b/tests/GaletteObjectsLend/Entity/tests/units/LendObject.php @@ -32,8 +32,6 @@ class LendObject extends GaletteTestCase { protected int $seed = 20240522000325; - protected \Galette\Core\Plugins $plugins; - private int $active_category_id; private int $inactive_category_id; private int $active_instock_status; @@ -48,7 +46,6 @@ class LendObject extends GaletteTestCase public function setUp(): void { parent::setUp(); - $this->plugins = $this->container->get('plugins'); $this->createCategories(); $this->createStatus(); } @@ -82,7 +79,7 @@ public function tearDown(): void */ public function testEmpty(): void { - $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb, $this->plugins); + $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb); $this->assertSame('€', $object->getCurrency()); $this->assertNull($object->getCurrentRent()); $this->assertTrue($object->isActive()); @@ -115,7 +112,7 @@ public function testCrud(): void 'status' => true, 'last_rent' => true ]; - $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb, $this->plugins, null, $deps); + $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb, null, $deps); $object->name = 'An object'; $object->category_id = $this->active_category_id; @@ -139,7 +136,7 @@ public function testCrud(): void $rent->object_id = $oid; $this->assertTrue($rent->store()); - $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb, $this->plugins, $oid, $deps); + $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb, $oid, $deps); $this->assertTrue($object->isActive()); $this->assertSame(1500.00, $object->getPrice()); $this->assertSame('1 500,00', $object->price); @@ -173,7 +170,7 @@ public function testCrud(): void $filter->filter_str = '50'; $this->assertSame('10x50', $object->displayDimension($filter)); - $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb, $this->plugins, $oid, $deps); + $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb, $oid, $deps); $this->assertSame('An object (edited)', $object->getName()); //edit category to inactive one @@ -181,12 +178,12 @@ public function testCrud(): void $this->assertNull($object->member); $this->assertNull($object->rents); $this->assertTrue($object->store()); - $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb, $this->plugins, $oid, $deps + ['member' => true, 'rents' => true]); + $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb, $oid, $deps + ['member' => true, 'rents' => true]); $this->assertFalse($object->isActive()); $this->assertInstanceOf(\Galette\Entity\Adherent::class, $object->member); //removing category - $rm_category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb, $this->plugins); + $rm_category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb); $rm_category->name = 'Category to be removed'; $rm_category->is_active = true; @@ -196,11 +193,11 @@ public function testCrud(): void $object->category_id = $category_id; $this->assertTrue($object->store()); - $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb, $this->plugins, $oid, $deps); + $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb, $oid, $deps); $this->assertSame($category_id, $object->getCategoryId()); $this->assertTrue($rm_category->delete()); - $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb, $this->plugins, $oid, $deps); + $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb, $oid, $deps); $this->assertNull($object->getCategoryId()); //clone @@ -209,9 +206,9 @@ public function testCrud(): void $this->assertNotEquals($oid, $clone_id); $this->assertSame('An object (edited)', $object->getName()); - $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb, $this->plugins, $oid); + $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb, $oid); $this->assertTrue($object->delete()); - $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb, $this->plugins, $clone_id); + $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb, $clone_id); $this->assertTrue($object->delete()); } @@ -251,7 +248,7 @@ private function createStatus(): void */ private function createCategories(): void { - $category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb, $this->plugins); + $category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb); $category->name = 'Active test category'; $category->is_active = true; @@ -260,7 +257,7 @@ private function createCategories(): void $this->active_category_id = $category->getId(); $this->assertGreaterThan(0, $this->active_category_id); - $category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb, $this->plugins); + $category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb); $category->name = 'Inactive test category'; $category->is_active = false; diff --git a/tests/GaletteObjectsLend/Entity/tests/units/LendRent.php b/tests/GaletteObjectsLend/Entity/tests/units/LendRent.php index 7f42fe2..d4c1c3c 100644 --- a/tests/GaletteObjectsLend/Entity/tests/units/LendRent.php +++ b/tests/GaletteObjectsLend/Entity/tests/units/LendRent.php @@ -32,7 +32,6 @@ class LendRent extends GaletteTestCase { protected int $seed = 20240524220704; - protected \Galette\Core\Plugins $plugins; private int $active_instock_status; private int $active_notinstock_status; private int $inactive_instock_status; @@ -45,8 +44,6 @@ class LendRent extends GaletteTestCase public function setUp(): void { parent::setUp(); - $this->plugins = $this->container->get('plugins'); - //$this->createCategories(); $this->createStatus(); } @@ -100,7 +97,7 @@ public function testCrud(): void { $rent = new \GaletteObjectsLend\Entity\LendRent(); - $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb, $this->plugins); + $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb); $object->name = 'Test object'; $this->assertTrue($object->store()); $oid = $object->object_id; diff --git a/tests/GaletteObjectsLend/Repository/tests/units/Categories.php b/tests/GaletteObjectsLend/Repository/tests/units/Categories.php index 413087a..567a958 100644 --- a/tests/GaletteObjectsLend/Repository/tests/units/Categories.php +++ b/tests/GaletteObjectsLend/Repository/tests/units/Categories.php @@ -32,19 +32,6 @@ class Categories extends GaletteTestCase { protected int $seed = 20240525091538; - protected \Galette\Core\Plugins $plugins; - - /** - * Set up tests - * - * @return void - */ - public function setUp(): void - { - parent::setUp(); - $this->plugins = $this->container->get('plugins'); - } - /** * Cleanup after each test method * @@ -67,7 +54,7 @@ public function tearDown(): void */ public function testGetList(): void { - $categories = new \GaletteObjectsLend\Repository\Categories($this->zdb, $this->login, $this->plugins); + $categories = new \GaletteObjectsLend\Repository\Categories($this->zdb, $this->login); $rs_list = $categories->getList(); $this->assertInstanceOf(\Laminas\Db\ResultSet\ResultSet::class, $rs_list); @@ -78,24 +65,24 @@ public function testGetList(): void $this->assertSame([], $categories->getCategoriesList(true)); $this->assertSame(0, $categories->getCount()); - $category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb, $this->plugins); + $category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb); $category->name = 'One category'; $category->is_active = true; $this->assertTrue($category->store()); $cat_one_id = $category->category_id; - $category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb, $this->plugins); + $category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb); $category->name = 'Another category'; $category->is_active = true; $this->assertTrue($category->store()); - $category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb, $this->plugins); + $category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb); $category->name = 'Yet another category'; $category->is_active = false; $this->assertTrue($category->store()); $filters = new \GaletteObjectsLend\Filters\CategoriesList(); - $categories = new \GaletteObjectsLend\Repository\Categories($this->zdb, $this->login, $this->plugins, $filters); + $categories = new \GaletteObjectsLend\Repository\Categories($this->zdb, $this->login, $filters); $this->assertCount(3, $categories->getCategoriesList(true)); $this->assertSame(3, $categories->getCount()); @@ -113,7 +100,7 @@ public function testGetList(): void $filters->not_empty = true; $this->assertCount(0, $categories->getCategoriesList(true)); - $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb, $this->plugins); + $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb); $object->name = 'One object'; $object->category_id = $cat_one_id; $this->assertTrue($object->store()); diff --git a/tests/GaletteObjectsLend/Repository/tests/units/Objects.php b/tests/GaletteObjectsLend/Repository/tests/units/Objects.php index 5a75ef9..4d4e6e2 100644 --- a/tests/GaletteObjectsLend/Repository/tests/units/Objects.php +++ b/tests/GaletteObjectsLend/Repository/tests/units/Objects.php @@ -32,7 +32,6 @@ class Objects extends GaletteTestCase { protected int $seed = 20240526224135; - protected \Galette\Core\Plugins $plugins; protected \GaletteObjectsLend\Entity\Preferences $lend_prefs; /** @@ -43,7 +42,6 @@ class Objects extends GaletteTestCase public function setUp(): void { parent::setUp(); - $this->plugins = $this->container->get('plugins'); $this->lend_prefs = new \GaletteObjectsLend\Entity\Preferences($this->zdb); } @@ -70,7 +68,7 @@ public function tearDown(): void */ public function testGetList(): void { - $objects = new \GaletteObjectsLend\Repository\Objects($this->zdb, $this->plugins, $this->lend_prefs); + $objects = new \GaletteObjectsLend\Repository\Objects($this->zdb, $this->lend_prefs); $rs_list = $objects->getList(); $this->assertInstanceOf(\Laminas\Db\ResultSet\ResultSet::class, $rs_list); @@ -81,28 +79,28 @@ public function testGetList(): void $this->assertSame([], $objects->getObjectsList(true)); $this->assertSame(0, $objects->getCount()); - $category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb, $this->plugins); + $category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb); $category->name = 'First category'; $category->is_active = true; $this->assertTrue($category->store()); $first_category_id = $category->getId(); $this->assertGreaterThan(0, $first_category_id); - $category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb, $this->plugins); + $category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb); $category->name = 'Second category'; $category->is_active = true; $this->assertTrue($category->store()); $second_category_id = $category->getId(); $this->assertGreaterThan(0, $second_category_id); - $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb, $this->plugins); + $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb); $object->name = 'First object'; $object->category_id = $first_category_id; $object->is_active = true; $this->assertTrue($object->store()); $first_object_id = $object->getId(); - $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb, $this->plugins); + $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb); $object->name = 'Second object'; $object->description = 'First description'; $object->category_id = $first_category_id; @@ -110,14 +108,14 @@ public function testGetList(): void $this->assertTrue($object->store()); $second_object_id = $object->getId(); - $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb, $this->plugins); + $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb); $object->name = 'Third object'; $object->category_id = $second_category_id; $object->is_active = true; $this->assertTrue($object->store()); $third_object_id = $object->getId(); - $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb, $this->plugins); + $object = new \GaletteObjectsLend\Entity\LendObject($this->zdb); $object->name = 'Fourth object'; $object->serial_number = 'GGABCDEXX'; $object->dimension = '210x297'; @@ -126,7 +124,7 @@ public function testGetList(): void $fourth_object_id = $object->getId(); $filters = new \GaletteObjectsLend\Filters\ObjectsList(); - $objects = new \GaletteObjectsLend\Repository\Objects($this->zdb, $this->plugins, $this->lend_prefs, $filters); + $objects = new \GaletteObjectsLend\Repository\Objects($this->zdb, $this->lend_prefs, $filters); $this->assertCount(4, $objects->getObjectsList(true)); $this->assertSame(4, $objects->getCount()); diff --git a/tests/GaletteObjectsLend/Repository/tests/units/Status.php b/tests/GaletteObjectsLend/Repository/tests/units/Status.php index 3dd3afa..b1f64f4 100644 --- a/tests/GaletteObjectsLend/Repository/tests/units/Status.php +++ b/tests/GaletteObjectsLend/Repository/tests/units/Status.php @@ -32,19 +32,6 @@ class Status extends GaletteTestCase { protected int $seed = 20240526084251; - protected \Galette\Core\Plugins $plugins; - - /** - * Set up tests - * - * @return void - */ - public function setUp(): void - { - parent::setUp(); - $this->plugins = $this->container->get('plugins'); - } - /** * Cleanup after each test method *