updateSummaryFields()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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