1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace DH\Adf\Node\Child; |
6
|
|
|
|
7
|
|
|
use DH\Adf\Builder\TextBuilder; |
8
|
|
|
use DH\Adf\Node\BlockNode; |
9
|
|
|
use DH\Adf\Node\Inline\Text; |
10
|
|
|
use DH\Adf\Node\Node; |
11
|
|
|
use JsonSerializable; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @see https://developer.atlassian.com/cloud/jira/platform/apis/document/nodes/listItem |
15
|
|
|
*/ |
16
|
|
|
class TaskItem extends BlockNode implements JsonSerializable |
17
|
|
|
{ |
18
|
|
|
use TextBuilder; |
19
|
|
|
|
20
|
|
|
protected string $type = 'taskItem'; |
21
|
|
|
protected array $allowedContentTypes = [ |
22
|
|
|
Text::class, |
23
|
|
|
]; |
24
|
|
|
|
25
|
|
|
/** @var bool State of Task Item */ |
26
|
|
|
private bool $todo; |
27
|
|
|
private ?string $localId; |
28
|
|
|
|
29
|
|
|
public function __construct(bool $todo, ?BlockNode $parent = null) |
30
|
|
|
{ |
31
|
|
|
parent::__construct($parent); |
32
|
|
|
$this->todo = $todo; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public static function load(array $data, ?BlockNode $parent = null): BlockNode |
36
|
|
|
{ |
37
|
|
|
self::checkNodeData(static::class, $data, ['attrs']); |
38
|
|
|
self::checkRequiredKeys(['state'], $data['attrs']); // task item needs state key |
39
|
|
|
|
40
|
|
|
$todo = $data['attrs']['state'] == 'TODO'; |
41
|
|
|
$node = new self($todo, $parent); |
42
|
|
|
|
43
|
|
|
$node->localId = $data['attrs']['localId'] ?? null; |
44
|
|
|
// set content if defined |
45
|
|
|
if (\array_key_exists('content', $data)) { |
46
|
|
|
foreach ($data['content'] as $nodeData) { |
47
|
|
|
$class = Node::NODE_MAPPING[$nodeData['type']]; |
48
|
|
|
$child = $class::load($nodeData, $node); |
49
|
|
|
|
50
|
|
|
$node->append($child); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return $node; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function isOpen(): bool |
58
|
|
|
{ |
59
|
|
|
return $this->todo; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function getLocalId(): ?string |
63
|
|
|
{ |
64
|
|
|
return $this->localId; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|