Passed
Push — master ( 21fbe2...d2fb54 )
by Nicolaas
05:21
created

CMSNicetiesRecordSummaryExtension   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 29
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getRecordSummary() 0 17 1
A updateSummaryFields() 0 3 1
1
<?php
2
3
namespace Sunnysideup\CMSNiceties\Extensions;
4
5
use SilverStripe\Core\Extension;
6
use SilverStripe\ORM\FieldType\DBField;
7
8
9
class CMSNicetiesRecordSummaryExtension extends Extension
10
{
11
12
    private static $casting = [
13
        'RecordSummary' => 'HTMLFragment',
14
    ];
15
16
    public function updateSummaryFields(&$array)
17
    {
18
        array_unshift($array, ['RecordSummary' => 'ID']);
19
    }
20
21
    protected function getRecordSummary()
22
    {
23
        /** @var DBField $owner */
24
        $owner = $this->getOwner();
25
        $html = '<div class="record-summary">';
26
        $html .= '<span class="record-summary-id">' . $owner->ID . '</span>';
27
        //created
28
        $created = $owner->obj('Created');
29
        $html .= '<span class="record-summary-more">Created: ' . $created->Nice() . '(' . $created->Ago() . ')</span>';
30
        //last edited
31
        $lastEdited = $owner->obj('LastEdited');
32
        $html .= '<span class="record-summary-more">Last Edited: ' . $lastEdited->Nice() . '(' . $lastEdited->Ago() . ')</span>';
33
        // close
34
        $html .= '</div>';
35
        // prepare for output
36
        $html = DBField::create_field('HTMLText', $html);
37
        return $html;
38
    }
39
}
40