|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use SilverStripe\Reports\Report; |
|
4
|
|
|
use DNADesign\Elemental\Models\BaseElement; |
|
5
|
|
|
use SilverStripe\Core\ClassInfo; |
|
6
|
|
|
use SilverStripe\Core\Injector\Injector; |
|
7
|
|
|
use SilverStripe\ORM\ArrayList; |
|
8
|
|
|
use SilverStripe\View\ArrayData; |
|
9
|
|
|
use SilverStripe\Core\Convert; |
|
10
|
|
|
|
|
11
|
|
|
class ElementUseReport extends Report |
|
|
|
|
|
|
12
|
|
|
{ |
|
13
|
|
|
protected $title = 'Content Blocks in Use'; |
|
14
|
|
|
|
|
15
|
|
|
protected $description = 'Show what Content Blocks are being used.'; |
|
16
|
|
|
|
|
17
|
|
|
public function getCount($params = array()) |
|
18
|
|
|
{ |
|
19
|
|
|
return BaseElement::get()->count(); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function sourceRecords($params = []) |
|
23
|
|
|
{ |
|
24
|
|
|
if (empty($params)) { |
|
25
|
|
|
$classes = ClassInfo::subclassesFor(BaseElement::class); |
|
26
|
|
|
$output = new ArrayList(); |
|
27
|
|
|
|
|
28
|
|
|
foreach ($classes as $class) { |
|
29
|
|
|
if ($class === BaseElement::class) { |
|
30
|
|
|
continue; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
$inst = Injector::inst()->create($class); |
|
34
|
|
|
|
|
35
|
|
|
$output->push(new ArrayData([ |
|
36
|
|
|
'Icon' => $inst->getIcon(), |
|
37
|
|
|
'Title' => $inst->getTypeNice(), |
|
38
|
|
|
'ClassName' => $inst->sanitiseClassName($class), |
|
39
|
|
|
'Total' => $class::get()->count() |
|
40
|
|
|
])); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
return $output; |
|
44
|
|
|
} elseif (isset($params['ClassName'])) { |
|
45
|
|
|
$convertClass = Injector::inst()->create(BaseElement::class)->unsanitiseClassName($params['ClassName']); |
|
46
|
|
|
|
|
47
|
|
|
if (ClassInfo::exists($convertClass)) { |
|
48
|
|
|
return $convertClass::get()->sort('Title', 'ASC'); |
|
49
|
|
|
} else { |
|
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function columns() |
|
55
|
|
|
{ |
|
56
|
|
|
$params = $this->params; |
|
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
if (empty($params)) { |
|
59
|
|
|
return [ |
|
60
|
|
|
'Icon' => [ |
|
61
|
|
|
'title' => '' |
|
62
|
|
|
], |
|
63
|
|
|
'Title' => [ |
|
64
|
|
|
'title' => _t(__CLASS__.'.Title', 'Content Type') |
|
65
|
|
|
], |
|
66
|
|
|
'Total' => [ |
|
67
|
|
|
'title' => _t(__CLASS__.'.Total', 'Total'), |
|
68
|
|
|
'link' => function ($value, $item) { |
|
69
|
|
|
return sprintf( |
|
70
|
|
|
'<a class="grid-field__link" href="%s" title="%s">%s</a>', |
|
71
|
|
|
Convert::raw2att($this->getLink('?filters[ClassName]='. $item->ClassName)), |
|
72
|
|
|
Convert::raw2att($value), |
|
|
|
|
|
|
73
|
|
|
Convert::raw2xml($value) |
|
74
|
|
|
); |
|
75
|
|
|
} |
|
76
|
|
|
] |
|
77
|
|
|
]; |
|
78
|
|
|
} else { |
|
79
|
|
|
return [ |
|
80
|
|
|
'EditorPreview' => [ |
|
81
|
|
|
'title' => '' |
|
82
|
|
|
], |
|
83
|
|
|
'PageTitle' => [ |
|
84
|
|
|
'title' => _t(__CLASS__.'.Page', 'Page'), |
|
85
|
|
|
'link' => true |
|
86
|
|
|
] |
|
87
|
|
|
]; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.