Skip to content

Commit 71618f7

Browse files
author
eweso
authored
Adding setNumId method for ListItem style
By allowing to set the numId in the ListItem style manually, you can separate lists. Every ListItem with the same numId belongs to one list. This allows you to restart list counting.
1 parent 400ee57 commit 71618f7

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/PhpWord/Style/ListItem.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
1212
*
1313
* @see https://github.com/PHPOffice/PHPWord
14-
* @copyright 2010-2018 PHPWord contributors
14+
* @copyright 2010-2017 PHPWord contributors
1515
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
1616
*/
1717

@@ -139,6 +139,16 @@ public function getNumId()
139139
return $this->numId;
140140
}
141141

142+
/**
143+
* Set numbering Id, to force list to restart counting. Same num id means same list
144+
* @param int
145+
*/
146+
public function setNumId($numInt)
147+
{
148+
$this->numId = $numInt;
149+
$this->getListTypeStyle();
150+
}
151+
142152
/**
143153
* Get legacy numbering definition
144154
*
@@ -148,7 +158,12 @@ public function getNumId()
148158
private function getListTypeStyle()
149159
{
150160
// Check if legacy style already registered in global Style collection
151-
$numStyle = "PHPWordList{$this->listType}";
161+
$numStyle = "PHPWordList_" . $this->listType;
162+
163+
if ($this->numId) {
164+
$numStyle .= '_' . $this->numId;
165+
}
166+
152167
if (Style::getStyle($numStyle) !== null) {
153168
$this->setNumStyle($numStyle);
154169

0 commit comments

Comments
 (0)