Merge pull request #32 from flashbackzoo/pulls/add-user-filter

Add report filter for only the pages a user is assigned to
This commit is contained in:
Damian Mooyman 2015-11-18 10:30:51 +13:00
commit 97adaee9a5
4 changed files with 28 additions and 13 deletions

View File

@ -112,10 +112,7 @@ class ContentReviewDefaultSettings extends DataExtension
*
* @return ArrayList
*/
public function ContentReviewOwners()
{
return new ArrayList();
public function ContentReviewOwners() {
return SiteTreeContentReview::merge_owners($this->OwnerGroups(), $this->OwnerUsers());
}
}

View File

@ -23,16 +23,18 @@ class PagesDueForReviewReport extends SS_Report
$filtersList = new FieldList();
$filtersList->push(
DateField::create("ReviewDateAfter", "Review date after or on")
DateField::create("ReviewDateAfter", _t("PagesDueForReviewReport.REVIEWDATEAFTER", "Review date after or on"))
->setConfig("showcalendar", true)
);
$filtersList->push(
DateField::create("ReviewDateBefore", "Review date before or on", date("d/m/Y", strtotime("midnight")))
DateField::create("ReviewDateBefore", _t("PagesDueForReviewReport.REVIEWDATEBEFORE", "Review date before or on"), date("d/m/Y", strtotime("midnight")))
->setConfig("showcalendar", true)
);
$filtersList->push(new CheckboxField("ShowVirtualPages", "Show Virtual Pages"));
$filtersList->push(new CheckboxField("ShowVirtualPages", _t("PagesDueForReviewReport.SHOWVIRTUALPAGES", "Show Virtual Pages")));
$filtersList->push(new CheckboxField("OnlyMyPages", _t("PagesDueForReviewReport.ONLYMYPAGES", "Only Show pages assigned to me")));
return $filtersList;
}
@ -159,7 +161,23 @@ class PagesDueForReviewReport extends SS_Report
$records = $records->filter("OwnerNames:PartialMatch", $ownerNames);
}
$records = new ArrayList($records->sort("NextReviewDate", "DESC")->toArray());
// Only show pages assigned to the current user?
// This come last because it transforms $records to an ArrayList.
if (!empty($params["OnlyMyPages"])) {
$currentUser = Member::currentUser();
$records = $records->filterByCallback(function($page) use ($currentUser) {
$options = $page->getOptions();
foreach ($options->ContentReviewOwners() as $owner) {
if ($currentUser->ID == $owner->ID) {
return true;
}
}
return false;
});
}
ContentReviewCompatability::done($compatibility);

View File

@ -43,7 +43,7 @@ You'll also need to run `dev/build`.
## Documentation
See the [docs/en](docs/en/introduction.md) folder.
See the [docs/en](docs/en/index.md) folder.
## Versioning

View File

@ -37,11 +37,11 @@ class ContentReviewReportTest extends FunctionalTest
));
$this->assertEquals(array(
"Contact Us",
"Contact Us Child",
"Staff",
"About Us",
"Home",
"About Us",
"Staff",
"Contact Us",
), $results->column("Title"));
SS_Datetime::set_mock_now("2010-02-13 00:00:00");
@ -49,8 +49,8 @@ class ContentReviewReportTest extends FunctionalTest
$results = $report->sourceRecords(array());
$this->assertEquals(array(
"About Us",
"Home",
"About Us",
), $results->column("Title"));
SS_Datetime::clear_mock_now();