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

145 lines
4.4 KiB
PHP
Raw Normal View History

2015-11-05 23:37:04 +01:00
<?php namespace App\Services;
2016-03-16 00:08:00 +01:00
use Auth;
2015-11-05 23:37:04 +01:00
use URL;
use Utils;
use App\Models\Task;
2016-03-16 00:08:00 +01:00
use App\Models\Invoice;
use App\Models\Client;
2015-11-05 23:37:04 +01:00
use App\Ninja\Repositories\TaskRepository;
use App\Services\BaseService;
class TaskService extends BaseService
{
protected $datatableService;
protected $taskRepo;
public function __construct(TaskRepository $taskRepo, DatatableService $datatableService)
{
$this->taskRepo = $taskRepo;
$this->datatableService = $datatableService;
}
protected function getRepo()
{
return $this->taskRepo;
}
/*
public function save()
{
return null;
}
*/
public function getDatatable($clientPublicId, $search)
{
$query = $this->taskRepo->find($clientPublicId, $search);
2016-03-16 00:08:00 +01:00
if(!Utils::hasPermission('view_all')){
$query->where('tasks.user_id', '=', Auth::user()->id);
}
2015-11-05 23:37:04 +01:00
return $this->createDatatable(ENTITY_TASK, $query, !$clientPublicId);
}
protected function getDatatableColumns($entityType, $hideClient)
{
return [
[
'client_name',
function ($model) {
2016-04-26 03:53:39 +02:00
if(!Auth::user()->can('viewByOwner', [ENTITY_CLIENT, $model->client_user_id])){
return Utils::getClientDisplayName($model);
}
2016-03-02 14:36:42 +01:00
return $model->client_public_id ? link_to("clients/{$model->client_public_id}", Utils::getClientDisplayName($model))->toHtml() : '';
2015-11-05 23:37:04 +01:00
},
! $hideClient
],
[
'created_at',
function ($model) {
2016-03-02 14:36:42 +01:00
return link_to("tasks/{$model->public_id}/edit", Task::calcStartTime($model))->toHtml();
2015-11-05 23:37:04 +01:00
}
],
[
'time_log',
function($model) {
return Utils::formatTime(Task::calcDuration($model));
}
],
[
'description',
function ($model) {
return $model->description;
}
],
[
'invoice_number',
function ($model) {
return self::getStatusLabel($model);
}
]
];
}
protected function getDatatableActions($entityType)
{
return [
[
trans('texts.edit_task'),
function ($model) {
return URL::to('tasks/'.$model->public_id.'/edit');
},
function ($model) {
2016-04-26 03:53:39 +02:00
return (!$model->deleted_at || $model->deleted_at == '0000-00-00') && Auth::user()->can('editByOwner', [ENTITY_TASK, $model->user_id]);
2015-11-05 23:37:04 +01:00
}
],
[
trans('texts.view_invoice'),
function ($model) {
return URL::to("/invoices/{$model->invoice_public_id}/edit");
},
function ($model) {
2016-04-26 03:53:39 +02:00
return $model->invoice_number && Auth::user()->can('editByOwner', [ENTITY_INVOICE, $model->invoice_user_id]);
2015-11-05 23:37:04 +01:00
}
],
[
trans('texts.stop_task'),
function ($model) {
return "javascript:stopTask({$model->public_id})";
},
function ($model) {
2016-04-26 03:53:39 +02:00
return $model->is_running && Auth::user()->can('editByOwner', [ENTITY_TASK, $model->user_id]);
2015-11-05 23:37:04 +01:00
}
],
[
trans('texts.invoice_task'),
function ($model) {
2016-01-21 23:29:10 +01:00
return "javascript:invoiceEntity({$model->public_id})";
2015-11-05 23:37:04 +01:00
},
function ($model) {
2016-04-26 03:53:39 +02:00
return ! $model->invoice_number && (!$model->deleted_at || $model->deleted_at == '0000-00-00') && Auth::user()->can('create', ENTITY_INVOICE);
2015-11-05 23:37:04 +01:00
}
]
];
}
private function getStatusLabel($model)
{
if ($model->invoice_number) {
$class = 'success';
$label = trans('texts.invoiced');
} elseif ($model->is_running) {
$class = 'primary';
$label = trans('texts.running');
} else {
$class = 'default';
$label = trans('texts.logged');
}
return "<h4><div class=\"label label-{$class}\">$label</div></h4>";
}
}