2019-04-27 15:18:00 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Http\Controllers\Images;
|
|
|
|
|
|
|
|
use BookStack\Exceptions\ImageUploadException;
|
2021-06-26 17:23:15 +02:00
|
|
|
use BookStack\Http\Controllers\Controller;
|
2019-04-27 15:18:00 +02:00
|
|
|
use BookStack\Uploads\ImageRepo;
|
|
|
|
use Illuminate\Http\Request;
|
2020-07-25 01:20:58 +02:00
|
|
|
use Illuminate\Validation\ValidationException;
|
2019-04-27 15:18:00 +02:00
|
|
|
|
|
|
|
class GalleryImageController extends Controller
|
|
|
|
{
|
|
|
|
protected $imageRepo;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GalleryImageController constructor.
|
|
|
|
*/
|
|
|
|
public function __construct(ImageRepo $imageRepo)
|
|
|
|
{
|
|
|
|
$this->imageRepo = $imageRepo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of gallery images, in a list.
|
|
|
|
* Can be paged and filtered by entity.
|
|
|
|
*/
|
|
|
|
public function list(Request $request)
|
|
|
|
{
|
|
|
|
$page = $request->get('page', 1);
|
|
|
|
$searchTerm = $request->get('search', null);
|
|
|
|
$uploadedToFilter = $request->get('uploaded_to', null);
|
|
|
|
$parentTypeFilter = $request->get('filter_type', null);
|
|
|
|
|
|
|
|
$imgData = $this->imageRepo->getEntityFiltered('gallery', $parentTypeFilter, $page, 24, $uploadedToFilter, $searchTerm);
|
2021-06-26 17:23:15 +02:00
|
|
|
|
2021-08-22 14:15:58 +02:00
|
|
|
return view('pages.parts.image-manager-list', [
|
2021-06-26 17:23:15 +02:00
|
|
|
'images' => $imgData['images'],
|
2020-07-25 01:20:58 +02:00
|
|
|
'hasMore' => $imgData['has_more'],
|
|
|
|
]);
|
2019-04-27 15:18:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a new gallery image in the system.
|
2021-06-26 17:23:15 +02:00
|
|
|
*
|
2020-07-25 01:20:58 +02:00
|
|
|
* @throws ValidationException
|
2019-04-27 15:18:00 +02:00
|
|
|
*/
|
|
|
|
public function create(Request $request)
|
|
|
|
{
|
|
|
|
$this->checkPermission('image-create-all');
|
|
|
|
$this->validate($request, [
|
2021-06-26 17:23:15 +02:00
|
|
|
'file' => $this->getImageValidationRules(),
|
2019-04-27 15:18:00 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
try {
|
|
|
|
$imageUpload = $request->file('file');
|
|
|
|
$uploadedTo = $request->get('uploaded_to', 0);
|
|
|
|
$image = $this->imageRepo->saveNew($imageUpload, 'gallery', $uploadedTo);
|
|
|
|
} catch (ImageUploadException $e) {
|
|
|
|
return response($e->getMessage(), 500);
|
|
|
|
}
|
|
|
|
|
|
|
|
return response()->json($image);
|
|
|
|
}
|
|
|
|
}
|