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

56 lines
1.3 KiB
PHP
Raw Normal View History

2015-11-05 23:37:04 +01:00
<?php namespace App\Services;
2016-09-23 16:00:47 +02:00
use Auth;
use Utils;
2015-11-05 23:37:04 +01:00
use App\Ninja\Repositories\ProductRepository;
2016-05-23 18:52:20 +02:00
use App\Ninja\Datatables\ProductDatatable;
2015-11-05 23:37:04 +01:00
class ProductService extends BaseService
{
/**
* @var DatatableService
*/
2015-11-05 23:37:04 +01:00
protected $datatableService;
/**
* @var ProductRepository
*/
2015-11-05 23:37:04 +01:00
protected $productRepo;
/**
* ProductService constructor.
*
* @param DatatableService $datatableService
* @param ProductRepository $productRepo
*/
2015-11-05 23:37:04 +01:00
public function __construct(DatatableService $datatableService, ProductRepository $productRepo)
{
$this->datatableService = $datatableService;
$this->productRepo = $productRepo;
}
/**
* @return ProductRepository
*/
2015-11-05 23:37:04 +01:00
protected function getRepo()
{
return $this->productRepo;
}
/**
* @param $accountId
* @return \Illuminate\Http\JsonResponse
*/
2016-10-18 20:15:08 +02:00
public function getDatatable($accountId, $search)
2015-11-05 23:37:04 +01:00
{
2016-09-23 16:00:47 +02:00
$datatable = new ProductDatatable(true);
2016-10-18 20:15:08 +02:00
$query = $this->productRepo->find($accountId, $search);
2015-11-05 23:37:04 +01:00
2016-09-23 16:00:47 +02:00
if(!Utils::hasPermission('view_all')){
$query->where('products.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
}