Version: current

     1 <?php
     2
     3 /**
     4  * Content side-report listing non used files
     5  * @package cms
     6  * @subpackage content
     7  */
     8
     9 class NonUsedFilesReport extends SS_Report {
    10
    11     protected $dataClass = 'File';
    12
    13     function title() {
    14         return _t('NonUsedFilesReport.NONUSEDFILES',"Non used files report");
    15     }
    16
    17     function sourceRecords($params, $sort, $limit) {
    18         if (!$sort) {
    19             $sort = "FileSize DESC";
    20         }
    21         $where = "ClassName <> 'Folder'";
    22         $IDs = DB::Query("SELECT DISTINCT FileID FROM DataObjectFileTracking")->column();
    23         if (count($IDs)) {
    24             $where .= " AND File.ID NOT IN(" . implode(', ', $IDs) . ")";
    25         }
    26         return DataObject::get('File', $where, $sort, '', $limit);
    27     }
    28
    29     function columns() {
    30         $fields = array(
    31             "Title" => array(
    32                 "title" => _t('NonUsedFilesReport.Title', 'Title'),
    33             ),
    34             "Filename" => array(
    35                 "title" => _t('NonUsedFilesReport.Filename', 'Filename'),
    36             ),
    37             'FileSize' => array(
    38                 'title' => _t('NonUsedFilesReport.Size', 'File size'),
    39                 'formatting' => '$Size'
    40             ),
    41             "Created" => array(
    42                 "title" => _t('NonUsedFilesReport.Created', 'Created at'),
    43             ),
    44             "LastEdited" => array(
    45                 "title" => _t('NonUsedFilesReport.LastEdited', 'Last edited at'),
    46             ),
    47             "Owner.Title" => array(
    48                 "title" => _t('NonUsedFilesReport.OwnerTitle', 'Owner'),
    49             )
    50         );
    51         return $fields;
    52     }
    53
    54     function sortColumns() {
    55         $fields = array(
    56             "Title",
    57             "Filename",
    58             'FileSize',
    59             "Created",
    60             "LastEdited"
    61         );
    62         return $fields;
    63     }
    64
    65     function getReportField() {
    66         $columnTitles = array();
    67         $fieldFormatting = array();
    68         $csvFieldFormatting = array();
    69         $fieldCasting = array();
    70
    71         // Parse the column information
    72         foreach($this->columns() as $source => $info) {
    73             if(is_string($info)) $info = array('title' => $info);
    74
    75             if(isset($info['formatting'])) $fieldFormatting[$source] = $info['formatting'];
    76             if(isset($info['csvFormatting'])) $csvFieldFormatting[$source] = $info['csvFormatting'];
    77             if(isset($info['casting'])) $fieldCasting[$source] = $info['casting'];
    78             $columnTitles[$source] = isset($info['title']) ? $info['title'] : $source;
    79         }
    80
    81         // To do: implement pagination
    82         $query = $this->sourceQuery($_REQUEST);
    83
    84         $tlf = new FileComplexTableField($this, 'ReportContent', $this->dataClass(), $columnTitles);
    85         $tlf->setCustomQuery($query);
    86
    87         if($fieldFormatting) $tlf->setFieldFormatting($fieldFormatting);
    88         if($csvFieldFormatting) $tlf->setCSVFieldFormatting($csvFieldFormatting);
    89         if($fieldCasting) $tlf->setFieldCasting($fieldCasting);
    90
    91         return $tlf;
    92     }
    93 }

[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. -