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
11 changes: 11 additions & 0 deletions .github/workflows/ci-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ jobs:
cd galette-core/galette/plugins/plugin-objectslend
../../vendor/bin/php-cs-fixer check --show-progress=dots --verbose --diff

# Core configuration, with the plugin paths given on the command line;
# run from the core root, where withPhpSets() reads the PHP version
- name: Rector
if: matrix.php-is-min
run: |
cd galette-core
galette/vendor/bin/rector process --dry-run --ansi \
galette/plugins/plugin-objectslend/lib \
galette/plugins/plugin-objectslend/tests \
galette/plugins/plugin-objectslend/*.php

- name: Twig CS
run: |
cd galette-core/galette/plugins/plugin-objectslend
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ abstract public static function getDefaultFilterName(): string;
*/
public function add(Request $request, Response $response): Response
{
return $this->edit($request, $response, null, 'add');
return $this->edit(request: $request, response: $response, id: null, action: 'add');
}

/**
Expand All @@ -172,7 +172,7 @@ public function add(Request $request, Response $response): Response
*/
public function doAdd(Request $request, Response $response): Response
{
return $this->doEdit($request, $response, null, 'add');
return $this->doEdit(request: $request, response: $response, id: null, action: 'add');
}

// /CRUD - Create
Expand Down
11 changes: 8 additions & 3 deletions lib/GaletteObjectsLend/Controllers/Crud/CategoriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,13 @@ protected function createFilters(): CategoriesList
*/
protected function getListView(Pagination $filters): array
{
$categories = new Categories($this->zdb, $this->preferences, $this->login, $filters);
$list = $categories->getCategoriesList(true);
$categories = new Categories(
zdb: $this->zdb,
preferences: $this->preferences,
login: $this->login,
filters: $filters
);
$list = $categories->getCategoriesList(as_cat: true);

return [
'categories_list',
Expand Down Expand Up @@ -185,7 +190,7 @@ public function confirmRemoveTitle(array $args): string
{
return sprintf(
_T('Remove category %1$s', 'objectslend'),
$this->loadEntity((int)$args['id'])->getName(false)
$this->loadEntity((int)$args['id'])->getName(count: false)
);
}
}
71 changes: 49 additions & 22 deletions lib/GaletteObjectsLend/Controllers/Crud/ObjectsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private function getFilters(): ObjectsList
*/
public function add(Request $request, Response $response): Response
{
return $this->edit($request, $response, null, 'add');
return $this->edit(request: $request, response: $response, id: null, action: 'add');
}

/**
Expand All @@ -91,7 +91,7 @@ public function add(Request $request, Response $response): Response
*/
public function doAdd(Request $request, Response $response): Response
{
return $this->doEdit($request, $response, null, 'add');
return $this->doEdit(request: $request, response: $response, id: null, action: 'add');
}

// /CRUD - Create
Expand Down Expand Up @@ -127,14 +127,20 @@ public function list(Request $request, Response $response, ?string $option = nul
}

$lendsprefs = new LendPreferences($this->preferences);
$objects = new Objects($this->zdb, $this->preferences, $this->login, $lendsprefs, $filters);
$list = $objects->getObjectsList(true);
$objects = new Objects(
zdb: $this->zdb,
preferences: $this->preferences,
login: $this->login,
lendsprefs: $lendsprefs,
filters: $filters
);
$list = $objects->getObjectsList(as_objects: true);

$this->session->{$this->getFiltersKey()} = $filters;

//assign pagination variables to the template and add pagination links
$filters->setViewCommonsFilters($lendsprefs, $this->view);
$filters->setViewPagination($this->routeparser, $this->view, false);
$filters->setViewPagination($this->routeparser, $this->view, restricted: false);

$cat_filters = new CategoriesList();
$cat_filters->active_filter = Categories::ACTIVE_CATEGORIES; //retrieve only active categories
Expand All @@ -143,8 +149,13 @@ public function list(Request $request, Response $response, ?string $option = nul
$objects_filters = clone $filters;
$objects_filters->category_filter = null;
$cat_filters->setObjectsFilter($objects_filters);
$categories = new Categories($this->zdb, $this->preferences, $this->login, $cat_filters);
$categories_list = $categories->getCategoriesList(true, false, false);
$categories = new Categories(
zdb: $this->zdb,
preferences: $this->preferences,
login: $this->login,
filters: $cat_filters
);
$categories_list = $categories->getCategoriesList(as_cat: true, count: false, limit: false);

// display page
$this->view->render(
Expand Down Expand Up @@ -301,7 +312,7 @@ public function edit(Request $request, Response $response, ?int $id = null, stri
unset($this->session->objectslend_object_data);

$categories = new Categories($this->zdb, $this->preferences, $this->login);
$categories_list = $categories->getCategoriesList(true);
$categories_list = $categories->getCategoriesList(as_cat: true);

if ($object->getId() !== null) {
$title = _T("Edit object", "objectslend");
Expand All @@ -311,8 +322,13 @@ public function edit(Request $request, Response $response, ?int $id = null, stri

$sfilter = new StatusList();
$sfilter->active_filter = \GaletteObjectsLend\Repository\Status::ACTIVE;
$statuses = new Status($this->zdb, $this->preferences, $this->login, $sfilter);
$slist = $statuses->getStatusList(true);
$statuses = new Status(
zdb: $this->zdb,
preferences: $this->preferences,
login: $this->login,
filters: $sfilter
);
$slist = $statuses->getStatusList(as_stt: true);

$lendsprefs = new LendPreferences($this->preferences);
$params = [
Expand Down Expand Up @@ -492,10 +508,10 @@ public function doUpdateStatus(Request $request, Response $response, ?int $id =

try {
$this->getLendService()->changeStatus(
$object,
(int)($post['new_status'] ?? 0),
empty($post['new_adh']) ? null : (int)$post['new_adh'],
$post['new_comment'] ?? ''
object: $object,
status_id: (int)($post['new_status'] ?? 0),
member_id: empty($post['new_adh']) ? null : (int)$post['new_adh'],
comments: $post['new_comment'] ?? ''
);
$this->flash->addMessage(
'success_detected',
Expand Down Expand Up @@ -729,15 +745,15 @@ public function doTake(Request $request, Response $response, int $id): Response

try {
$contribution = $service->take(
$object,
(int)($post['status'] ?? 0),
$post['expected_return'] ?? null,
empty($post[Adherent::PK]) ? null : (int)$post[Adherent::PK],
empty($post['rent_price'])
object: $object,
status_id: (int)($post['status'] ?? 0),
date_forecast: $post['expected_return'] ?? null,
member_id: empty($post[Adherent::PK]) ? null : (int)$post[Adherent::PK],
rent_price: empty($post['rent_price'])
? null
//FIXME: better currency format handler
: (float)str_replace([' ', ','], ['', '.'], $post['rent_price']),
empty($post['payment_type']) ? null : (int)$post['payment_type']
payment_type: empty($post['payment_type']) ? null : (int)$post['payment_type']
);
} catch (LendException $e) {
$this->flash->addMessage('error_detected', $e->getMessage());
Expand Down Expand Up @@ -832,7 +848,12 @@ private function lendResponse(Request $request, Response $response): Response
*/
private function getLendService(?LendPreferences $lendsprefs = null): LendService
{
return new LendService($this->zdb, $this->preferences, $this->login, $lendsprefs ?? new LendPreferences($this->preferences));
return new LendService(
zdb: $this->zdb,
preferences: $this->preferences,
login: $this->login,
lendsprefs: $lendsprefs ?? new LendPreferences($this->preferences)
);
}

// /CRUD - Update
Expand Down Expand Up @@ -918,7 +939,13 @@ protected function doDelete(array $args, array $post): bool
{
$filters = $this->getFilters();
$lendsprefs = new LendPreferences($this->preferences);
$objects = new Objects($this->zdb, $this->preferences, $this->login, $lendsprefs, $filters);
$objects = new Objects(
zdb: $this->zdb,
preferences: $this->preferences,
login: $this->login,
lendsprefs: $lendsprefs,
filters: $filters
);

if (!is_array($post['id'])) {
$ids = (array)$post['id'];
Expand Down
11 changes: 8 additions & 3 deletions lib/GaletteObjectsLend/Controllers/Crud/StatusController.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,13 @@ protected function applyOwnFilters(Pagination $filters, array $post): void
*/
protected function getListView(Pagination $filters): array
{
$statuses = new Status($this->zdb, $this->preferences, $this->login, $filters);
$list = $statuses->getStatusList(true);
$statuses = new Status(
zdb: $this->zdb,
preferences: $this->preferences,
login: $this->login,
filters: $filters
);
$list = $statuses->getStatusList(as_stt: true);

if (count($statuses->getActiveStockStatuses()) == 0) {
$this->flash->addMessage(
Expand Down Expand Up @@ -128,7 +133,7 @@ protected function fillEntity(LendCategory|LendStatus $entity, array $post): voi
->setText($post['text'])
->setInStock(isset($post['in_stock']))
->setActive(isset($post['is_active']))
->setRentDayNumber(strlen($days) > 0 ? (int)$days : null);
->setRentDayNumber($days !== '' ? (int)$days : null);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/GaletteObjectsLend/Controllers/MainController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function preferences(Request $request, Response $response): Response
$params = [
'page_title' => _T('ObjectsLend preferences', 'objectslend'),
//a rent is not a membership fee
'type_cotis_options' => $ctypes->getList(false),
'type_cotis_options' => $ctypes->getList(extent: false),
'lendsprefs' => (new LendPreferences($this->preferences))->toArray(),
'sample_data' => !(new SampleData($this->zdb))->hasObjects()
];
Expand Down Expand Up @@ -81,7 +81,7 @@ public function storePreferences(Request $request, Response $response): Response
$type_id = $post[LendPreferences::GENERATED_CONTRIBUTION_TYPE_ID] ?? null;
if (
isset($post[LendPreferences::AUTO_GENERATE_CONTRIBUTION])
&& !isset((new ContributionsTypes($this->zdb))->getList(false)[(int)$type_id])
&& !isset((new ContributionsTypes($this->zdb))->getList(extent: false)[(int)$type_id])
) {
$stored = false;
$errors[] = _T("Generated contributions must be of a donation type.", "objectslend");
Expand Down
25 changes: 18 additions & 7 deletions lib/GaletteObjectsLend/Controllers/PdfController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ class PdfController extends GPdfController
public function printObject(Request $request, Response $response, int $id): Response
{
$lendsprefs = new LendPreferences($this->preferences);
$object = (new Objects($this->zdb, $this->preferences, $this->login, $lendsprefs))->getWithCurrentRent($id);
$object = (new Objects(
zdb: $this->zdb,
preferences: $this->preferences,
login: $this->login,
lendsprefs: $lendsprefs
))->getWithCurrentRent($id);

$pdf = new PdfObject(
$this->zdb,
Expand All @@ -65,14 +70,20 @@ 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->preferences, $this->login, $lendsprefs, $filters);
$list = $objects->getObjectsList(true, true, false);
$objects = new Objects(
zdb: $this->zdb,
preferences: $this->preferences,
login: $this->login,
lendsprefs: $lendsprefs,
filters: $filters
);
$list = $objects->getObjectsList(as_objects: true, count: true, limit: false);

$pdf = new PdfObjects(
$this->zdb,
$this->preferences,
$lendsprefs,
$this->login
zdb: $this->zdb,
prefs: $this->preferences,
lendsprefs: $lendsprefs,
login: $this->login
);

$pdf->drawList($list);
Expand Down
10 changes: 3 additions & 7 deletions lib/GaletteObjectsLend/Entity/LendCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,15 @@ class LendCategory
'picture' => true
];

private Db $zdb;

/**
* Default constructor
*
* @param Db $zdb Database instance
* @param int|ArrayObject<string,mixed>|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, int|ArrayObject|null $args = null, ?array $deps = null)
public function __construct(private readonly Db $zdb, int|ArrayObject|null $args = null, ?array $deps = null)
{
$this->zdb = $zdb;

if ($deps !== null) {
$this->deps = array_merge(
$this->deps,
Expand Down Expand Up @@ -156,7 +152,7 @@ public function delete(): void
}
//a picture file removed here comes back from the database on rollback
$picture = new CategoryPicture($this->category_id);
if ($picture->hasPicture() && !$picture->delete(false)) {
if ($picture->hasPicture() && !$picture->delete(transaction: false)) {
throw new \RuntimeException('Unable to remove picture');
}
$select = $this->zdb->select(LEND_PREFIX . LendObject::TABLE)
Expand Down Expand Up @@ -191,7 +187,7 @@ public function delete(): void
*/
public function getName(bool $count = true): string
{
$name = $this->name !== null ? $this->name : _T("No category", "objectslend");
$name = $this->name ?? _T("No category", "objectslend");

if ($count === true) {
$name .= " ({$this->objects_nb})";
Expand Down
4 changes: 2 additions & 2 deletions lib/GaletteObjectsLend/Entity/LendObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class LendObject
* @param Db $zdb Database instance
* @param int|ArrayObject<string,mixed>|null $args Maybe null, an RS object or an id from database
*/
public function __construct(private Db $zdb, int|ArrayObject|null $args = null)
public function __construct(private readonly Db $zdb, int|ArrayObject|null $args = null)
{
if (is_int($args)) {
$select = $this->zdb->select(LEND_PREFIX . self::TABLE)
Expand Down Expand Up @@ -202,7 +202,7 @@ public function delete(): void
}
//a picture file removed here comes back from the database on rollback
$picture = $this->getPicture();
if ($picture->hasPicture() && !$picture->delete(false)) {
if ($picture->hasPicture() && !$picture->delete(transaction: false)) {
throw new \RuntimeException('Unable to remove picture');
}
//remove rents
Expand Down
8 changes: 4 additions & 4 deletions lib/GaletteObjectsLend/Entity/LendRent.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class LendRent
* @param Db $zdb Database instance
* @param int|ArrayObject<string,mixed>|null $args Either an int with rent id, null, or a resultset row
*/
public function __construct(private Db $zdb, int|ArrayObject|null $args = null)
public function __construct(private readonly Db $zdb, int|ArrayObject|null $args = null)
{
$this->date_begin = date('Y-m-d H:i:s');

Expand Down Expand Up @@ -256,7 +256,7 @@ public function getDateBegin(): string
*/
public function setDateBegin(string $date): self
{
$this->date_begin = $this->parseDate($date, true) ?? $this->date_begin;
$this->date_begin = $this->parseDate($date, datetime: true) ?? $this->date_begin;
return $this;
}

Expand All @@ -275,7 +275,7 @@ public function getDateForecast(): string
*/
public function setDateForecast(string $date): self
{
$this->date_forecast = $this->parseDate($date, false);
$this->date_forecast = $this->parseDate($date, datetime: false);
return $this;
}

Expand All @@ -294,7 +294,7 @@ public function getDateEnd(): string
*/
public function setDateEnd(string $date): self
{
$this->date_end = $this->parseDate($date, true);
$this->date_end = $this->parseDate($date, datetime: true);
return $this;
}

Expand Down
Loading
Loading