1<?php
2
3namespace dokuwiki\plugin\wordimport\docx;
4
5/**
6 * A list item
7 *
8 * This is a paragraph that is part of a list
9 */
10class ListItem extends Paragraph
11{
12    /** @var int the nesting level starting at 0 */
13    protected $level = 0;
14    /** @var string the type of list, ordered or unordered */
15    protected $type = 'unordered';
16
17    /**
18     * The type of list is determined looking at the numbering.xml data
19     * @inheritdoc
20     */
21    public function parse()
22    {
23        parent::parse();
24        $this->level = (int)$this->p->xpath('w:pPr/w:numPr/w:ilvl')[0]->attributes('w', true)->val;
25        $id = (int)$this->p->xpath('w:pPr/w:numPr/w:numId')[0]->attributes('w', true)->val;
26        $this->type = $this->docx->getNumbering()->getType($id, $this->level);
27    }
28
29    /** @inheritdoc */
30    public function __toString(): string
31    {
32        $text = parent::__toString();
33        $bullet = $this->type === 'ordered' ? '-' : '*';
34        return str_pad('', ($this->level + 1) * 2) . $bullet . ' ' . $text;
35    }
36
37    /** @inheritdoc */
38    public function mergeToPrevious(): bool
39    {
40        return true;
41    }
42}
43