Skip to content

Add prepend/append options to BaseListView #273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 15, 2025
Merged
Changes from 3 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
33 changes: 33 additions & 0 deletions src/BaseListView.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@
*/
private ?string $containerTag = 'div';
private array $containerAttributes = [];
private string $prepend = '';
private string $append = '';

/**
* @psalm-var non-empty-string|null
Expand Down Expand Up @@ -218,7 +220,7 @@
return $new;
}

final public function multiSort(bool $enable = true): static

Check warning on line 223 in src/BaseListView.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "TrueValue": @@ @@ $new->urlParameterProvider = $provider; return $new; } - final public function multiSort(bool $enable = true): static + final public function multiSort(bool $enable = false): static { $new = clone $this; $new->multiSort = $enable;
{
$new = clone $this;
$new->multiSort = $enable;
Expand Down Expand Up @@ -248,6 +250,30 @@
return $new;
}

/**
* Returns a new instance with HTML content to be added after the open container tag.
*
* @param string|Stringable $prepend The HTML content to be prepended.
*/
final public function prepend(string|Stringable $prepend): static

Check warning on line 258 in src/BaseListView.php

View check run for this annotation

Codecov / codecov/patch

src/BaseListView.php#L258

Added line #L258 was not covered by tests
{
$new = clone $this;
$new->prepend = (string) $prepend;
return $new;

Check warning on line 262 in src/BaseListView.php

View check run for this annotation

Codecov / codecov/patch

src/BaseListView.php#L260-L262

Added lines #L260 - L262 were not covered by tests
}

/**
* Returns a new instance with HTML content to be added before the close container tag.
*
* @param string|Stringable $append The HTML content to be appended.
*/
final public function append(string|Stringable $append): static

Check warning on line 270 in src/BaseListView.php

View check run for this annotation

Codecov / codecov/patch

src/BaseListView.php#L270

Added line #L270 was not covered by tests
{
$new = clone $this;
$new->append = (string) $append;
return $new;

Check warning on line 274 in src/BaseListView.php

View check run for this annotation

Codecov / codecov/patch

src/BaseListView.php#L272-L274

Added lines #L272 - L274 were not covered by tests
}

/**
* Return a new instance with the empty text.
*
Expand Down Expand Up @@ -543,6 +569,13 @@
)
);

if ($this->prepend !== '') {
$content = $this->prepend . "\n" . $content;

Check warning on line 573 in src/BaseListView.php

View check run for this annotation

Codecov / codecov/patch

src/BaseListView.php#L573

Added line #L573 was not covered by tests
}
if ($this->append !== '') {
$content .= "\n" . $this->append;

Check warning on line 576 in src/BaseListView.php

View check run for this annotation

Codecov / codecov/patch

src/BaseListView.php#L576

Added line #L576 was not covered by tests
}

return $this->containerTag === null
? $content
: Html::tag($this->containerTag, "\n" . $content . "\n", $this->containerAttributes)
Expand Down Expand Up @@ -593,7 +626,7 @@
*
* @psalm-return list{FilterInterface[]|null,ValidationResult}
*/
protected function makeFilters(): array

Check warning on line 629 in src/BaseListView.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "ProtectedVisibility": @@ @@ * * @psalm-return list{FilterInterface[]|null,ValidationResult} */ - protected function makeFilters(): array + private function makeFilters(): array { return [[], new ValidationResult()]; }
{
return [[], new ValidationResult()];
}
Expand Down Expand Up @@ -762,7 +795,7 @@
}
}

