2016-11-29 18:47:26 +01:00
|
|
|
<?php namespace App\Services;
|
|
|
|
|
|
|
|
use App\Models\Client;
|
|
|
|
use App\Ninja\Repositories\ProjectRepository;
|
|
|
|
use App\Ninja\Datatables\ProjectDatatable;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ProjectService
|
|
|
|
*/
|
|
|
|
class ProjectService extends BaseService
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var ProjectRepository
|
|
|
|
*/
|
|
|
|
protected $projectRepo;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var DatatableService
|
|
|
|
*/
|
|
|
|
protected $datatableService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CreditService constructor.
|
|
|
|
*
|
|
|
|
* @param ProjectRepository $creditRepo
|
|
|
|
* @param DatatableService $datatableService
|
|
|
|
*/
|
|
|
|
public function __construct(ProjectRepository $projectRepo, DatatableService $datatableService)
|
|
|
|
{
|
|
|
|
$this->projectRepo = $projectRepo;
|
|
|
|
$this->datatableService = $datatableService;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return CreditRepository
|
|
|
|
*/
|
|
|
|
protected function getRepo()
|
|
|
|
{
|
|
|
|
return $this->projectRepo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $data
|
|
|
|
* @return mixed|null
|
|
|
|
*/
|
2016-12-15 14:11:04 +01:00
|
|
|
public function save($data, $project = false)
|
2016-11-29 18:47:26 +01:00
|
|
|
{
|
|
|
|
if (isset($data['client_id']) && $data['client_id']) {
|
|
|
|
$data['client_id'] = Client::getPrivateId($data['client_id']);
|
|
|
|
}
|
|
|
|
|
2016-12-15 13:17:10 +01:00
|
|
|
return $this->projectRepo->save($data, $project);
|
2016-11-29 18:47:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $clientPublicId
|
|
|
|
* @param $search
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
*/
|
|
|
|
public function getDatatable($search, $userId)
|
|
|
|
{
|
|
|
|
// we don't support bulk edit and hide the client on the individual client page
|
|
|
|
$datatable = new ProjectDatatable();
|
|
|
|
|
|
|
|
$query = $this->projectRepo->find($search, $userId);
|
|
|
|
|
|
|
|
return $this->datatableService->createDatatable($datatable, $query);
|
|
|
|
}
|
|
|
|
}
|