Skip to content

Commit a65f305

Browse files
committed
ImageData
1 parent 9dc087f commit a65f305

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

src/Calculators/DurationCalculator.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
class DurationCalculator
1010
{
11-
CONST CHARACTERS_PER_SECOND = 25;
12-
1311
public function __construct(
1412
protected Content $content
1513
) {

src/Data/Blocks/ImageData.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace Yuges\Contentable\Data\Blocks;
4+
5+
use Yuges\Contentable\Config\Config;
6+
use Yuges\Contentable\Enums\BlockType;
7+
use Yuges\Contentable\Interfaces\BlockType as BlockTypeInterface;
8+
9+
class ImageData extends \Yuges\Contentable\Abstracts\BlockData
10+
{
11+
protected const BlockTypeInterface TYPE = BlockType::Image;
12+
13+
public function __construct(
14+
public array $file = [
15+
'url' => '',
16+
],
17+
public ?string $caption = '',
18+
public bool $stretched = true,
19+
public bool $withBorder = false,
20+
public bool $withBackground = false,
21+
) {
22+
parent::__construct();
23+
}
24+
25+
public function getData(): array
26+
{
27+
return [
28+
'file' => $this->file,
29+
'caption' => $this->caption,
30+
'stretched' => $this->stretched,
31+
'withBorder' => $this->withBorder,
32+
'withBackground' => $this->withBackground,
33+
];
34+
}
35+
36+
public function duration(): float
37+
{
38+
$calculator = Config::getDurationCalculatorClass();
39+
40+
return ($this->file['url'] ?? 0 ? 5 : 0) + $calculator::duration($this->caption);
41+
}
42+
}

src/Enums/BlockType.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ enum BlockType: string implements \Yuges\Contentable\Interfaces\BlockType
66
{
77
case List = 'list';
88
case Quote = 'quote';
9+
case Image = 'image';
910
case Header = 'header';
1011
case Paragraph = 'paragraph';
1112
case Delimiter = 'delimiter';

0 commit comments

Comments
 (0)