Skip to content

Commit

Permalink
Add events
Browse files Browse the repository at this point in the history
  • Loading branch information
Hatim EL OUFIR committed Jul 5, 2022
1 parent f8380a9 commit 1bc63f7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to `filament-workflow-manager` will be documented in this file.

## 1.1.4 - 2022-07-05

- Add events

## 1.1.3 - 2022-07-05

- History system
Expand Down
20 changes: 18 additions & 2 deletions src/Core/WorkflowResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,33 @@ trait WorkflowResource

protected function afterSave(): void
{
$old_status = $this->record->workflow_status->workflow_status_id;
$old_status = $this->record->workflow_status->status;
$data = $this->form->getState();
$this->record->workflow_status->workflow_status_id = $data['workflow_status_id'];
$this->record->workflow_status->save();
$this->saveHistory($old_status);
$this->saveHistory($old_status->id);
if ($old_status->id !== $this->record->workflow_status->workflow_status_id) {
$this->emit('WorkflowStatusUpdated', [
'type' => 'update',
'old_status' => $old_status,
'new_status' => $this->record->workflow_status->status,
'model' => $this->record,
'user' => auth()->user()
]);
}
}

protected function afterCreate(): void
{
call_user_func($this->getModel() . '::initiate_default_status', $this->record->id);
$this->saveHistory();
$this->emit('WorkflowStatusUpdated', [
'type' => 'create',
'old_status' => null,
'new_status' => $this->record->workflow_status->workflow_status,
'model' => $this->record,
'user' => auth()->user()
]);
}

private function saveHistory(int|null $old_status = null): void
Expand Down

0 comments on commit 1bc63f7

Please sign in to comment.