| 23 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
//require_once 'class.paragraph.php';
|
|
|
4 |
//require_once 'class.odt.php';
|
|
|
5 |
|
|
|
6 |
include_once 'phpodt.php';
|
|
|
7 |
|
|
|
8 |
/**
|
|
|
9 |
* A Class representing a list.
|
|
|
10 |
*
|
|
|
11 |
* @author Issam RACHDI
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
class ODTList {
|
|
|
15 |
|
|
|
16 |
/**
|
|
|
17 |
* The DOMDocument instance containing the content of the document
|
|
|
18 |
* @var DOMDocument
|
|
|
19 |
*/
|
|
|
20 |
private $contentDocument;
|
|
|
21 |
|
|
|
22 |
/**
|
|
|
23 |
* The DOMElement representing the list
|
|
|
24 |
* @var DOMElement
|
|
|
25 |
*/
|
|
|
26 |
private $listElement;
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
*
|
|
|
30 |
* @param DOMDocument $contentDocument
|
|
|
31 |
* @param boolean $addToDocument true if you're adding the list to the document, false if you want to add it as an item to another list
|
|
|
32 |
* @param array $items The items of the list. You can also add items via the addItem method
|
|
|
33 |
*/
|
|
|
34 |
function __construct($items = null, $addToDocument = true) {
|
|
|
35 |
$this->contentDocument = ODT::getInstance()->getDocumentContent();
|
|
|
36 |
$this->listElement = $this->contentDocument->createElement('text:list');
|
|
|
37 |
if ($addToDocument) {
|
|
|
38 |
$this->contentDocument->getElementsByTagName('office:text')->item(0)->appendChild($this->listElement);
|
|
|
39 |
}
|
|
|
40 |
if ($items != null && is_array($items)) {
|
|
|
41 |
foreach ($items as $item) {
|
|
|
42 |
$this->addItem($item);
|
|
|
43 |
}
|
|
|
44 |
}
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
/**
|
|
|
48 |
* Specifies the styles to apply to this list
|
|
|
49 |
*
|
|
|
50 |
* @param ListStyle $listStyle
|
|
|
51 |
*/
|
|
|
52 |
function setStyle($listStyle) {
|
|
|
53 |
$this->listElement->setAttribute('text:style-name', $listStyle->getStyleName());
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
/**
|
|
|
57 |
* Adds an item to the list
|
|
|
58 |
*
|
|
|
59 |
* @param string $item
|
|
|
60 |
*/
|
|
|
61 |
function addItem($item) {
|
|
|
62 |
$element = $this->contentDocument->createElement('text:list-item');
|
|
|
63 |
$p = new Paragraph(null, false);
|
|
|
64 |
$p->addText($item);
|
|
|
65 |
$element->appendChild($p->getDOMElement());
|
|
|
66 |
$this->listElement->appendChild($element);
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
/**
|
|
|
70 |
* Adds a sublist to this list
|
|
|
71 |
*
|
|
|
72 |
* @param ODTList $sublist
|
|
|
73 |
*/
|
|
|
74 |
function addSubList($sublist) {
|
|
|
75 |
$element = $this->contentDocument->createElement('text:list-item');
|
|
|
76 |
$element->appendChild($sublist->getDOMElement());
|
|
|
77 |
$this->listElement->appendChild($element);
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
/**
|
|
|
81 |
* Returns the DOMElement representing this list
|
|
|
82 |
*
|
|
|
83 |
* @return DOMElement
|
|
|
84 |
*/
|
|
|
85 |
public function getDOMElement() {
|
|
|
86 |
return $this->listElement;
|
|
|
87 |
}
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
?>
|