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\ConfirmTemplateBuilder; |
15
|
|
|
use LINE\LINEBot\MessageBuilder\TemplateMessageBuilder; |
16
|
|
|
use LINE\LINEBot\TemplateActionBuilder\MessageTemplateActionBuilder; |
17
|
|
|
use LINE\LINEBot\TemplateActionBuilder\PostbackTemplateActionBuilder; |
18
|
|
|
use LINE\LINEBot\TemplateActionBuilder\UriTemplateActionBuilder; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author YokYukYik <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class ConfirmTemplate extends AbstractTemplate |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
public $altText = 'This is confirm template.'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
public $title = 'Are You sure?'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var Action[] |
37
|
|
|
*/ |
38
|
|
|
public $actions = []; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* {@inheritdoc} |
42
|
|
|
*/ |
43
|
|
View Code Duplication |
public function getTemplate() |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
$actions = []; |
46
|
|
|
ksort($this->actions); |
47
|
|
|
|
48
|
|
|
/** @var Action $action */ |
49
|
|
|
foreach ($this->actions as $action) { |
50
|
|
|
switch (strtolower($action->type)) { |
51
|
|
|
case Action::TYPE_POSTBACK: |
52
|
|
|
$actions[] = new PostbackTemplateActionBuilder($action->label, $action->value); |
53
|
|
|
break; |
54
|
|
|
case Action::TYPE_URI: |
55
|
|
|
$actions[] = new UriTemplateActionBuilder($action->label, $action->value); |
56
|
|
|
break; |
57
|
|
|
default: |
58
|
|
|
$actions[] = new MessageTemplateActionBuilder($action->label, $action->value);; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return new TemplateMessageBuilder( |
63
|
|
|
$this->altText, |
64
|
|
|
new ConfirmTemplateBuilder($this->title, $actions) |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param string $label |
70
|
|
|
* @param string $text |
71
|
|
|
* @param string $type |
72
|
|
|
*/ |
73
|
|
|
public function addYesAction($label = 'Yes', $text = 'yes', $type = Action::TYPE_MESSAGE) |
74
|
|
|
{ |
75
|
|
|
$this->actions[0] = new Action($label, $text, $type); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param string $label |
80
|
|
|
* @param string $text |
81
|
|
|
* @param string $type |
82
|
|
|
*/ |
83
|
|
|
public function addNoAction($label = 'No', $text = 'no', $type = Action::TYPE_MESSAGE) |
84
|
|
|
{ |
85
|
|
|
$this->actions[1] = new Action($label, $text, $type); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.