1 <?php
2
3 4 5 6 7
8
9 class BigFilesReport extends SS_Report {
10
11 protected $dataClass = 'File';
12
13 function title() {
14 return _t('BigFilesReport.TITLE',"Top 100 big files");
15 }
16
17 function sourceRecords($params, $sort, $limit) {
18
19 if (!$limit) {
20 $limit = array(
21 'limit' => 100,
22 'start' => 0
23 );
24 }
25 if (!$sort) {
26 $sort = "FileSize DESC";
27 }
28 return DataObject::get('File', "ClassName <> 'Folder'", $sort, '', $limit);
29 }
30
31 function columns() {
32 $fields = array(
33 "Title" => array(
34 "title" => _t('BigFilesReport.Title', 'Title')
35 ),
36 "Filename" => array(
37 "title" => _t('BigFilesReport.Filename', 'Filename'),
38 ),
39 'FileSize' => array(
40 'title' => _t('NonUsedFilesReport.Size', 'File size'),
41 'formatting' => '$Size'
42 ),
43 "Created" => array(
44 "title" => _t('BigFilesReport.Created', 'Created at'),
45 ),
46 "LastEdited" => array(
47 "title" => _t('BigFilesReport.LastEdited', 'Last edited at'),
48 ),
49 "Owner.Title" => array(
50 "title" => _t('BigFilesReport.OwnerTitle', 'Owner'),
51 ),
52 "UsageCount" => array(
53 "title" => _t('BigFilesReport.UsageCount', 'Usage count'),
54 'casting' => 'Int'
55 ),
56 );
57 return $fields;
58 }
59
60 function sortColumns() {
61 $fields = array(
62 "Title",
63 "Filename",
64 'FileSize',
65 "Created",
66 "LastEdited"
67 );
68 return $fields;
69 }
70
71 function getReportField() {
72 $columnTitles = array();
73 $fieldFormatting = array();
74 $csvFieldFormatting = array();
75 $fieldCasting = array();
76
77
78 foreach($this->columns() as $source => $info) {
79 if(is_string($info)) $info = array('title' => $info);
80
81 if(isset($info['formatting'])) $fieldFormatting[$source] = $info['formatting'];
82 if(isset($info['csvFormatting'])) $csvFieldFormatting[$source] = $info['csvFormatting'];
83 if(isset($info['casting'])) $fieldCasting[$source] = $info['casting'];
84 $columnTitles[$source] = isset($info['title']) ? $info['title'] : $source;
85 }
86
87 $tlf = new FileComplexTableField($this, 'ReportContent', $this->dataClass(), $columnTitles);
88 $tlf->setCustomQuery($this->sourceQuery($_REQUEST));
89 $tlf->setPageSize(20);
90 $tlf->setHighlightConditions(array(
91 array(
92 'rule' => '$UsageCount == 0',
93 'class' => 'fileNotUsed'
94 ),
95 ));
96
97
98 if($fieldFormatting) $tlf->setFieldFormatting($fieldFormatting);
99 if($csvFieldFormatting) $tlf->setCSVFieldFormatting($csvFieldFormatting);
100 if($fieldCasting) $tlf->setFieldCasting($fieldCasting);
101
102 return $tlf;
103 }
104 }
105
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-