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.
This commit is contained in:
eweso 2018-03-30 19:24:45 +02:00 committed by GitHub
parent 400ee57bee
commit 71618f704d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 2 deletions

View File

@ -11,7 +11,7 @@
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
* *
* @see https://github.com/PHPOffice/PHPWord * @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors * @copyright 2010-2017 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/ */
@ -139,6 +139,16 @@ class ListItem extends AbstractStyle
return $this->numId; return $this->numId;
} }
/**
* Set numbering Id, to force list to restart counting. Same num id means same list
* @param int
*/
public function setNumId($numInt)
{
$this->numId = $numInt;
$this->getListTypeStyle();
}
/** /**
* Get legacy numbering definition * Get legacy numbering definition
* *
@ -148,7 +158,12 @@ class ListItem extends AbstractStyle
private function getListTypeStyle() private function getListTypeStyle()
{ {
// Check if legacy style already registered in global Style collection // Check if legacy style already registered in global Style collection
$numStyle = "PHPWordList{$this->listType}"; $numStyle = "PHPWordList_" . $this->listType;
if ($this->numId) {
$numStyle .= '_' . $this->numId;
}
if (Style::getStyle($numStyle) !== null) { if (Style::getStyle($numStyle) !== null) {
$this->setNumStyle($numStyle); $this->setNumStyle($numStyle);