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
|
|
|
foreach ($query as $row) { |
27
|
|
|
$array[$row['ClassNameLastEdited']] = |
28
|
|
|
Injector::inst()->get($row['ClassNameLastEdited'])->i18n_singular_name() . |
29
|
|
|
' (×' . $row['Count'] . ')'; |
30
|
|
|
if ($myClass && $myClass === $row['ClassNameLastEdited']) { |
31
|
|
|
return $row['Count']; |
32
|
|
|
} |
33
|
|
|
} |
34
|
|
|
return '<br />' . implode('<br> ', $array); |
|
|
|
|
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
private static $table_name = 'ObjectsUpdated'; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var array |
44
|
|
|
*/ |
45
|
|
|
private static $db = [ |
46
|
|
|
'ClassNameLastEdited' => 'Varchar(255)', |
47
|
|
|
]; |
48
|
|
|
|
49
|
|
|
private static $default_sort = [ |
50
|
|
|
'ID' => 'DESC', |
51
|
|
|
]; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var array |
55
|
|
|
*/ |
56
|
|
|
private static $summary_fields = [ |
57
|
|
|
'LastEdited.Ago' => 'Updated', |
58
|
|
|
'Title' => 'Record name', |
59
|
|
|
]; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @var array |
63
|
|
|
*/ |
64
|
|
|
private static $field_labels = [ |
65
|
|
|
'Created' => 'Updated', |
66
|
|
|
'Title' => 'Human readable name', |
67
|
|
|
]; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @var array |
71
|
|
|
*/ |
72
|
|
|
private static $casting = [ |
73
|
|
|
'Title' => 'Varchar', |
74
|
|
|
]; |
75
|
|
|
|
76
|
|
|
public function getTitle(): string |
77
|
|
|
{ |
78
|
|
|
if (class_exists((string) $this->ClassNameLastEdited)) { |
79
|
|
|
return Injector::inst()->get($this->ClassNameLastEdited)->i18n_singular_name(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
return 'ERROR: class not found'; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function getCMSFields() |
86
|
|
|
{ |
87
|
|
|
$fields = parent::getCMSFields(); |
88
|
|
|
$fields->removeByName('ClassNameLastEdited'); |
89
|
|
|
$fields->addFieldsToTab( |
90
|
|
|
'Root.Main', |
91
|
|
|
[ |
92
|
|
|
ReadonlyField::create('Created', 'Recorded'), |
93
|
|
|
ReadonlyField::create('Title', 'Title', $this->getTitle()) |
94
|
|
|
->setDescription('Included ' . self::classes_edited($this->ClassNameLastEdited) . '× in the list.'), |
95
|
|
|
] |
96
|
|
|
); |
97
|
|
|
return $fields; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|