Add report filter for only the pages a user is assigned to

This commit is contained in:
David Craig 2015-11-12 16:00:34 +13:00
parent 8980e29320
commit fc6caa2011
4 changed files with 28 additions and 13 deletions

View File

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

View File

@ -23,16 +23,18 @@ class PagesDueForReviewReport extends SS_Report
$filtersList = new FieldList(); $filtersList = new FieldList();
$filtersList->push( $filtersList->push(
DateField::create("ReviewDateAfter", "Review date after or on") DateField::create("ReviewDateAfter", _t("PagesDueForReviewReport.REVIEWDATEAFTER", "Review date after or on"))
->setConfig("showcalendar", true) ->setConfig("showcalendar", true)
); );
$filtersList->push( $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) ->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; return $filtersList;
} }
@ -159,7 +161,23 @@ class PagesDueForReviewReport extends SS_Report
$records = $records->filter("OwnerNames:PartialMatch", $ownerNames); $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); ContentReviewCompatability::done($compatibility);

View File

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

View File

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