1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-13 22:54:25 +01:00
invoiceninja/app/Services/ProductService.php
2016-10-18 21:15:08 +03:00

56 lines
1.3 KiB
PHP

<?php namespace App\Services;
use Auth;
use Utils;
use App\Ninja\Repositories\ProductRepository;
use App\Ninja\Datatables\ProductDatatable;
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
* @return \Illuminate\Http\JsonResponse
*/
public function getDatatable($accountId, $search)
{
$datatable = new ProductDatatable(true);
$query = $this->productRepo->find($accountId, $search);
if(!Utils::hasPermission('view_all')){
$query->where('products.user_id', '=', Auth::user()->id);
}
return $this->datatableService->createDatatable($datatable, $query);
}
}