Widget jobs added and created_by column fixed..
This commit is contained in:
@@ -136,6 +136,7 @@ class CreateDashboard extends Job
|
||||
'name' => $name,
|
||||
'sort' => $sort,
|
||||
'settings' => (new $class())->getDefaultSettings(),
|
||||
'created_by' => user_id(),
|
||||
]);
|
||||
|
||||
$sort++;
|
||||
|
||||
40
app/Jobs/Common/CreateWidget.php
Normal file
40
app/Jobs/Common/CreateWidget.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Common;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Models\Common\Widget;
|
||||
|
||||
class CreateWidget extends Job
|
||||
{
|
||||
protected $widget;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $request
|
||||
*/
|
||||
public function __construct($request)
|
||||
{
|
||||
$this->request = $this->getRequestInstance($request);
|
||||
$this->request->merge(['created_by' => user_id()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return Widget
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->request['enabled'] = $this->request['enabled'] ?? 1;
|
||||
|
||||
\DB::transaction(function () {
|
||||
$this->widget = Widget::create($this->request->all());
|
||||
});
|
||||
|
||||
return $this->widget;
|
||||
}
|
||||
}
|
||||
62
app/Jobs/Common/DeleteWidget.php
Normal file
62
app/Jobs/Common/DeleteWidget.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Common;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
|
||||
class DeleteItem extends Job
|
||||
{
|
||||
protected $item;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $item
|
||||
*/
|
||||
public function __construct($item)
|
||||
{
|
||||
$this->item = $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return boolean|Exception
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
\DB::transaction(function () {
|
||||
$this->deleteRelationships($this->item, ['taxes']);
|
||||
|
||||
$this->item->delete();
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if this action is applicable.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
if ($relationships = $this->getRelationships()) {
|
||||
$message = trans('messages.warning.deleted', ['name' => $this->item->name, 'text' => implode(', ', $relationships)]);
|
||||
|
||||
throw new \Exception($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function getRelationships()
|
||||
{
|
||||
$rels = [
|
||||
'invoice_items' => 'invoices',
|
||||
'bill_items' => 'bills',
|
||||
];
|
||||
|
||||
return $this->countRelationships($this->item, $rels);
|
||||
}
|
||||
}
|
||||
39
app/Jobs/Common/UpdateWidget.php
Normal file
39
app/Jobs/Common/UpdateWidget.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Common;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Models\Common\Widget;
|
||||
|
||||
class UpdateItem extends Job
|
||||
{
|
||||
protected $widget;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $widget
|
||||
* @param $request
|
||||
*/
|
||||
public function __construct($widget, $request)
|
||||
{
|
||||
$this->widget = $widget;
|
||||
$this->request = $this->getRequestInstance($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
\DB::transaction(function () {
|
||||
$this->widget->update($this->request->all());
|
||||
});
|
||||
|
||||
return $this->widget;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user