1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/app/Services/ProductService.php
2019-01-30 22:25:37 +11:00

60 lines
1.3 KiB
PHP

<?php
namespace App\Services;
use App\Ninja\Datatables\ProductDatatable;
use App\Ninja\Repositories\ProductRepository;
use Auth;
use Utils;
class ProductService extends BaseService
{
/**
* @var DatatableService
*/
protected $datatableService;
/**
* @var ProductRepository
*/
protected $productRepo;
/**
* ProductService constructor.
*
* @param DatatableService $datatableService
* @param ProductRepository $productRepo
*/
public function __construct(DatatableService $datatableService, ProductRepository $productRepo)
{
$this->datatableService = $datatableService;
$this->productRepo = $productRepo;
}
/**
* @return ProductRepository
*/
protected function getRepo()
{
return $this->productRepo;
}
/**
* @param $accountId
* @param mixed $search
*
* @return \Illuminate\Http\JsonResponse
*/
public function getDatatable($accountId, $search)
{
$datatable = new ProductDatatable(true);
$query = $this->productRepo->find($accountId, $search);
if (! Utils::hasPermission('view_product')) {
$query->where('products.user_id', '=', Auth::user()->id);
}
return $this->datatableService->createDatatable($datatable, $query);
}
}