invoiceninja/app/Services/BaseService.php
Joshua Dwire 90e1f6695c Improve user permission support
* Hide links based on permissions
* Restrict editing/creating within other UI
2016-03-15 22:07:11 -04:00

52 lines
1.2 KiB
PHP

<?php namespace App\Services;
use Illuminate\Foundation\Bus\DispatchesJobs;
use App\Services\DatatableService;
class BaseService
{
public static $bulk_actions = array('archive', 'restore', 'delete');
use DispatchesJobs;
protected function getRepo()
{
return null;
}
public function bulk($ids, $action)
{
if ( ! $ids || ! in_array($action, static::$bulk_actions) ) {
return 0;
}
$entities = $this->getRepo()->findByPublicIdsWithTrashed($ids);
foreach ($entities as $entity) {
if($entity->canEdit()){
$this->getRepo()->$action($entity);
}
}
return count($entities);
}
public function createDatatable($entityType, $query, $showCheckbox = true, $hideClient = false)
{
$columns = $this->getDatatableColumns($entityType, !$showCheckbox);
$actions = $this->getDatatableActions($entityType);
return $this->datatableService->createDatatable($entityType, $query, $columns, $actions, $showCheckbox);
}
protected function getDatatableColumns($entityType, $hideClient)
{
return [];
}
protected function getDatatableActions($entityType)
{
return [];
}
}