1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DNADesign\Elemental\Reports; |
4
|
|
|
|
5
|
|
|
use DNADesign\Elemental\Models\BaseElement; |
6
|
|
|
use SilverStripe\Core\ClassInfo; |
7
|
|
|
use SilverStripe\Core\Injector\Injector; |
8
|
|
|
use SilverStripe\Forms\GridField\GridField; |
9
|
|
|
use SilverStripe\ORM\ArrayList; |
10
|
|
|
use SilverStripe\Reports\Report; |
11
|
|
|
use SilverStripe\View\ArrayData; |
12
|
|
|
use SilverStripe\View\Requirements; |
13
|
|
|
|
14
|
|
|
class ElementTypeReport extends Report |
15
|
|
|
{ |
16
|
|
|
public function title() |
17
|
|
|
{ |
18
|
|
|
return _t(__CLASS__ . '.Title', 'Content block types'); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function description() |
22
|
|
|
{ |
23
|
|
|
return _t(__CLASS__ . '.Description', 'Show which types of content blocks exist'); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function sourceRecords($params = []) |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
$classes = $this->getElementTypes(); |
29
|
|
|
$output = ArrayList::create(); |
30
|
|
|
|
31
|
|
|
foreach ($classes as $class) { |
32
|
|
|
/** @var BaseElement $element */ |
33
|
|
|
$element = Injector::inst()->create($class); |
34
|
|
|
|
35
|
|
|
$output->push(ArrayData::create([ |
36
|
|
|
'Icon' => $element->getIcon(), |
37
|
|
|
'Type' => $element->getType(), |
38
|
|
|
'TypeNice' => $element->getTypeNice(), |
39
|
|
|
'ClassName' => $element->sanitiseClassName($class), |
40
|
|
|
'Total' => $class::get()->count(), |
41
|
|
|
])); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return $output; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Return an array of all valid classes that extend BaseElement |
49
|
|
|
* |
50
|
|
|
* @return string[] |
51
|
|
|
*/ |
52
|
|
|
protected function getElementTypes() |
53
|
|
|
{ |
54
|
|
|
$classes = ClassInfo::subclassesFor(BaseElement::class); |
55
|
|
|
$output = []; |
56
|
|
|
|
57
|
|
|
foreach ($classes as $className) { |
58
|
|
|
if ($className === BaseElement::class) { |
59
|
|
|
continue; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$output[] = $className; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return $output; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function columns() |
69
|
|
|
{ |
70
|
|
|
$inUseReport = new ElementsInUseReport; |
71
|
|
|
|
72
|
|
|
return [ |
73
|
|
|
'Icon' => [ |
74
|
|
|
'title' => '', |
75
|
|
|
], |
76
|
|
|
'Type' => [ |
77
|
|
|
'title' => _t(__CLASS__ . '.Type', 'Content Type'), |
78
|
|
|
'formatting' => function ($value, $item) use ($inUseReport) { |
79
|
|
|
return sprintf( |
80
|
|
|
'<a class="grid-field__link" href="%s" title="%s">%s</a>', |
81
|
|
|
$inUseReport->getLink('?filters[ClassName]='. $item->ClassName), |
82
|
|
|
$item->Type, |
83
|
|
|
$item->TypeNice |
84
|
|
|
); |
85
|
|
|
}, |
86
|
|
|
], |
87
|
|
|
'Total' => [ |
88
|
|
|
'title' => _t(__CLASS__ . '.Total', 'Total'), |
89
|
|
|
], |
90
|
|
|
]; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Add elemental CSS and a unique class name to the GridField |
95
|
|
|
* |
96
|
|
|
* @return GridField |
97
|
|
|
*/ |
98
|
|
|
public function getReportField() |
99
|
|
|
{ |
100
|
|
|
Requirements::css('dnadesign/silverstripe-elemental:css/elemental-admin.css'); |
101
|
|
|
|
102
|
|
|
/** @var GridField $field */ |
103
|
|
|
$field = parent::getReportField(); |
104
|
|
|
$field->addExtraClass('elemental-report__grid-field'); |
105
|
|
|
|
106
|
|
|
return $field; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.