if (!empty($sort) && $dataReader->isSortable()) {

Check warning on line 798 in src/BaseListView.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "LogicalAndSingleSubExprNegation": @@ @@ $dataReader = $dataReader->withToken(PageToken::previous($previousPage)); } } - if (!empty($sort) && $dataReader->isSortable()) { + if (!empty($sort) && !$dataReader->isSortable()) { $sortObject = $dataReader->getSort(); if ($sortObject !== null) { $order = OrderHelper::stringToArray($sort);
$sortObject = $dataReader->getSort();
if ($sortObject !== null) {
$order = OrderHelper::stringToArray($sort);
Expand All @@ -777,7 +810,7 @@
}
}

if (!empty($filters) && $dataReader->isFilterable()) {

Check warning on line 813 in src/BaseListView.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "LogicalAndSingleSubExprNegation": @@ @@ $dataReader = $dataReader->withSort($sortObject->withOrder($this->prepareOrder($order))); } } - if (!empty($filters) && $dataReader->isFilterable()) { + if (!empty($filters) && !$dataReader->isFilterable()) { $dataReader = $dataReader->withFilter(new All(...$filters)); } return $dataReader;

Check warning on line 813 in src/BaseListView.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "LogicalAndNegation": @@ @@ $dataReader = $dataReader->withSort($sortObject->withOrder($this->prepareOrder($order))); } } - if (!empty($filters) && $dataReader->isFilterable()) { + if (!(!empty($filters) && $dataReader->isFilterable())) { $dataReader = $dataReader->withFilter(new All(...$filters)); } return $dataReader;

Check warning on line 813 in src/BaseListView.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "LogicalAnd": @@ @@ $dataReader = $dataReader->withSort($sortObject->withOrder($this->prepareOrder($order))); } } - if (!empty($filters) && $dataReader->isFilterable()) { + if (!empty($filters) || $dataReader->isFilterable()) { $dataReader = $dataReader->withFilter(new All(...$filters)); } return $dataReader;
$dataReader = $dataReader->withFilter(new All(...$filters));
}

Expand Down Expand Up @@ -921,7 +954,7 @@
$currentPage = $dataReader->getCurrentPage();

// The starting row number (1-based) currently being displayed
$begin = ($currentPage - 1) * $dataReader->getPageSize() + 1;

Check warning on line 957 in src/BaseListView.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "Multiplication": @@ @@ // The page number (1-based) current being displayed $currentPage = $dataReader->getCurrentPage(); // The starting row number (1-based) currently being displayed - $begin = ($currentPage - 1) * $dataReader->getPageSize() + 1; + $begin = ($currentPage - 1) / $dataReader->getPageSize() + 1; // The number of rows currently being displayed $count = $dataReader->getCurrentPageSize(); // The ending row number (1-based) currently being displayed

Check warning on line 957 in src/BaseListView.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "Minus": @@ @@ // The page number (1-based) current being displayed $currentPage = $dataReader->getCurrentPage(); // The starting row number (1-based) currently being displayed - $begin = ($currentPage - 1) * $dataReader->getPageSize() + 1; + $begin = ($currentPage + 1) * $dataReader->getPageSize() + 1; // The number of rows currently being displayed $count = $dataReader->getCurrentPageSize(); // The ending row number (1-based) currently being displayed

Check warning on line 957 in src/BaseListView.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "IncrementInteger": @@ @@ // The page number (1-based) current being displayed $currentPage = $dataReader->getCurrentPage(); // The starting row number (1-based) currently being displayed - $begin = ($currentPage - 1) * $dataReader->getPageSize() + 1; + $begin = ($currentPage - 2) * $dataReader->getPageSize() + 1; // The number of rows currently being displayed $count = $dataReader->getCurrentPageSize(); // The ending row number (1-based) currently being displayed

Check warning on line 957 in src/BaseListView.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "DecrementInteger": @@ @@ // The page number (1-based) current being displayed $currentPage = $dataReader->getCurrentPage(); // The starting row number (1-based) currently being displayed - $begin = ($currentPage - 1) * $dataReader->getPageSize() + 1; + $begin = ($currentPage - 0) * $dataReader->getPageSize() + 1; // The number of rows currently being displayed $count = $dataReader->getCurrentPageSize(); // The ending row number (1-based) currently being displayed

// The number of rows currently being displayed
$count = $dataReader->getCurrentPageSize();
Expand Down