1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00
invoiceninja/app/Http/Controllers/BaseController.php

54 lines
1.5 KiB
PHP
Raw Normal View History

2017-01-30 20:40:43 +01:00
<?php
namespace App\Http\Controllers;
2015-03-16 22:45:25 +01:00
2016-04-26 03:53:39 +02:00
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
2017-01-30 20:40:43 +01:00
use Illuminate\Foundation\Bus\DispatchesJobs;
use Request;
use Utils;
2015-10-28 20:22:07 +01:00
2015-03-16 22:45:25 +01:00
class BaseController extends Controller
{
2016-04-26 03:53:39 +02:00
use DispatchesJobs, AuthorizesRequests;
2016-05-15 12:58:11 +02:00
2016-04-28 14:16:33 +02:00
protected $entityType;
2015-10-28 20:22:07 +01:00
2015-03-16 22:45:25 +01:00
/**
* Setup the layout used by the controller.
*
* @return void
*/
protected function setupLayout()
{
if (! is_null($this->layout)) {
$this->layout = View::make($this->layout);
}
}
2016-09-19 15:30:46 +02:00
protected function returnBulk($entityType, $action, $ids)
{
2017-01-30 17:05:31 +01:00
if (! is_array($ids)) {
$ids = [$ids];
}
2016-11-25 11:53:35 +01:00
2016-09-19 15:30:46 +02:00
$isDatatable = filter_var(request()->datatable, FILTER_VALIDATE_BOOLEAN);
2016-11-25 11:53:35 +01:00
$referer = Request::server('HTTP_REFERER');
2016-09-19 15:30:46 +02:00
$entityTypes = Utils::pluralizeEntityType($entityType);
2016-11-25 11:53:35 +01:00
// when restoring redirect to entity
2016-11-25 15:02:39 +01:00
if ($action == 'restore' && count($ids) == 1) {
return redirect("{$entityTypes}/" . $ids[0]);
2016-11-25 11:53:35 +01:00
// when viewing from a datatable list
2017-12-25 11:39:00 +01:00
} elseif (strpos($referer, '/clients/') || strpos($referer, '/projects/')) {
2016-11-25 15:02:39 +01:00
return redirect($referer);
2016-09-19 15:30:46 +02:00
} elseif ($isDatatable || ($action == 'archive' || $action == 'delete')) {
return redirect("{$entityTypes}");
2016-11-25 11:53:35 +01:00
// when viewing individual entity
2016-09-19 15:30:46 +02:00
} elseif (count($ids)) {
return redirect("{$entityTypes}/" . $ids[0] . '/edit');
2016-09-19 15:30:46 +02:00
} else {
return redirect("{$entityTypes}");
}
}
2015-03-16 22:45:25 +01:00
}