Repo for the search and displace core module including the interface to select files and search and displace operations to run on them.
https://searchanddisplace.com
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.
78 lines
1.9 KiB
78 lines
1.9 KiB
<?php
|
|
|
|
namespace App\SearchDisplace\Documents;
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class DocumentFile
|
|
{
|
|
protected $storage;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->storage = Storage::disk('local');
|
|
}
|
|
|
|
public function getAfterIngest($id)
|
|
{
|
|
$path = $this->getPath($id);
|
|
|
|
// Ingest success.
|
|
if ($this->storage->exists("$path/document.json")) {
|
|
return [
|
|
'status' => 'success',
|
|
'content' => $this->getDocumentContent($path),
|
|
];
|
|
}
|
|
|
|
// Ingest fail.
|
|
if ($this->storage->exists("$path/document")) {
|
|
return [
|
|
'status' => 'fail',
|
|
];
|
|
}
|
|
|
|
return [
|
|
'status' => 'processing',
|
|
'message' => 'Document has not been processed yet.',
|
|
];
|
|
}
|
|
|
|
public function destroy($id)
|
|
{
|
|
$path = $this->getPath($id);
|
|
|
|
return $this->storage->deleteDirectory($path);
|
|
}
|
|
|
|
protected function getPath($id)
|
|
{
|
|
return "contracts/$id";
|
|
}
|
|
|
|
protected function getDocumentContent($path)
|
|
{
|
|
$content = json_decode($this->storage->get("$path/document.json"));
|
|
|
|
return $this->convertToHTML($content);
|
|
}
|
|
|
|
protected function convertToHTML($elements)
|
|
{
|
|
$html = '';
|
|
$url = url('/') . '/contracts-images';
|
|
foreach($elements as $key => $element) {
|
|
if($element->tag !== 'img') {
|
|
$html .= "<$element->tag style=\"$element->style\">$element->content</$element->tag>";
|
|
} else {
|
|
$src = $url . '/' . str_replace(' ', '%20', $element->src);
|
|
$html .= "<img $element->style src=\"$src\" alt=\"$element->details\">";
|
|
}
|
|
|
|
if($key !== array_key_last($elements))
|
|
$html .= '<br>';
|
|
}
|
|
|
|
return $html;
|
|
}
|
|
}
|