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
|
|
|
|
13
|
|
|
namespace LineMob\Core\Template\Carousel; |
14
|
|
|
|
15
|
|
|
use LINE\LINEBot\MessageBuilder\TemplateBuilder\CarouselColumnTemplateBuilder; |
16
|
|
|
use LINE\LINEBot\MessageBuilder\TemplateBuilder\CarouselTemplateBuilder; |
17
|
|
|
use LINE\LINEBot\MessageBuilder\TemplateMessageBuilder; |
18
|
|
|
use LineMob\Core\Template\AbstractTemplate; |
19
|
|
|
use LineMob\Core\Template\Action; |
20
|
|
|
use LineMob\Core\Template\ActionTemplateTrait; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @author Ishmael Doss <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class CarouselTemplate extends AbstractTemplate |
26
|
|
|
{ |
27
|
|
|
use ActionTemplateTrait; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var Item[] |
31
|
|
|
*/ |
32
|
|
|
public $items; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
public $altText = 'This is carousel template.'; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* {@inheritdoc} |
41
|
|
|
*/ |
42
|
|
|
public function getTemplate() |
43
|
|
|
{ |
44
|
|
|
$items = []; |
45
|
|
|
|
46
|
|
|
foreach ($this->items as $item) { |
47
|
|
|
$items[] = new CarouselColumnTemplateBuilder( |
48
|
|
|
mb_substr($item->title, 0, 40), mb_substr($item->text, 0, 60), |
49
|
|
|
$item->thumbnail, |
50
|
|
|
$this->createActions($item->actions) |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return new TemplateMessageBuilder($this->altText, new CarouselTemplateBuilder($items)); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param string $title |
59
|
|
|
* @param string $text |
60
|
|
|
* @param string $thumbnail |
61
|
|
|
* @param array|Action[] $actions |
62
|
|
|
*/ |
63
|
|
|
public function addItem($title, $text, $thumbnail, array $actions = []) |
64
|
|
|
{ |
65
|
|
|
$this->items[] = new Item($title, $text, $thumbnail, $actions); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|