/
page_changes.php
83 lines (71 loc) · 2.34 KB
/
page_changes.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
<?php
namespace Concrete\Controller\SinglePage\Dashboard\Reports;
use Concrete\Core\Csv\Export\PageActivityExporter;
use Concrete\Core\Csv\WriterFactory;
use Concrete\Core\Page\Controller\DashboardPageController;
use Concrete\Core\Page\Collection\Version\GlobalVersionList;
use Symfony\Component\HttpFoundation\StreamedResponse;
class PageChanges extends DashboardPageController
{
public function view()
{
$this->set('dt', $this->app->make('helper/form/date_time'));
}
public function csv_export()
{
if (!$this->token->validate('export_page_changes')) {
$this->error->add($this->token->getErrorMessage());
}
if ($this->error->has()) {
return $this->view();
}
return StreamedResponse::create(
function () {
$writer = $this->getWriter();
$writer->setUnloadDoctrineEveryTick(50);
$writer->insertHeaders();
$writer->insertList($this->getVersionList());
},
200,
[
'Content-Type' => 'text/csv',
'Content-Disposition' => 'attachment; filename=page_changes.csv',
]
);
}
/**
* Get the writer that will create the CSV.
*
* @return \Concrete\Core\Csv\Export\PageActivityExporter
*/
private function getWriter()
{
return $this->app->make(
PageActivityExporter::class, [
'writer' => $this->app->make(WriterFactory::class)
->createFromPath('php://output', 'w'),
]
);
}
/**
* Get the item list object.
*
* @return \Concrete\Core\Page\Collection\Version\GlobalVersionList
*/
private function getVersionList()
{
/* @var \Concrete\Core\Form\Service\Widget\DateTime $dt */
$dt = $this->app->make('helper/form/date_time');
$startDate = $dt->translate('startDate', null, true);
$endDate = $dt->translate('endDate', null, true);
$versionList = new GlobalVersionList();
$versionList->sortByDateApprovedDesc();
if ($startDate !== null) {
$versionList->filterByApprovedAfter($startDate);
}
if ($endDate !== null) {
$versionList->filterByApprovedBefore($endDate);
}
return $versionList;
}
}