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
6 changes: 3 additions & 3 deletions lib/GaletteObjectsLend/Controllers/Crud/ObjectsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ public function doUpdateStatus(Request $request, Response $response, ?int $id =
->withStatus(301)
->withHeader(
'Location',
$this->routeparser->urlFor('objectslend_object_edit', ['id' => $object->getId()])
$this->routeparser->urlFor('objectslend_object_edit', ['id' => (string)$object->getId()])
);
}

Expand Down Expand Up @@ -579,7 +579,7 @@ public function doClone(Request $request, Response $response, int $id): Response
'Location',
$this->routeparser->urlFor(
'objectslend_object_edit',
['id' => $object->getId()]
['id' => (string)$object->getId()]
)
);
}
Expand Down Expand Up @@ -902,7 +902,7 @@ public function confirmRemoveTitle(array $args): string
$filters = $this->getFilters();
return str_replace(
'%count',
count($filters->selected),
(string)count($filters->selected),
_T('You are about to remove %count objects.', 'objectslend')
);
}
Expand Down
1 change: 0 additions & 1 deletion lib/GaletteObjectsLend/Controllers/PdfController.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public function printObjects(Request $request, Response $response): Response
$this->zdb,
$this->preferences,
$lendsprefs,
$filters,
$this->login
);

Expand Down
56 changes: 25 additions & 31 deletions lib/GaletteObjectsLend/IO/PdfObjects.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Galette\Core\Preferences;
use Galette\Core\Login;
use GaletteObjectsLend\Entity\LendObject;
use GaletteObjectsLend\Filters\ObjectsList;
use GaletteObjectsLend\Entity\LendCategory;
use GaletteObjectsLend\LendPreferences;

Expand All @@ -31,7 +30,6 @@ class PdfObjects extends Pdf

private Db $zdb;
private LendPreferences $lendsprefs;
private ObjectsList $filters;
private Login $login;

