2017-01-30 20:40:43 +01:00
|
|
|
<?php
|
2015-11-05 23:37:04 +01:00
|
|
|
|
2017-01-30 20:40:43 +01:00
|
|
|
namespace App\Services;
|
|
|
|
|
2017-12-24 20:01:17 +01:00
|
|
|
use App\Ninja\Datatables\ProjectTaskDatatable;
|
2017-01-30 20:40:43 +01:00
|
|
|
use App\Ninja\Datatables\TaskDatatable;
|
|
|
|
use App\Ninja\Repositories\TaskRepository;
|
2016-03-16 00:08:00 +01:00
|
|
|
use Auth;
|
2015-11-05 23:37:04 +01:00
|
|
|
use Utils;
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
2017-01-30 20:40:43 +01:00
|
|
|
* Class TaskService.
|
2016-07-03 18:11:58 +02:00
|
|
|
*/
|
2015-11-05 23:37:04 +01:00
|
|
|
class TaskService extends BaseService
|
|
|
|
{
|
|
|
|
protected $datatableService;
|
|
|
|
protected $taskRepo;
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* TaskService constructor.
|
|
|
|
*
|
2017-01-30 20:40:43 +01:00
|
|
|
* @param TaskRepository $taskRepo
|
2016-07-03 18:11:58 +02:00
|
|
|
* @param DatatableService $datatableService
|
|
|
|
*/
|
2015-11-05 23:37:04 +01:00
|
|
|
public function __construct(TaskRepository $taskRepo, DatatableService $datatableService)
|
|
|
|
{
|
|
|
|
$this->taskRepo = $taskRepo;
|
|
|
|
$this->datatableService = $datatableService;
|
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return TaskRepository
|
|
|
|
*/
|
2015-11-05 23:37:04 +01:00
|
|
|
protected function getRepo()
|
|
|
|
{
|
|
|
|
return $this->taskRepo;
|
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @param $clientPublicId
|
|
|
|
* @param $search
|
2017-01-30 20:40:43 +01:00
|
|
|
*
|
2016-07-03 18:11:58 +02:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
*/
|
2017-12-24 20:01:17 +01:00
|
|
|
public function getDatatable($clientPublicId, $projectPublicId, $search)
|
2015-11-05 23:37:04 +01:00
|
|
|
{
|
2017-12-24 20:01:17 +01:00
|
|
|
if ($projectPublicId) {
|
|
|
|
$datatable = new ProjectTaskDatatable(true, true);
|
|
|
|
} else {
|
|
|
|
$datatable = new TaskDatatable(true, $clientPublicId);
|
|
|
|
}
|
|
|
|
|
|
|
|
$query = $this->taskRepo->find($clientPublicId, $projectPublicId, $search);
|
2015-11-05 23:37:04 +01:00
|
|
|
|
2017-01-30 20:40:43 +01:00
|
|
|
if (! Utils::hasPermission('view_all')) {
|
2016-03-16 00:08:00 +01:00
|
|
|
$query->where('tasks.user_id', '=', Auth::user()->id);
|
|
|
|
}
|
|
|
|
|
2016-05-23 18:52:20 +02:00
|
|
|
return $this->datatableService->createDatatable($datatable, $query);
|
2015-11-05 23:37:04 +01:00
|
|
|
}
|
2016-05-23 18:52:20 +02:00
|
|
|
}
|