Skip to content
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

ENH: Respect sort and limit arguments #158

Merged
merged 1 commit into from
Mar 10, 2022
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
12 changes: 11 additions & 1 deletion src/Reports/PagesDueForReviewReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,26 @@ public function columns()

/**
* @param array $params
* @param array|string|null $sort
* @param int|null $limit
*
* @return SS_List
*/
public function sourceRecords($params = [])
public function sourceRecords($params = [], $sort = null, $limit = null)
{
Versioned::set_stage(Versioned::DRAFT);

$records = SiteTree::get();
$compatibility = ContentReviewCompatability::start();

// Apply sort and limit if appropriate.
if ($sort !== null) {
$records = $records->sort($sort);
}
if ($limit !== null) {
$records = $records->limit($limit);
}

if (empty($params['ReviewDateBefore']) && empty($params['ReviewDateAfter'])) {
// If there's no review dates set, default to all pages due for review now
$records = $records->where(
Expand Down
22 changes: 13 additions & 9 deletions src/Reports/PagesWithoutReviewScheduleReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,12 @@ public function columns()

/**
* @param array $params
* @param array|string|null $sort
* @param int|null $limit
*
* @return SS_List
*/
public function sourceRecords($params = [])
public function sourceRecords($params = [], $sort = null, $limit = null)
{
Versioned::set_stage(Versioned::DRAFT);

Expand All @@ -125,16 +127,18 @@ public function sourceRecords($params = [])
));
}

$records->sort("ParentID");
$records = $records->toArray();
// Apply sort and limit if appropriate.
if ($sort !== null) {
GuySartorelli marked this conversation as resolved.
Show resolved Hide resolved
$records = $records->sort($sort);
}
if ($limit !== null) {
$records = $records->limit($limit);
}

// Trim out calculated values
$list = ArrayList::create();
foreach ($records as $record) {
if (!$this->hasReviewSchedule($record)) {
$list->push($record);
}
}
$list = $records->filterByCallback(function ($record) {
return !$this->hasReviewSchedule($record);
});

ContentReviewCompatability::done($compatibility);

Expand Down
12 changes: 6 additions & 6 deletions tests/php/ContentReviewReportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ public function testPagesWithoutReviewScheduleReport()

$results = $report->sourceRecords();

$this->assertEquals([
"Home",
"About Us",
"Page without review date",
"Page owned by group",
], $results->column("Title"));
$this->assertListEquals([
['Title' => 'Home'],
['Title' => 'About Us'],
['Title' => 'Page without review date'],
['Title' => 'Page owned by group'],
], $results);
}
}