/
PagesWithoutReviewScheduleReport.php
148 lines (127 loc) · 4.33 KB
/
PagesWithoutReviewScheduleReport.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
require_once "Zend/Date.php";
/**
* Show all pages that need to be reviewed.
*/
class PagesWithoutReviewScheduleReport extends SS_Report
{
/**
* @return string
*/
public function title()
{
return _t("PagesWithoutReviewScheduleReport.TITLE", "Pages without a scheduled review.");
}
/**
* @return FieldList
*/
public function parameterFields()
{
$params = new FieldList();
$params->push(new CheckboxField("ShowVirtualPages", "Show Virtual Pages"));
return $params;
}
/**
* @return array
*/
public function columns()
{
$linkBase = singleton("CMSPageEditController")->Link("show");
$linkPath = parse_url($linkBase, PHP_URL_PATH);
$linkQuery = parse_url($linkBase, PHP_URL_QUERY);
$fields = array(
"Title" => array(
"title" => "Page name",
"formatting" => "<a href='{$linkPath}/\$ID?{$linkQuery}' title='Edit page'>\$value</a>",
),
"NextReviewDate" => array(
"title" => "Review Date",
"casting" => "Date->Full",
),
"OwnerNames" => array(
"title" => "Owner",
),
"LastEditedByName" => "Last edited by",
"AbsoluteLink" => array(
"title" => "URL",
"formatting" => function ($value, $item) {
$liveLink = $item->AbsoluteLiveLink;
$stageLink = $item->AbsoluteLink();
return sprintf("%s <a href='%s'>%s</a>",
$stageLink,
$liveLink ? $liveLink : $stageLink . "?stage=Stage",
$liveLink ? "(live)" : "(draft)"
);
},
),
"ContentReviewType" => array(
"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;
},
),
);
return $fields;
}
/**
* @param array $params
*
* @return SS_List
*/
public function sourceRecords($params = array())
{
Versioned::reading_stage("Stage");
$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"])) {
$virtualPageClasses = ClassInfo::subclassesFor("VirtualPage");
$records = $records->where(sprintf(
"\"SiteTree\".\"ClassName\" NOT IN ('%s')",
implode("','", array_values($virtualPageClasses))
));
}
$records->sort("ParentID");
$records = $records->toArray();
// Trim out calculated values
$list = new ArrayList();
foreach ($records as $record) {
if (!$this->hasReviewSchedule($record)) {
$list->push($record);
}
}
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();
if ($options->OwnerGroups()->count() == 0 && $options->OwnerUsers()->count() == 0) {
return false;
}
return true;
}
}