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

46 lines
737 B
PHP
Raw Normal View History

2017-01-30 20:40:43 +01:00
<?php
namespace App\Services;
2015-10-28 20:22:07 +01:00
2016-04-27 18:13:29 +02:00
use Auth;
2016-03-02 14:36:42 +01:00
use Illuminate\Foundation\Bus\DispatchesJobs;
2015-10-28 20:22:07 +01:00
/**
2017-01-30 20:40:43 +01:00
* Class BaseService.
*/
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
/**
* @return null
*/
2015-10-28 20:22:07 +01:00
protected function getRepo()
{
return null;
}
/**
* @param $ids
* @param $action
2017-01-30 20:40:43 +01:00
*
* @return int
*/
2015-10-29 15:42:05 +01:00
public function bulk($ids, $action)
2015-10-28 20:22:07 +01:00
{
2017-01-30 17:05:31 +01:00
if (! $ids) {
2015-10-28 20:22:07 +01:00
return 0;
}
$entities = $this->getRepo()->findByPublicIdsWithTrashed($ids);
foreach ($entities as $entity) {
2016-08-02 16:38:51 +02:00
if (Auth::user()->can('edit', $entity)) {
$this->getRepo()->$action($entity);
}
2015-10-28 20:22:07 +01:00
}
return count($entities);
}
}