/**
Expand All @@ -40,14 +38,12 @@ class PdfObjects extends Pdf
* @param Db $zdb Database instance
* @param Preferences $prefs Preferences
* @param LendPreferences $lendsprefs Plugin preferences
* @param ObjectsList $filters Current filters
* @param Login $login Login instance
*/
public function __construct(
Db $zdb,
Preferences $prefs,
LendPreferences $lendsprefs,
ObjectsList $filters,
Login $login,
) {
parent::__construct($prefs);
Expand All @@ -58,7 +54,6 @@ public function __construct(
$this->filename = _T('objects_cards', 'objectslend') . '.pdf';
$this->zdb = $zdb;
$this->lendsprefs = $lendsprefs;
$this->filters = $filters;
$this->login = $login;
}

Expand Down Expand Up @@ -91,7 +86,7 @@ public function Header(): void
// @phpcs:enable
$this->SetFont(Pdf::FONT, 'B');
$x = $this->getX();
$this->Cell(0, 10, _T("Objects list", "objectslend"), 0, false, 'C', false, '', 0, false, 'M', 'M');
$this->Cell(0, 10, _T("Objects list", "objectslend"), 0, 0, 'C', false, '', 0, false, 'M', 'M');
$this->SetFont(Pdf::FONT, '', self::LIST_FONT);
$this->setX($x);
$this->Cell(
Expand All @@ -103,7 +98,7 @@ public function Header(): void
_T("Printed on %date", "objectslend")
),
0,
false,
0,
'R',
false,
'',
Expand Down Expand Up @@ -137,56 +132,55 @@ public function drawList(array $objects): void
$w_date = 22;
$w_adherent = 26;

$this->Cell($w_checkbox, 0, $this->stretchHead('', $w_checkbox), 1, 0, 'C', 1);
$this->Cell($w_name, 0, $this->stretchHead(_T("Name", "objectslend"), $w_name), 1, 0, 'C', 1);
$this->Cell($w_description, 0, $this->stretchHead(_T("Description", "objectslend"), $w_description), 1, 0, 'C', 1);
$this->Cell($w_serial, 0, $this->stretchHead(_T("Serial", "objectslend"), $w_serial), 1, 0, 'C', 1);
$this->Cell($w_price, 0, $this->stretchHead(_T("Price", "objectslend"), $w_price), 1, 0, 'C', 1);
$this->Cell($w_price, 0, $this->stretchHead(_T("Borrow price", "objectslend"), $w_price), 1, 0, 'C', 1);
$this->Cell($w_dimension, 0, $this->stretchHead(_T("Dimensions", "objectslend"), $w_dimension), 1, 0, 'C', 1);
$this->Cell($w_weight, 0, $this->stretchHead(_T("Weight", "objectslend"), $w_weight), 1, 0, 'C', 1);
$this->Cell($w_status, 0, $this->stretchHead(_T("Status", "objectslend"), $w_status), 1, 0, 'C', 1);
$this->Cell($w_date, 0, $this->stretchHead(_T("Since", "objectslend"), $w_date), 1, 0, 'C', 1);
$this->Cell($w_adherent, 0, $this->stretchHead(_T("Member", "objectslend"), $w_adherent), 1, 0, 'C', 1);
$this->Cell($w_date, 0, $this->stretchHead(_T("Return", "objectslend"), $w_date), 1, 1, 'C', 1);
$this->Cell($w_checkbox, 0, $this->stretchHead('', $w_checkbox), 1, 0, 'C', true);
$this->Cell($w_name, 0, $this->stretchHead(_T("Name", "objectslend"), $w_name), 1, 0, 'C', true);
$this->Cell($w_description, 0, $this->stretchHead(_T("Description", "objectslend"), $w_description), 1, 0, 'C', true);
$this->Cell($w_serial, 0, $this->stretchHead(_T("Serial", "objectslend"), $w_serial), 1, 0, 'C', true);
$this->Cell($w_price, 0, $this->stretchHead(_T("Price", "objectslend"), $w_price), 1, 0, 'C', true);
$this->Cell($w_price, 0, $this->stretchHead(_T("Borrow price", "objectslend"), $w_price), 1, 0, 'C', true);
$this->Cell($w_dimension, 0, $this->stretchHead(_T("Dimensions", "objectslend"), $w_dimension), 1, 0, 'C', true);
$this->Cell($w_weight, 0, $this->stretchHead(_T("Weight", "objectslend"), $w_weight), 1, 0, 'C', true);
$this->Cell($w_status, 0, $this->stretchHead(_T("Status", "objectslend"), $w_status), 1, 0, 'C', true);
$this->Cell($w_date, 0, $this->stretchHead(_T("Since", "objectslend"), $w_date), 1, 0, 'C', true);
$this->Cell($w_adherent, 0, $this->stretchHead(_T("Member", "objectslend"), $w_adherent), 1, 0, 'C', true);
$this->Cell($w_date, 0, $this->stretchHead(_T("Return", "objectslend"), $w_date), 1, 1, 'C', true);

$this->SetFont('');

$current_category = -1;
//objects come ordered by category: a heading, and the previous
//category subtotal, each time it changes
$current_category = null;
$sum_price = 0;
$grant_total = 0;
$row = 0;
$existing_categories = [];

foreach ($objects as $object) {
$category_id = (int)$object->getCategoryId();
if (
$this->lendsprefs->isEnabled(LendPreferences::VIEW_CATEGORY)
&& $current_category !== $object->getCategoryId()
&& $current_category !== $category_id
) {
$this->SetFont('', 'B');

if (($this->login->isAdmin() || $this->login->isStaff()) && $sum_price > 0 && !in_array($object->getCategoryId(), $existing_categories)) {
if (($this->login->isAdmin() || $this->login->isStaff()) && $sum_price > 0) {
$width = $w_checkbox + $w_name + $w_description + $w_serial + $w_price;
$this->Cell($width, 0, number_format($sum_price, 2, ',', ''), '', 0, 'R');
$sum_price = 0;
$this->Ln();
}

if (!empty($object->getCategoryId()) && !in_array($object->getCategoryId(), $existing_categories)) {
$category = new LendCategory($this->zdb, (int)$object->getCategoryId());
if ($category_id > 0) {
$category = new LendCategory($this->zdb, $category_id);
$text = str_replace(
'%category',
$category->getName(false),
_T("Category: %category", "objectslend")
);
$existing_categories[] = $object->getCategoryId();
$this->Cell(0, 0, $text, 0, 1, 'C');
} elseif (!in_array(0, $existing_categories)) {
} else {
$text = _T("No category", "objectslend");
$existing_categories[0] = 0;
$this->Cell(0, 0, $text, 0, 1, 'C');
}

$this->Cell(0, 0, $text, 0, 1, 'C');
$current_category = $category_id;

$this->SetFont('');
}
Expand Down
3 changes: 2 additions & 1 deletion lib/GaletteObjectsLend/Repository/Objects.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ protected function buildOrderClause(): array
self::ORDERBY_BDATE => ['r.date_begin'],
self::ORDERBY_FDATE => ['r.date_forecast'],
self::ORDERBY_MEMBER => ['a.nom_adh', 'a.prenom_adh'],
self::ORDERBY_CATEGORY => ['c.name'],
//homonymous categories must not be mixed: the objects list PDF relies on it
self::ORDERBY_CATEGORY => ['c.name', 'o.category_id'],
default => []
};

Expand Down
31 changes: 0 additions & 31 deletions phpstan-baseline.neon

This file was deleted.

3 changes: 0 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
includes:
- phpstan-baseline.neon

parameters:
parallel:
maximumNumberOfProcesses: 2
Expand Down
39 changes: 39 additions & 0 deletions tests/GaletteObjectsLend/Repository/tests/units/Objects.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,43 @@ public function testGetList(): void
$objects->removeObjects([$first_object_id, $second_object_id, $third_object_id]);
$this->assertCount(1, $objects->getObjectsList(true));
}

/**
* Objects of homonymous categories are not mixed when ordered by category
*/
public function testOrderByHomonymousCategories(): void
{
$category_ids = [];
foreach ([1, 2] as $i) {
$category = new \GaletteObjectsLend\Entity\LendCategory($this->zdb);
$category->setName('Same name');
$category->setActive(true);
$category->store();
$category_ids[] = $category->getId();
}

//stored alternately, so that an order on the name alone may mix them
foreach ([0, 1, 0, 1, 0, 1] as $i => $index) {
$object = new \GaletteObjectsLend\Entity\LendObject($this->zdb);
$object->setName('Object ' . $i);
$object->setCategoryId($category_ids[$index]);
$object->setActive(true);
$object->store();
}

$filters = new \GaletteObjectsLend\Filters\ObjectsList();
$filters->orderby = \GaletteObjectsLend\Repository\Objects::ORDERBY_CATEGORY;
$objects = new \GaletteObjectsLend\Repository\Objects($this->zdb, $this->preferences, $this->login, $this->lend_prefs, $filters);
$list = $objects->getObjectsList(true, true, false);
$this->assertCount(6, $list);

$sequence = array_map(fn($object) => $object->getCategoryId(), $list);
$changes = 0;
for ($i = 1; $i < count($sequence); $i++) {
if ($sequence[$i] !== $sequence[$i - 1]) {
$changes++;
}
}
$this->assertSame(1, $changes, 'Categories order: ' . implode(', ', $sequence));
}
}
Loading