|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sunnysideup\SimpleTemplateCaching\Model; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Core\Injector\Injector; |
|
6
|
|
|
use SilverStripe\Forms\ReadonlyField; |
|
7
|
|
|
use SilverStripe\ORM\DataObject; |
|
8
|
|
|
use SilverStripe\ORM\DB; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* A blog category for generalising blog posts. |
|
12
|
|
|
* |
|
13
|
|
|
* @property string $ClassNameLastEdited |
|
14
|
|
|
*/ |
|
15
|
|
|
class ObjectsUpdated extends DataObject |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
public static function classes_edited(?string $myClass = ''): string |
|
19
|
|
|
{ |
|
20
|
|
|
$query = DB::query(' |
|
21
|
|
|
SELECT "ClassNameLastEdited", COUNT(*) AS "Count" |
|
22
|
|
|
FROM "ObjectsUpdated" |
|
23
|
|
|
GROUP BY "ClassNameLastEdited" |
|
24
|
|
|
ORDER BY "ClassNameLastEdited" ASC |
|
25
|
|
|
'); |
|
26
|
|
|
$array = []; |
|
27
|
|
|
foreach ($query as $row) { |
|
28
|
|
|
$array[$row['ClassNameLastEdited']] = |
|
29
|
|
|
Injector::inst()->get($row['ClassNameLastEdited'])->i18n_singular_name() . |
|
30
|
|
|
' (×' . $row['Count'] . ')'; |
|
31
|
|
|
if ($myClass && $myClass === $row['ClassNameLastEdited']) { |
|
32
|
|
|
return $row['Count']; |
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
return '<br />' . implode('<br> ', $array); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var string |
|
40
|
|
|
*/ |
|
41
|
|
|
private static $table_name = 'ObjectsUpdated'; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var array |
|
45
|
|
|
*/ |
|
46
|
|
|
private static $db = [ |
|
47
|
|
|
'ClassNameLastEdited' => 'Varchar(255)', |
|
48
|
|
|
]; |
|
49
|
|
|
|
|
50
|
|
|
private static $default_sort = [ |
|
51
|
|
|
'ID' => 'DESC', |
|
52
|
|
|
]; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @var array |
|
56
|
|
|
*/ |
|
57
|
|
|
private static $summary_fields = [ |
|
58
|
|
|
'LastEdited.Ago' => 'Updated', |
|
59
|
|
|
'Title' => 'Record name', |
|
60
|
|
|
]; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @var array |
|
64
|
|
|
*/ |
|
65
|
|
|
private static $field_labels = [ |
|
66
|
|
|
'Created' => 'Updated', |
|
67
|
|
|
'Title' => 'Human readable name', |
|
68
|
|
|
]; |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @var array |
|
72
|
|
|
*/ |
|
73
|
|
|
private static $casting = [ |
|
74
|
|
|
'Title' => 'Varchar', |
|
75
|
|
|
]; |
|
76
|
|
|
|
|
77
|
|
|
public function getTitle(): string |
|
78
|
|
|
{ |
|
79
|
|
|
if (class_exists((string) $this->ClassNameLastEdited)) { |
|
80
|
|
|
return Injector::inst()->get($this->ClassNameLastEdited)->i18n_singular_name(); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
return 'ERROR: class not found'; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function getCMSFields() |
|
87
|
|
|
{ |
|
88
|
|
|
$fields = parent::getCMSFields(); |
|
89
|
|
|
$fields->removeByName('ClassNameLastEdited'); |
|
90
|
|
|
$fields->addFieldsToTab( |
|
91
|
|
|
'Root.Main', |
|
92
|
|
|
[ |
|
93
|
|
|
ReadonlyField::create('Created', 'Recorded'), |
|
94
|
|
|
ReadonlyField::create('Title', 'Title', $this->getTitle()) |
|
95
|
|
|
->setDescription('Included ' . self::classes_edited($this->ClassNameLastEdited) . '× in the list.'), |
|
96
|
|
|
] |
|
97
|
|
|
); |
|
98
|
|
|
return $fields; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|