2017-01-30 21:40:43 +02:00
|
|
|
<?php
|
2015-11-06 00:37:04 +02:00
|
|
|
|
2017-01-30 21:40:43 +02:00
|
|
|
namespace App\Services;
|
|
|
|
|
|
|
|
|
|
use App\Ninja\Datatables\ProductDatatable;
|
|
|
|
|
use App\Ninja\Repositories\ProductRepository;
|
2016-09-23 17:00:47 +03:00
|
|
|
use Auth;
|
|
|
|
|
use Utils;
|
2015-11-06 00:37:04 +02:00
|
|
|
|
|
|
|
|
class ProductService extends BaseService
|
|
|
|
|
{
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
|
* @var DatatableService
|
|
|
|
|
*/
|
2015-11-06 00:37:04 +02:00
|
|
|
protected $datatableService;
|
2016-07-03 18:11:58 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var ProductRepository
|
|
|
|
|
*/
|
2015-11-06 00:37:04 +02:00
|
|
|
protected $productRepo;
|
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
|
* ProductService constructor.
|
|
|
|
|
*
|
2017-01-30 21:40:43 +02:00
|
|
|
* @param DatatableService $datatableService
|
2016-07-03 18:11:58 +02:00
|
|
|
* @param ProductRepository $productRepo
|
|
|
|
|
*/
|
2015-11-06 00:37:04 +02:00
|
|
|
public function __construct(DatatableService $datatableService, ProductRepository $productRepo)
|
|
|
|
|
{
|
|
|
|
|
$this->datatableService = $datatableService;
|
|
|
|
|
$this->productRepo = $productRepo;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
|
* @return ProductRepository
|
|
|
|
|
*/
|
2015-11-06 00:37:04 +02:00
|
|
|
protected function getRepo()
|
|
|
|
|
{
|
|
|
|
|
return $this->productRepo;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
|
* @param $accountId
|
2017-01-30 21:49:42 +02:00
|
|
|
* @param mixed $search
|
2017-01-30 21:40:43 +02:00
|
|
|
*
|
2016-07-03 18:11:58 +02:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
|
*/
|
2016-10-18 21:15:08 +03:00
|
|
|
public function getDatatable($accountId, $search)
|
2015-11-06 00:37:04 +02:00
|
|
|
{
|
2016-09-23 17:00:47 +03:00
|
|
|
$datatable = new ProductDatatable(true);
|
2016-10-18 21:15:08 +03:00
|
|
|
$query = $this->productRepo->find($accountId, $search);
|
2015-11-06 00:37:04 +02:00
|
|
|
|
2018-06-07 20:08:34 +10:00
|
|
|
if (! Utils::hasPermission('view_product')) {
|
2016-09-23 17:00:47 +03:00
|
|
|
$query->where('products.user_id', '=', Auth::user()->id);
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-23 19:52:20 +03:00
|
|
|
return $this->datatableService->createDatatable($datatable, $query);
|
2015-11-06 00:37:04 +02:00
|
|
|
}
|
2016-05-23 19:52:20 +03:00
|
|
|
}
|