63 lines
2 KiB
PHP
63 lines
2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Bo\XmlIncos\SearchXmlInco;
|
|
use App\Http\Resources\XmlIncoCollection;
|
|
use App\Models\XmlInco;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Kwaadpepper\ImageResizer\ImageResizer;
|
|
use Symfony\Component\HttpFoundation\StreamedResponse;
|
|
|
|
class XmlIncoController extends Controller
|
|
{
|
|
/**
|
|
* Download a file from inco storage.
|
|
*
|
|
* @param string $inco_picture
|
|
* @return \Symfony\Component\HttpFoundation\StreamedResponse
|
|
*/
|
|
public function getXmlIncoPicture(string $inco_picture): StreamedResponse
|
|
{
|
|
if (!($picturePath = XmlInco::getXmlIncoPicturePath($inco_picture))) {
|
|
abort(404);
|
|
}
|
|
/** @var \Illuminate\Filesystem\FilesystemAdapter */
|
|
$disk = XmlInco::getDisk();
|
|
|
|
// * Resized inco picture if wanted.
|
|
if (request()->get('resize')) {
|
|
$resizedPath = ImageResizer::resizeImageOrIgnore(
|
|
$disk->path($picturePath),
|
|
'boIncoPicture'
|
|
);
|
|
$picturePath = $resizedPath ? $resizedPath : $picturePath;
|
|
/** @var \Illuminate\Filesystem\FilesystemAdapter */
|
|
$disk = Storage::disk('public');
|
|
}
|
|
|
|
return \response()->streamDownload(function () use ($disk, $picturePath) {
|
|
$stream = $disk->readStream($picturePath);
|
|
\fpassthru($stream);
|
|
\fclose($stream);
|
|
}, $inco_picture, [
|
|
'Content-Type' => $disk->mimeType($picturePath),
|
|
'Content-Length' => $disk->size($picturePath),
|
|
'Content-Disposition' => 'inline',
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Search for xml inco
|
|
*
|
|
* @param \App\Http\Requests\Bo\XmlIncos\SearchXmlInco $request
|
|
* @return \App\Http\Resources\XmlIncoCollection
|
|
*/
|
|
public function getXmlIncos(SearchXmlInco $request)
|
|
{
|
|
return new XmlIncoCollection(XmlInco::where('id', 'LIKE', "%$request->term%")
|
|
->orWhere('descriptif', 'LIKE', "%$request->term%")
|
|
->get());
|
|
}
|
|
}
|