You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.7 KiB
77 lines
2.7 KiB
<?php
|
|
|
|
namespace App\Parser\DocxParser;
|
|
|
|
use App\Parser\DocxParser\Traits\Helper;
|
|
use Exception;
|
|
use PhpOffice\PhpWord\Reader\Word2007\Numbering;
|
|
use PhpOffice\PhpWord\Style;
|
|
|
|
class ListItemRun
|
|
{
|
|
|
|
use Helper;
|
|
|
|
public function handle($list)
|
|
{
|
|
$result = [];
|
|
$listElements = $this->getElements($list);
|
|
|
|
if (count($listElements)) {
|
|
foreach ($listElements as $index => $element) {
|
|
|
|
//dd($element->getFontStyle());
|
|
|
|
try {
|
|
$handler = $this->getHandler($element);
|
|
$data = $handler->handle($element);
|
|
|
|
if ($data && isset($data[ 'content' ]) && strlen(trim(strip_tags($data[ 'content' ])))) {
|
|
$styleName = $list->getParagraphStyle()->getStyleName();
|
|
|
|
if ($index === 0) {
|
|
$result[] = [
|
|
'content' => $data,
|
|
'type' => 'listItemRun',
|
|
'depth' => (int) $list->getDepth(),
|
|
'styleDepth' => $this->getStyleListDepth($styleName),
|
|
'styleName' => $styleName,
|
|
'index' => $list->getElementIndex(),
|
|
'children' => []
|
|
|
|
];
|
|
} else {
|
|
if (isset($result[ count($result) - 1 ])) {
|
|
$result[ count($result) - 1 ][ 'content' ][ 'content' ] .= ' '.$data[ 'content' ];
|
|
} else {
|
|
$result[] = [
|
|
'content' => $data,
|
|
'type' => 'listItemRun',
|
|
'depth' => (int) $list->getDepth(),
|
|
'styleDepth' => $this->getStyleListDepth($styleName),
|
|
'styleName' => $styleName,
|
|
'index' => $list->getElementIndex(),
|
|
'children' => []
|
|
];
|
|
}
|
|
}
|
|
}
|
|
} catch (Exception $e) {
|
|
throw new Exception($e->getMessage());
|
|
}
|
|
|
|
|
|
}
|
|
if ($result) {
|
|
if (count($result) === 1) {
|
|
$result = reset($result);
|
|
$result[ 'content' ][ 'content' ] = '<p>'.$result[ 'content' ][ 'content' ].'</p>';
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
}
|