1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00
invoiceninja/app/Ninja/Datatables/TaskDatatable.php

133 lines
4.8 KiB
PHP
Raw Normal View History

2017-01-30 20:40:43 +01:00
<?php
namespace App\Ninja\Datatables;
2016-05-23 18:52:20 +02:00
use App\Models\Task;
2017-01-30 20:40:43 +01:00
use Auth;
use URL;
use Utils;
2016-05-23 18:52:20 +02:00
class TaskDatatable extends EntityDatatable
{
public $entityType = ENTITY_TASK;
2016-11-29 18:47:26 +01:00
public $sortCol = 3;
2016-05-23 18:52:20 +02:00
public function columns()
{
return [
[
'client_name',
function ($model) {
2017-01-30 20:40:43 +01:00
if (! Auth::user()->can('viewByOwner', [ENTITY_CLIENT, $model->client_user_id])) {
2016-05-23 18:52:20 +02:00
return Utils::getClientDisplayName($model);
}
return $model->client_public_id ? link_to("clients/{$model->client_public_id}", Utils::getClientDisplayName($model))->toHtml() : '';
},
2017-01-30 20:40:43 +01:00
! $this->hideClient,
2016-05-23 18:52:20 +02:00
],
2016-11-29 18:47:26 +01:00
[
'project',
function ($model) {
2017-01-30 20:40:43 +01:00
if (! Auth::user()->can('editByOwner', [ENTITY_PROJECT, $model->project_user_id])) {
2016-11-29 18:47:26 +01:00
return $model->project;
}
2017-12-24 20:01:17 +01:00
return $model->project_public_id ? link_to("projects/{$model->project_public_id}", $model->project)->toHtml() : '';
2017-01-30 20:40:43 +01:00
},
2016-11-29 18:47:26 +01:00
],
2016-05-23 18:52:20 +02:00
[
'date',
2016-05-23 18:52:20 +02:00
function ($model) {
2017-01-30 20:40:43 +01:00
if (! Auth::user()->can('viewByOwner', [ENTITY_EXPENSE, $model->user_id])) {
return Task::calcStartTime($model);
}
2017-01-30 20:40:43 +01:00
2016-05-23 18:52:20 +02:00
return link_to("tasks/{$model->public_id}/edit", Task::calcStartTime($model))->toHtml();
2017-01-30 20:40:43 +01:00
},
2016-05-23 18:52:20 +02:00
],
[
'duration',
2017-01-30 17:05:31 +01:00
function ($model) {
2017-12-19 19:36:25 +01:00
if (! Auth::user()->can('viewByOwner', [ENTITY_EXPENSE, $model->user_id])) {
return Utils::formatTime(Task::calcDuration($model));
}
return link_to("tasks/{$model->public_id}/edit", Utils::formatTime(Task::calcDuration($model)))->toHtml();
2017-01-30 20:40:43 +01:00
},
2016-05-23 18:52:20 +02:00
],
[
'description',
function ($model) {
2018-01-08 11:01:06 +01:00
return e(substr($model->description, 0, 80) . (strlen($model->description) > 80 ? '...' : ''));
2017-01-30 20:40:43 +01:00
},
2016-05-23 18:52:20 +02:00
],
[
'status',
2016-05-23 18:52:20 +02:00
function ($model) {
return self::getStatusLabel($model);
2017-01-30 20:40:43 +01:00
},
],
2016-05-23 18:52:20 +02:00
];
}
public function actions()
{
return [
[
trans('texts.edit_task'),
function ($model) {
return URL::to('tasks/'.$model->public_id.'/edit');
},
function ($model) {
2017-01-30 20:40:43 +01:00
return (! $model->deleted_at || $model->deleted_at == '0000-00-00') && Auth::user()->can('editByOwner', [ENTITY_TASK, $model->user_id]);
},
2016-05-23 18:52:20 +02:00
],
[
trans('texts.view_invoice'),
function ($model) {
return URL::to("/invoices/{$model->invoice_public_id}/edit");
},
function ($model) {
return $model->invoice_number && Auth::user()->can('editByOwner', [ENTITY_INVOICE, $model->invoice_user_id]);
2017-01-30 20:40:43 +01:00
},
2016-05-23 18:52:20 +02:00
],
2017-05-22 20:35:50 +02:00
[
trans('texts.resume_task'),
function ($model) {
return "javascript:submitForm_task('resume', {$model->public_id})";
},
function ($model) {
return ! $model->is_running && Auth::user()->can('editByOwner', [ENTITY_TASK, $model->user_id]);
},
],
2016-05-23 18:52:20 +02:00
[
trans('texts.stop_task'),
function ($model) {
2016-11-25 11:53:35 +01:00
return "javascript:submitForm_task('stop', {$model->public_id})";
2016-05-23 18:52:20 +02:00
},
function ($model) {
return $model->is_running && Auth::user()->can('editByOwner', [ENTITY_TASK, $model->user_id]);
2017-01-30 20:40:43 +01:00
},
2016-05-23 18:52:20 +02:00
],
[
trans('texts.invoice_task'),
function ($model) {
2016-11-25 11:53:35 +01:00
return "javascript:submitForm_task('invoice', {$model->public_id})";
2016-05-23 18:52:20 +02:00
},
function ($model) {
2017-05-22 20:35:50 +02:00
return ! $model->is_running && ! $model->invoice_number && (! $model->deleted_at || $model->deleted_at == '0000-00-00') && Auth::user()->can('create', ENTITY_INVOICE);
2017-01-30 20:40:43 +01:00
},
],
2016-05-23 18:52:20 +02:00
];
}
private function getStatusLabel($model)
{
2017-12-19 19:36:25 +01:00
$label = Task::calcStatusLabel($model->is_running, $model->balance, $model->invoice_number, $model->task_status);
2016-12-26 19:09:49 +01:00
$class = Task::calcStatusClass($model->is_running, $model->balance, $model->invoice_number);
2016-05-23 18:52:20 +02:00
return "<h4><div class=\"label label-{$class}\">$label</div></h4>";
}
}