Passed
Pull Request — master (#16)
by
unknown
02:10
created

ButtonsTemplate::getTemplate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the LineMob package.
5
 *
6
 * (c) Ishmael Doss <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace LineMob\Core\Template;
13
14
use LINE\LINEBot\MessageBuilder\TemplateBuilder\ButtonTemplateBuilder;
15
use LINE\LINEBot\MessageBuilder\TemplateMessageBuilder;
16
17
/**
18
 * @author YokYukYik <[email protected]>
19
 */
20
class ButtonsTemplate extends AbstractTemplate
21
{
22
    use ActionTemplateTrait;
23
24
    /**
25
     * @var string
26
     */
27
    public $altText = 'This is buttons template.';
28
29
    /**
30
     * @var string
31
     */
32
    public $title = 'Menu';
33
34
    /**
35
     * @var string
36
     */
37
    public $text = 'Please select';
38
39
    /**
40
     * @var string
41
     */
42
    public $thumbnail;
43
44
    /**
45
     * @var Action[]
46
     */
47
    public $actions = [];
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function getTemplate()
53
    {
54
        return new TemplateMessageBuilder($this->altText, new ButtonTemplateBuilder(
55
            $this->title,
56
            $this->text,
57
            $this->thumbnail,
58
            $this->createActions()
59
        ));
60
    }
61
62
    /**
63
     * @param $label
64
     * @param $text
65
     */
66
    public function addMessageAction($label, $text)
67
    {
68
        $this->actions[] = new Action($label, $text, Action::TYPE_MESSAGE);
69
    }
70
71
    /**
72
     * @param $label
73
     * @param $link
74
     */
75
    public function addUriAction($label, $link)
76
    {
77
        $this->actions[] = new Action($label, $link, Action::TYPE_URI);
78
    }
79
80
    /**
81
     * @param $label
82
     * @param $data
83
     */
84
    public function addPostbackAction($label, $data)
85
    {
86
        $this->actions[] = new Action($label, $data, Action::TYPE_POSTBACK);
87
    }
88
}
89