2015-10-28 20:22:07 +01:00
|
|
|
<?php namespace App\Services;
|
|
|
|
|
2016-04-27 18:13:29 +02:00
|
|
|
use Auth;
|
2016-03-02 14:36:42 +01:00
|
|
|
use Illuminate\Foundation\Bus\DispatchesJobs;
|
2015-11-05 23:37:04 +01:00
|
|
|
use App\Services\DatatableService;
|
2015-10-28 20:22:07 +01:00
|
|
|
|
|
|
|
class BaseService
|
|
|
|
{
|
2016-03-02 14:36:42 +01:00
|
|
|
use DispatchesJobs;
|
2015-10-28 20:22:07 +01:00
|
|
|
|
|
|
|
protected function getRepo()
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-10-29 15:42:05 +01:00
|
|
|
public function bulk($ids, $action)
|
2015-10-28 20:22:07 +01:00
|
|
|
{
|
2016-03-16 03:38:42 +01:00
|
|
|
if ( ! $ids ) {
|
2015-10-28 20:22:07 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
$entities = $this->getRepo()->findByPublicIdsWithTrashed($ids);
|
|
|
|
|
|
|
|
foreach ($entities as $entity) {
|
2016-04-26 03:53:39 +02:00
|
|
|
if(Auth::user()->can('edit', $entity)){
|
2016-03-16 03:07:11 +01:00
|
|
|
$this->getRepo()->$action($entity);
|
|
|
|
}
|
2015-10-28 20:22:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return count($entities);
|
|
|
|
}
|
2015-11-05 23:37:04 +01:00
|
|
|
|
2016-04-24 04:10:51 +02:00
|
|
|
public function createDatatable($entityType, $query, $showCheckbox = true, $hideClient = false, $orderColumns = [])
|
2015-11-05 23:37:04 +01:00
|
|
|
{
|
2015-11-15 11:08:32 +01:00
|
|
|
$columns = $this->getDatatableColumns($entityType, !$showCheckbox);
|
2015-11-05 23:37:04 +01:00
|
|
|
$actions = $this->getDatatableActions($entityType);
|
|
|
|
|
2016-04-24 04:10:51 +02:00
|
|
|
return $this->datatableService->createDatatable($entityType, $query, $columns, $actions, $showCheckbox, $orderColumns);
|
2015-11-05 23:37:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getDatatableColumns($entityType, $hideClient)
|
|
|
|
{
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getDatatableActions($entityType)
|
|
|
|
{
|
|
|
|
return [];
|
|
|
|
}
|
2015-10-28 20:22:07 +01:00
|
|
|
}
|