1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/app/Http/Controllers/TaskStatusController.php

184 lines
4.9 KiB
PHP
Raw Normal View History

2020-10-20 01:01:59 +02:00
<?php
2023-05-18 01:12:12 +02:00
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
2020-10-20 01:01:59 +02:00
namespace App\Http\Controllers;
use App\Factory\TaskStatusFactory;
2022-01-03 02:20:03 +01:00
use App\Filters\TaskStatusFilters;
2023-10-26 04:57:44 +02:00
use App\Http\Requests\TaskStatus\ActionTaskStatusRequest;
use App\Http\Requests\TaskStatus\CreateTaskStatusRequest;
use App\Http\Requests\TaskStatus\DestroyTaskStatusRequest;
2023-08-04 10:13:26 +02:00
use App\Http\Requests\TaskStatus\EditTaskStatusRequest;
2020-10-20 01:01:59 +02:00
use App\Http\Requests\TaskStatus\ShowTaskStatusRequest;
use App\Http\Requests\TaskStatus\StoreTaskStatusRequest;
use App\Http\Requests\TaskStatus\UpdateTaskStatusRequest;
2023-10-26 04:57:44 +02:00
use App\Models\TaskStatus;
use App\Repositories\TaskStatusRepository;
use App\Transformers\TaskStatusTransformer;
use App\Utils\Traits\MakesHash;
use Illuminate\Http\Response;
2020-10-20 01:01:59 +02:00
class TaskStatusController extends BaseController
{
use MakesHash;
protected $entity_type = TaskStatus::class;
protected $entity_transformer = TaskStatusTransformer::class;
/**
* @var TaskStatusRepository
*/
protected $task_status_repo;
/**
* TaskStatusController constructor.
*
2020-10-28 11:10:49 +01:00
* @param TaskStatusRepository $task_status_repo The payment term repo
2020-10-20 01:01:59 +02:00
*/
public function __construct(TaskStatusRepository $task_status_repo)
{
parent::__construct();
$this->task_status_repo = $task_status_repo;
}
2024-01-14 05:05:00 +01:00
2020-10-20 01:01:59 +02:00
/**
2023-05-18 01:12:12 +02:00
* index
*
* @param TaskStatusFilters $filters
* @return Response
2020-10-20 01:01:59 +02:00
*/
2022-01-03 02:20:03 +01:00
public function index(TaskStatusFilters $filters)
2020-10-20 01:01:59 +02:00
{
2022-01-03 02:20:03 +01:00
$task_status = TaskStatus::filter($filters);
2020-10-20 01:01:59 +02:00
return $this->listResponse($task_status);
}
2024-01-14 05:05:00 +01:00
2020-10-20 01:01:59 +02:00
/**
2023-05-18 01:12:12 +02:00
* create
2020-10-20 01:01:59 +02:00
*
2023-05-18 01:12:12 +02:00
* @param CreateTaskStatusRequest $request
2020-10-28 11:10:49 +01:00
* @return Response
2020-10-20 01:01:59 +02:00
*/
public function create(CreateTaskStatusRequest $request)
{
2023-09-27 06:12:03 +02:00
/** @var \App\Models\User $user */
$user = auth()->user();
$task_status = TaskStatusFactory::create($user->company()->id, auth()->user()->id);
2020-10-20 01:01:59 +02:00
return $this->itemResponse($task_status);
}
/**
* Store a newly created resource in storage.
*
2020-10-28 11:10:49 +01:00
* @param StoreTaskStatusRequest $request The request
* @return Response
2020-10-20 01:01:59 +02:00
*
2023-05-18 01:12:12 +02:00
*/
2020-10-20 01:01:59 +02:00
public function store(StoreTaskStatusRequest $request)
{
2023-09-27 06:12:03 +02:00
/** @var \App\Models\User $user */
$user = auth()->user();
2023-09-27 06:12:03 +02:00
$task_status = TaskStatusFactory::create($user->company()->id, auth()->user()->id);
2020-10-20 01:01:59 +02:00
$task_status->fill($request->all());
2021-01-07 23:03:29 +01:00
2020-10-20 01:01:59 +02:00
$task_status->save();
return $this->itemResponse($task_status->fresh());
}
/**
2020-10-28 11:10:49 +01:00
* @param ShowTaskStatusRequest $request
* @param TaskStatus $task_status
* @return Response|mixed
2020-10-20 01:01:59 +02:00
*/
public function show(ShowTaskStatusRequest $request, TaskStatus $task_status)
{
return $this->itemResponse($task_status);
}
/**
2020-10-28 11:10:49 +01:00
* @param EditTaskStatusRequest $request
* @param TaskStatus $payment
* @return Response|mixed
2020-10-20 01:01:59 +02:00
*/
public function edit(EditTaskStatusRequest $request, TaskStatus $payment)
{
return $this->itemResponse($payment);
}
/**
* Update the specified resource in storage.
*
2020-10-28 11:10:49 +01:00
* @param UpdateTaskStatusRequest $request The request
* @param TaskStatus $task_status The payment term
* @return Response
2020-10-20 01:01:59 +02:00
*/
public function update(UpdateTaskStatusRequest $request, TaskStatus $task_status)
{
2024-01-14 05:05:00 +01:00
2020-10-20 01:01:59 +02:00
$task_status->fill($request->all());
2023-05-18 01:12:12 +02:00
$reorder = $task_status->isDirty('status_order');
2020-10-20 01:01:59 +02:00
$task_status->save();
2024-01-14 05:05:00 +01:00
2023-10-26 04:57:44 +02:00
if ($reorder) {
2023-05-18 01:12:12 +02:00
$this->task_status_repo->reorder($task_status);
2023-10-26 04:57:44 +02:00
}
2023-05-18 01:12:12 +02:00
2020-10-20 01:01:59 +02:00
return $this->itemResponse($task_status->fresh());
2024-01-14 05:05:00 +01:00
2020-10-20 01:01:59 +02:00
}
/**
* Remove the specified resource from storage.
*
2020-10-28 11:10:49 +01:00
* @param DestroyTaskStatusRequest $request
* @param TaskStatus $task_status
2023-05-18 01:12:12 +02:00
* @return Response
2023-10-26 04:57:44 +02:00
*
2020-10-28 11:10:49 +01:00
* @throws \Exception
2020-10-20 01:01:59 +02:00
*/
public function destroy(DestroyTaskStatusRequest $request, TaskStatus $task_status)
{
2021-04-19 11:59:11 +02:00
$task_status = $this->task_status_repo->delete($task_status);
2021-04-19 11:59:11 +02:00
return $this->itemResponse($task_status);
2020-10-20 01:01:59 +02:00
}
/**
* Perform bulk actions on the list view.
2023-05-18 01:12:12 +02:00
* @param ActionTaskStatusRequest $request
* @return Response
2020-10-20 01:01:59 +02:00
*/
2023-02-09 03:30:39 +01:00
public function bulk(ActionTaskStatusRequest $request)
2020-10-20 01:01:59 +02:00
{
2023-02-09 03:30:39 +01:00
$action = $request->input('action');
2020-10-20 01:01:59 +02:00
2023-02-09 03:30:39 +01:00
$ids = $request->input('ids');
2020-10-20 01:01:59 +02:00
2023-02-09 03:30:39 +01:00
TaskStatus::withTrashed()
->company()
->whereIn('id', $this->transformKeys($ids))
->cursor()
->each(function ($task_status, $key) use ($action) {
2023-02-16 02:36:09 +01:00
$this->task_status_repo->{$action}($task_status);
});
2020-10-20 01:01:59 +02:00
return $this->listResponse(TaskStatus::withTrashed()->whereIn('id', $this->transformKeys($ids)));
}
}