Issues (144)

src/Reports/SubsiteReportWrapper.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace SilverStripe\Subsites\Reports;
4
5
use SilverStripe\Forms\FieldList;
6
use SilverStripe\Forms\TreeMultiselectField;
7
use SilverStripe\Reports\ReportWrapper;
8
use SilverStripe\Subsites\Model\Subsite;
9
10
/**
11
 * Creates a subsite-aware version of another report.
12
 * Pass another report (or its classname) into the constructor.
13
 */
14
class SubsiteReportWrapper extends ReportWrapper
15
{
16
17
    /**
18
     * @return FieldList
19
     */
20
    public function parameterFields()
21
    {
22
        $subsites = Subsite::accessible_sites('CMS_ACCESS_CMSMain', true);
23
        $options = $subsites->toDropdownMap('ID', 'Title');
24
25
        $subsiteField = TreeMultiselectField::create(
26
            'Subsites',
27
            _t(__CLASS__ . '.ReportDropdown', 'Sites'),
28
            $options
29
        );
30
        $subsiteField->setValue(array_keys($options));
31
32
        // We don't need to make the field editable if only one subsite is available
33
        if (sizeof($options) <= 1) {
34
            $subsiteField = $subsiteField->performReadonlyTransformation();
35
        }
36
37
        $fields = parent::parameterFields();
38
        if ($fields) {
39
            $fields->insertBefore($subsiteField, $fields->First()->Name());
40
        } else {
41
            $fields = FieldList::create($subsiteField);
42
        }
43
        return $fields;
44
    }
45
46
    /**
47
     * @return array
48
     */
49
    public function columns()
50
    {
51
        $columns = parent::columns();
52
        $columns['Subsite.Title'] = Subsite::class;
53
        return $columns;
54
    }
55
56
    ///////////////////////////////////////////////////////////////////////////////////////////
57
    // Querying
58
59
    /**
60
     * @param arary $params
0 ignored issues
show
The type SilverStripe\Subsites\Reports\arary was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
61
     * @return void
62
     */
63
    public function beforeQuery($params)
64
    {
65
        // The user has select a few specific sites
66
        if (!empty($params['Subsites'])) {
67
            Subsite::$force_subsite = $params['Subsites'];
68
69
            // Default: restrict to all accessible sites
70
        } else {
71
            $subsites = Subsite::accessible_sites('CMS_ACCESS_CMSMain');
72
            $options = $subsites->toDropdownMap('ID', 'Title');
73
            Subsite::$force_subsite = join(',', array_keys($options));
74
        }
75
    }
76
77
    /**
78
     * @return void
79
     */
80
    public function afterQuery()
81
    {
82
        // Manually manage the subsite filtering
83
        Subsite::$force_subsite = null;
84
    }
85
}
86