CMSNicetiesRecordSummaryExtension   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 16
c 4
b 0
f 0
dl 0
loc 31
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getRecordSummary() 0 19 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
/**
10
 * Class \Sunnysideup\CMSNiceties\Extensions\CMSNicetiesRecordSummaryExtension
11
 *
12
 * @property CMSNicetiesRecordSummaryExtension $owner
13
 */
14
class CMSNicetiesRecordSummaryExtension extends Extension
15
{
16
17
    private static $casting = [
18
        'RecordSummary' => 'HTMLFragment',
19
    ];
20
21
    public function updateSummaryFields(&$array)
22
    {
23
        $array = ['RecordSummary' => 'ID'] + $array;
24
    }
25
26
    public function getRecordSummary()
27
    {
28
        /** @var DBField $owner */
29
        $owner = $this->getOwner();
30
        $html = '<div class="record-summary">';
31
        $html .= '<div class="record-summary-id">' . $owner->ID . '</div>';
32
        $html .= '<div class="record-summary-dropdown">';
33
        //created
34
        $created = $owner->obj('Created');
35
        $html .= '<div class="record-summary-more">Created: ' . $created->Ago() . '</div>';
36
        //last edited
37
        $lastEdited = $owner->obj('LastEdited');
38
        $html .= '<div class="record-summary-more">Last Edited: ' . $lastEdited->Ago() . '</div>';
39
        // close
40
        $html .= '</div>';
41
        $html .= '</div>';
42
        // prepare for output
43
        $html = DBField::create_field('HTMLText', $html);
44
        return $html;
45
    }
46
}
47