mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-06 03:02:34 +01:00
ba75a44eb8
* Adopt Laravel coding style The Laravel framework adopts the PSR-2 coding style with some additions. Laravel apps *should* adopt this coding style as well. However, Shift allows you to customize the adopted coding style by adding your own [PHP CS Fixer][1] `.php_cs` config to your project. You may use [Shift's .php_cs][2] file as a base. [1]: https://github.com/FriendsOfPHP/PHP-CS-Fixer [2]: https://gist.github.com/laravel-shift/cab527923ed2a109dda047b97d53c200 * Shift bindings PHP 5.5.9+ adds the new static `class` property which provides the fully qualified class name. This is preferred over using class name strings as these references are checked by the parser. * Shift core files * Shift to Throwable * Add laravel/ui dependency * Unindent vendor mail templates * Shift config files * Default config files In an effort to make upgrading the constantly changing config files easier, Shift defaulted them so you can review the commit diff for changes. Moving forward, you should use ENV variables or create a separate config file to allow the core config files to remain automatically upgradeable. * Shift Laravel dependencies * Shift cleanup * Upgrade to Laravel 7 Co-authored-by: Laravel Shift <shift@laravelshift.com>
153 lines
3.9 KiB
PHP
153 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Http\Requests\Document\DestroyDocumentRequest;
|
|
use App\Http\Requests\Document\EditDocumentRequest;
|
|
use App\Http\Requests\Document\ShowDocumentRequest;
|
|
use App\Http\Requests\Document\StoreDocumentRequest;
|
|
use App\Http\Requests\Document\UpdateDocumentRequest;
|
|
use App\Models\Document;
|
|
use App\Repositories\DocumentRepository;
|
|
use App\Transformers\DocumentTransformer;
|
|
use App\Utils\Traits\MakesHash;
|
|
use Illuminate\Http\Request;
|
|
|
|
class DocumentController extends BaseController
|
|
{
|
|
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();
|
|
|
|
$this->middleware('password_protected', ['only' => ['destroy']]);
|
|
|
|
$this->document_repo = $document_repo;
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(StoreDocumentRequest $request)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function show(ShowDocumentRequest $request, Document $document)
|
|
{
|
|
return $this->itemResponse($document);
|
|
}
|
|
|
|
public function download(ShowDocumentRequest $request, Document $document)
|
|
{
|
|
return response()->streamDownload(function () use ($document) {
|
|
echo file_get_contents($document->generateUrl());
|
|
}, basename($document->generateUrl()));
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit(EditDocumentRegquest $request, Document $document)
|
|
{
|
|
return $this->itemResponse($document);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(UpdateDocumentRequest $request, Document $document)
|
|
{
|
|
return $this->itemResponse($document);
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy(DestroyDocumentRequest $request, Document $document)
|
|
{
|
|
$this->document_repo->delete($document);
|
|
|
|
return response()->json(['message'=>'success']);
|
|
}
|
|
|
|
public function bulk()
|
|
{
|
|
$action = request()->input('action');
|
|
|
|
$ids = request()->input('ids');
|
|
|
|
$documents = Document::withTrashed()->whereIn('id', $this->transformKeys($ids))->company()->get();
|
|
|
|
if (! $invoices) {
|
|
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());
|
|
}
|
|
}
|