phpdocx
This commit is contained in:
parent
8ba1c4ef56
commit
fb472f29c5
@ -9,6 +9,7 @@
|
||||
use App\Models\Study;
|
||||
use App\Models\StudyReport;
|
||||
use App\Services\DocumentGenerator\Word;
|
||||
use App\Services\ReportStorage;
|
||||
|
||||
class ReportController extends HashidControllerBase
|
||||
{
|
||||
@ -75,6 +76,8 @@ public function download(string $uuid)
|
||||
// $study = Study::with(['reports.radiologist', 'readingPhysician'])->where('accession_number', $uuid)->firstOrFail();
|
||||
$report = StudyReport::where('accession_number', $uuid)->firstOrFail();
|
||||
|
||||
return Word::make($report->study, $report);
|
||||
$path = Word::make($report->study, $report);
|
||||
|
||||
return response()->download(ReportStorage::abspath($path));
|
||||
}
|
||||
}
|
||||
|
@ -4,36 +4,24 @@
|
||||
|
||||
use App\Models\Study;
|
||||
use App\Models\StudyReport;
|
||||
use PhpOffice\PhpWord\IOFactory;
|
||||
use PhpOffice\PhpWord\PhpWord;
|
||||
use PhpOffice\PhpWord\Shared\Html;
|
||||
use App\Services\ReportStorage;
|
||||
use CreateDocx;
|
||||
|
||||
class Word
|
||||
final readonly class Word
|
||||
{
|
||||
public static function make(Study $study, StudyReport $report)
|
||||
public static function make(Study $study, StudyReport $report): string
|
||||
{
|
||||
$filename = $report->accession_number . '.docx';
|
||||
$filepath = ReportStorage::customFilepath($study, $filename);
|
||||
if (ReportStorage::exists($study, $filename)) {
|
||||
return $filepath;
|
||||
}
|
||||
|
||||
$html = $report->getContent();
|
||||
|
||||
$phpWord = new PhpWord;
|
||||
$section = $phpWord->addSection();
|
||||
|
||||
// Add HTML content to the section
|
||||
Html::addHtml($section, $html, false, false);
|
||||
|
||||
// Save the document as a DOCX file
|
||||
// $filename = 'report.docx';
|
||||
$writer = IOFactory::createWriter($phpWord, 'Word2007');
|
||||
ob_start();
|
||||
$writer->save('php://output');
|
||||
$content = ob_get_clean();
|
||||
|
||||
return $content;
|
||||
|
||||
$content = view('staff.reports.word', compact('study', 'report'))->render();
|
||||
$filepath = ReportStorage::reportFilepath($study, '.docx');
|
||||
Storage::put($filepath, $content);
|
||||
$docx = new CreateDocx;
|
||||
$docx->embedHTML($html);
|
||||
$docx->createDocx(ReportStorage::abspath($filepath));
|
||||
|
||||
return $filepath;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,8 @@
|
||||
"Tests\\": "tests/"
|
||||
},
|
||||
"files": [
|
||||
"app/helpers.php"
|
||||
"app/helpers.php",
|
||||
"src/phpdocx/src/CreateDocx.php"
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
@ -90,6 +91,7 @@
|
||||
"composer clear-all",
|
||||
"composer cache-all"
|
||||
],
|
||||
"clr": "composer clear-all",
|
||||
"fix": "php-cs-fixer fix",
|
||||
"dev": [
|
||||
"Composer\\Config::disableProcessTimeout",
|
||||
|
Loading…
Reference in New Issue
Block a user