2014-02-19 03:58:19 +01:00
|
|
|
<?php
|
2015-11-02 00:27:42 +01:00
|
|
|
|
2017-09-06 05:49:23 +02:00
|
|
|
namespace SilverStripe\ContentReview\Reports;
|
|
|
|
|
|
|
|
use SilverStripe\CMS\Controllers\CMSPageEditController;
|
|
|
|
use SilverStripe\CMS\Model\SiteTree;
|
|
|
|
use SilverStripe\CMS\Model\VirtualPage;
|
|
|
|
use SilverStripe\ContentReview\Compatibility\ContentReviewCompatability;
|
|
|
|
use SilverStripe\Core\ClassInfo;
|
2018-01-08 04:47:31 +01:00
|
|
|
use SilverStripe\Forms\CheckboxField;
|
|
|
|
use SilverStripe\Forms\FieldList;
|
2017-09-06 05:49:23 +02:00
|
|
|
use SilverStripe\ORM\ArrayList;
|
|
|
|
use SilverStripe\ORM\DataObject;
|
2018-01-08 04:47:31 +01:00
|
|
|
use SilverStripe\ORM\SS_List;
|
2017-09-06 05:49:23 +02:00
|
|
|
use SilverStripe\Reports\Report;
|
|
|
|
use SilverStripe\SiteConfig\SiteConfig;
|
|
|
|
use SilverStripe\Versioned\Versioned;
|
2014-02-19 03:58:19 +01:00
|
|
|
|
|
|
|
/**
|
2015-11-02 00:27:42 +01:00
|
|
|
* Show all pages that need to be reviewed.
|
2014-02-19 03:58:19 +01:00
|
|
|
*/
|
2017-09-06 05:49:23 +02:00
|
|
|
class PagesWithoutReviewScheduleReport extends Report
|
2015-11-02 00:27:42 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function title()
|
|
|
|
{
|
2018-01-08 21:53:59 +01:00
|
|
|
return _t(__CLASS__ . ".TITLE", "Pages without a scheduled review.");
|
2015-11-02 00:27:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return FieldList
|
|
|
|
*/
|
|
|
|
public function parameterFields()
|
|
|
|
{
|
2017-09-06 05:49:23 +02:00
|
|
|
$params = FieldList::create();
|
|
|
|
$params->push(CheckboxField::create("ShowVirtualPages", "Show Virtual Pages"));
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
return $params;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function columns()
|
|
|
|
{
|
2017-09-06 05:49:23 +02:00
|
|
|
$linkBase = singleton(CMSPageEditController::class)->Link("show");
|
2015-11-02 00:27:42 +01:00
|
|
|
$linkPath = parse_url($linkBase, PHP_URL_PATH);
|
|
|
|
$linkQuery = parse_url($linkBase, PHP_URL_QUERY);
|
|
|
|
|
2018-01-08 04:47:31 +01:00
|
|
|
$fields = [
|
|
|
|
"Title" => [
|
2015-11-02 00:27:42 +01:00
|
|
|
"title" => "Page name",
|
|
|
|
"formatting" => "<a href='{$linkPath}/\$ID?{$linkQuery}' title='Edit page'>\$value</a>",
|
2018-01-08 04:47:31 +01:00
|
|
|
],
|
|
|
|
"NextReviewDate" => [
|
2015-11-02 00:27:42 +01:00
|
|
|
"title" => "Review Date",
|
|
|
|
"casting" => "Date->Full",
|
2018-01-08 04:47:31 +01:00
|
|
|
],
|
|
|
|
"OwnerNames" => [
|
2015-11-02 00:27:42 +01:00
|
|
|
"title" => "Owner",
|
2018-01-08 04:47:31 +01:00
|
|
|
],
|
2015-11-02 00:27:42 +01:00
|
|
|
"LastEditedByName" => "Last edited by",
|
2018-01-08 04:47:31 +01:00
|
|
|
"AbsoluteLink" => [
|
2015-11-02 00:27:42 +01:00
|
|
|
"title" => "URL",
|
|
|
|
"formatting" => function ($value, $item) {
|
|
|
|
$liveLink = $item->AbsoluteLiveLink;
|
|
|
|
$stageLink = $item->AbsoluteLink();
|
|
|
|
|
2017-09-06 05:49:23 +02:00
|
|
|
return sprintf(
|
|
|
|
"%s <a href='%s'>%s</a>",
|
2015-11-02 00:27:42 +01:00
|
|
|
$stageLink,
|
|
|
|
$liveLink ? $liveLink : $stageLink . "?stage=Stage",
|
|
|
|
$liveLink ? "(live)" : "(draft)"
|
|
|
|
);
|
|
|
|
},
|
2018-01-08 04:47:31 +01:00
|
|
|
],
|
|
|
|
"ContentReviewType" => [
|
2015-11-02 00:27:42 +01:00
|
|
|
"title" => "Settings are",
|
|
|
|
"formatting" => function ($value, $item) use ($linkPath, $linkQuery) {
|
|
|
|
if ($item->ContentReviewType == "Inherit") {
|
|
|
|
$options = $item->getOptions();
|
|
|
|
if ($options && $options instanceof SiteConfig) {
|
|
|
|
return "Inherited from <a href='admin/settings'>Settings</a>";
|
|
|
|
} elseif ($options) {
|
|
|
|
return sprintf(
|
|
|
|
"Inherited from <a href='%s/%d?%s'>%s</a>",
|
|
|
|
$linkPath,
|
|
|
|
$options->ID,
|
|
|
|
$linkQuery,
|
|
|
|
$options->Title
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $value;
|
|
|
|
},
|
2018-01-08 04:47:31 +01:00
|
|
|
],
|
|
|
|
];
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $params
|
2022-03-10 21:14:06 +01:00
|
|
|
* @param array|string|null $sort
|
|
|
|
* @param int|null $limit
|
2015-11-02 00:27:42 +01:00
|
|
|
*
|
|
|
|
* @return SS_List
|
|
|
|
*/
|
2022-03-10 21:14:06 +01:00
|
|
|
public function sourceRecords($params = [], $sort = null, $limit = null)
|
2015-11-02 00:27:42 +01:00
|
|
|
{
|
2017-09-06 05:49:23 +02:00
|
|
|
Versioned::set_stage(Versioned::DRAFT);
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
$records = SiteTree::get();
|
|
|
|
$compatibility = ContentReviewCompatability::start();
|
|
|
|
|
|
|
|
// If there's no review dates set, default to all pages due for review now.
|
|
|
|
|
|
|
|
// Show virtual pages?
|
|
|
|
if (empty($params["ShowVirtualPages"])) {
|
2017-09-06 05:49:23 +02:00
|
|
|
$virtualPageClasses = ClassInfo::subclassesFor(VirtualPage::class);
|
2015-11-02 00:27:42 +01:00
|
|
|
$records = $records->where(sprintf(
|
|
|
|
"\"SiteTree\".\"ClassName\" NOT IN ('%s')",
|
|
|
|
implode("','", array_values($virtualPageClasses))
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2022-03-10 21:14:06 +01:00
|
|
|
// Apply sort and limit if appropriate.
|
|
|
|
if ($sort !== null) {
|
|
|
|
$records = $records->sort($sort);
|
|
|
|
}
|
|
|
|
if ($limit !== null) {
|
|
|
|
$records = $records->limit($limit);
|
|
|
|
}
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
// Trim out calculated values
|
2022-03-10 21:14:06 +01:00
|
|
|
$list = $records->filterByCallback(function ($record) {
|
|
|
|
return !$this->hasReviewSchedule($record);
|
|
|
|
});
|
2015-11-02 00:27:42 +01:00
|
|
|
|
|
|
|
ContentReviewCompatability::done($compatibility);
|
|
|
|
|
|
|
|
return $list;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param DataObject $record
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
protected function hasReviewSchedule(DataObject $record)
|
|
|
|
{
|
|
|
|
if (!$record->obj("NextReviewDate")->exists()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$options = $record->getOptions();
|
|
|
|
|
2018-08-20 23:27:05 +02:00
|
|
|
if ($options && $options->OwnerGroups()->count() == 0 && $options->OwnerUsers()->count() == 0) {
|
2015-11-02 00:27:42 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|