1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-19 17:42:44 +01:00
invoiceninja/app/Http/Controllers/DocumentController.php

156 lines
3.9 KiB
PHP
Raw Normal View History

2020-06-23 13:05:41 +02:00
<?php
namespace App\Http\Controllers;
2020-06-24 14:22:44 +02:00
use App\Http\Requests\Document\DestroyDocumentRequest;
2020-06-24 10:59:56 +02:00
use App\Http\Requests\Document\ShowDocumentRequest;
use App\Http\Requests\Document\StoreDocumentRequest;
use App\Http\Requests\Document\UpdateDocumentRequest;
use App\Models\Document;
2020-06-24 12:17:42 +02:00
use App\Repositories\DocumentRepository;
use App\Transformers\DocumentTransformer;
use App\Utils\Traits\MakesHash;
2020-06-23 13:05:41 +02:00
use Illuminate\Http\Request;
2020-10-28 11:10:49 +01:00
use Illuminate\Http\Response;
2020-06-23 13:05:41 +02:00
2020-06-24 10:59:56 +02:00
class DocumentController extends BaseController
2020-06-23 13:05:41 +02:00
{
2020-06-24 12:17:42 +02:00
use MakesHash;
protected $entity_type = Document::class;
protected $entity_transformer = DocumentTransformer::class;
/**
* @var DocumentRepository
*/
protected $document_repo;
/**
* DocumentController constructor.
* @param DocumentRepository $document_repo
*/
public function __construct(DocumentRepository $document_repo)
{
parent::__construct();
2020-08-11 05:21:43 +02:00
$this->middleware('password_protected', ['only' => ['destroy']]);
2020-06-24 12:17:42 +02:00
$this->document_repo = $document_repo;
}
2020-06-23 13:05:41 +02:00
/**
* Display a listing of the resource.
*
2020-10-28 11:10:49 +01:00
* @return void
2020-06-23 13:05:41 +02:00
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*
2020-10-28 11:10:49 +01:00
* @return void
2020-06-23 13:05:41 +02:00
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
2020-10-28 11:10:49 +01:00
* @param StoreDocumentRequest $request
* @return void
2020-06-23 13:05:41 +02:00
*/
2020-06-24 10:59:56 +02:00
public function store(StoreDocumentRequest $request)
2020-06-23 13:05:41 +02:00
{
//
}
/**
* Display the specified resource.
*
2020-10-28 11:10:49 +01:00
* @param ShowDocumentRequest $request
* @param Document $document
* @return Response
2020-06-23 13:05:41 +02:00
*/
2020-06-24 10:59:56 +02:00
public function show(ShowDocumentRequest $request, Document $document)
2020-06-23 13:05:41 +02:00
{
2020-06-24 12:17:42 +02:00
return $this->itemResponse($document);
}
2020-06-24 10:59:56 +02:00
2020-06-24 14:12:43 +02:00
public function download(ShowDocumentRequest $request, Document $document)
2020-06-24 12:17:42 +02:00
{
return response()->streamDownload(function () use ($document) {
2020-06-24 12:17:42 +02:00
echo file_get_contents($document->generateUrl());
}, basename($document->generateUrl()));
2020-06-23 13:05:41 +02:00
}
/**
* Show the form for editing the specified resource.
*
2020-10-28 11:10:49 +01:00
* @param EditDocumentRegquest $request
* @param Document $document
* @return Response
2020-06-23 13:05:41 +02:00
*/
2020-06-24 10:59:56 +02:00
public function edit(EditDocumentRegquest $request, Document $document)
2020-06-23 13:05:41 +02:00
{
2020-06-24 14:12:43 +02:00
return $this->itemResponse($document);
2020-06-23 13:05:41 +02:00
}
/**
* Update the specified resource in storage.
*
2020-10-28 11:10:49 +01:00
* @param UpdateDocumentRequest $request
* @param Document $document
* @return Response
2020-06-23 13:05:41 +02:00
*/
2020-06-24 10:59:56 +02:00
public function update(UpdateDocumentRequest $request, Document $document)
2020-06-23 13:05:41 +02:00
{
2020-06-24 14:12:43 +02:00
return $this->itemResponse($document);
2020-06-23 13:05:41 +02:00
}
/**
* Remove the specified resource from storage.
*
2020-10-28 11:10:49 +01:00
* @param DestroyDocumentRequest $request
* @param Document $document
* @return Response
2020-06-23 13:05:41 +02:00
*/
2020-06-24 10:59:56 +02:00
public function destroy(DestroyDocumentRequest $request, Document $document)
2020-06-23 13:05:41 +02:00
{
2020-06-24 12:17:42 +02:00
$this->document_repo->delete($document);
return response()->json(['message'=>'success']);
2020-06-23 13:05:41 +02:00
}
public function bulk()
{
2020-06-24 12:17:42 +02:00
$action = request()->input('action');
$ids = request()->input('ids');
$documents = Document::withTrashed()->whereIn('id', $this->transformKeys($ids))->company()->get();
if (! $invoices) {
2020-06-24 12:17:42 +02:00
return response()->json(['message' => 'No Documents Found']);
}
/*
* Send the other actions to the switch
*/
$documents->each(function ($document, $key) use ($action) {
if (auth()->user()->can('edit', $document)) {
$this->{$action}($document);
}
});
/* Need to understand which permission are required for the given bulk action ie. view / edit */
return $this->listResponse(Document::withTrashed()->whereIn('id', $this->transformKeys($ids))->company());
2020-06-23 13:05:41 +02:00
}
}