Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 14 additions & 27 deletions lib/GaletteObjectsLend/Controllers/Crud/CategoriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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();
}

Expand Down
50 changes: 16 additions & 34 deletions lib/GaletteObjectsLend/Controllers/Crud/ObjectsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -226,7 +227,6 @@ public function show(Request $request, Response $response, int $id): Response
];
$object = new LendObject(
$this->zdb,
$this->plugins,
$id,
$deps
);
Expand Down Expand Up @@ -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) {
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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'];
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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']);

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -606,7 +591,6 @@ public function lend(Request $request, Response $response, string $action, int $
];
$object = new LendObject(
$this->zdb,
$this->plugins,
$id,
$deps
);
Expand Down Expand Up @@ -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
);

Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'];
Expand Down
2 changes: 1 addition & 1 deletion lib/GaletteObjectsLend/Controllers/ImagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions lib/GaletteObjectsLend/Controllers/PdfController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public function printObject(Request $request, Response $response, int $id): Resp
];
$object = new LendObject(
$this->zdb,
$this->plugins,
$id,
$deps
);
Expand Down Expand Up @@ -98,16 +97,15 @@ 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(
$this->zdb,
$this->preferences,
$lendsprefs,
$filters,
$this->login,
$this->plugins
$this->login
);

$pdf->drawList($list);
Expand Down
7 changes: 2 additions & 5 deletions lib/GaletteObjectsLend/Entity/CategoryPicture.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

namespace GaletteObjectsLend\Entity;

use Galette\Core\Plugins;

/**
* Picture for category
*
Expand All @@ -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);
}
}
16 changes: 6 additions & 10 deletions lib/GaletteObjectsLend/Entity/LendCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
use Analog\Analog;
use ArrayObject;
use Galette\Core\Db;
use Galette\Core\Plugins;
use Laminas\Db\Sql\Predicate;

/**
Expand Down Expand Up @@ -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<string,int|string>|null $args Maybe null, an RS object or an id from database
* @param ?array<string,bool> $deps Dependencies configuration, see LendCategory::$deps
* @param Db $zdb Database instance
* @param int|ArrayObject<string,int|string>|null $args Maybe null, an RS object or an id from database
* @param ?array<string,bool> $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(
Expand All @@ -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)) {
Expand Down Expand Up @@ -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);
}
}

Expand Down
Loading