Completed
Push — master ( e01dda...35da90 )
by Michael
01:11
created

InstagramPost::getCMSFields()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 9.568
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace X3dgoo\InstagramScraper\Model;
4
5
use SilverStripe\ORM\DataObject;
6
use SilverStripe\Forms\LiteralField;
7
8
/**
9
 * @property bool $Show
10
 * @property string $InstagramID
11
 * @property string $ShortCode
12
 * @property string $Handle
13
 * @property string $Caption
14
 * @property string $Link
15
 * @property string $Type
16
 * @property string $ImageLowResolutionUrl
17
 * @property string $ImageStandardResolutionUrl
18
 * @property string $ImageHighResolutionUrl
19
 * @property string $ImageThumbnailURL
20
 * @property mixed $Posted
21
 * @property int $LikesCount
22
 * @property int $CommentsCount
23
 */
24
class InstagramPost extends DataObject
25
{
26
    private static $db = [
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
27
        'Show' => 'Boolean',
28
        'InstagramID' => 'Varchar(100)',
29
        'ShortCode' => 'Varchar(100)',
30
        'Handle' => 'Varchar(100)',
31
        'Caption' => 'Text',
32
        'Link' => 'Text',
33
        'Type' => 'Varchar(100)',
34
        'ImageLowResolutionUrl' => 'Text',
35
        'ImageStandardResolutionUrl' => 'Text',
36
        'ImageHighResolutionUrl' => 'Text',
37
        'ImageThumbnailURL' => 'Text',
38
        'Posted' => 'Datetime',
39
        'LikesCount' => 'Int',
40
        'CommentsCount' => 'Int',
41
    ];
42
43
    private static $defaults = [
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
44
        'Show' => true,
45
    ];
46
47
    private static $singular_name = 'Instagram Post';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
48
    private static $plural_name = 'Instagram Posts';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
49
    private static $default_sort = 'Posted DESC';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
50
    private static $table_name = 'InstagramPost';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
51
52
    private static $summary_fields = [
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
53
        'ImageThumbnailURL',
54
        'Handle',
55
        'Caption.Summary',
56
        'Posted',
57
        'Show.Nice',
58
    ];
59
60
    private static $field_labels = [
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
61
        'ImageThumbnailURL' => 'Image',
62
        'Caption.Summary' => 'Caption',
63
        'Show.Nice' => 'Show',
64
    ];
65
66
    public function getCMSFields()
67
    {
68
        $fields = parent::getCMSFields();
69
70
        if ($this->ImageThumbnailURL) {
71
            $fields->addFieldToTab(
72
                'Root.Main',
73
                LiteralField::create(
74
                    'ImagePreview',
75
                    '<div class="form-group field text">' .
76
                        '<label class="form__field-label">Image</label>' .
77
                        '<div class="form__field-holder">' .
78
                        '<img src="' . $this->ImageThumbnailURL . '" style="max-width: 200px;" />' .
79
                        '</div>' .
80
                        '</div>'
81
                ),
82
                'Show'
83
            );
84
        }
85
86
        return $fields;
87
    }
88
}
89