-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f30cb12
commit 6c55700
Showing
569 changed files
with
25,545 additions
and
9,627 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
namespace Litepie\Actions; | ||
|
||
use Illuminate\Support\Facades\Auth; | ||
|
||
class Action | ||
{ | ||
protected $name = null; | ||
protected $roles = null; | ||
protected $type = []; | ||
protected $form = []; | ||
|
||
public function __construct($name = null) | ||
{ | ||
$this->name = $name; | ||
} | ||
|
||
public function roles(array $roles = []) | ||
{ | ||
if (!empty($roles)) { | ||
$this->roles = $roles; | ||
} | ||
return $this->roles; | ||
} | ||
|
||
public function name(string $name = null): string | ||
{ | ||
if (!empty($name)) { | ||
$this->name = $name; | ||
} | ||
return $this->name; | ||
} | ||
|
||
public function type(array $types = []) | ||
{ | ||
if (is_array($types)) { | ||
foreach ($types as $type) { | ||
$this->type[] = ActionType::tryFrom($type); | ||
} | ||
} | ||
return $this->type; | ||
} | ||
|
||
public function form(array $form = null) | ||
{ | ||
if (!empty($form)) { | ||
return $this->form = $form; | ||
} | ||
|
||
if (empty($this->form)) { | ||
return null; | ||
} | ||
foreach ($this->form as $key => $val) { | ||
$this->form[$key]['label'] = trans($val['label']); | ||
$this->form[$key]['placeholder'] = trans($val['placeholder']); | ||
} | ||
|
||
return $this->form; | ||
} | ||
|
||
public function authorized() | ||
{ | ||
if (!isset($this->roles)) { | ||
return true; | ||
} | ||
|
||
if (isset($this->roles['permission']) | ||
&& Auth::user()->can($this->roles['permission'])) { | ||
return true; | ||
} | ||
|
||
if (isset($this->roles['user']) | ||
&& Auth::user()->hasRole($this->roles['user'])) { | ||
return true; | ||
} | ||
|
||
if (isset($this->roles['team']) | ||
&& Auth::user()->teams()->hasRole($this->roles['team'])) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public function isType($type = ActionType::List) | ||
{ | ||
if (in_array($type, $this->type())) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace Litepie\Actions; | ||
|
||
use Lorisleiva\Actions\ActionRequest as BaseActionRequest; | ||
|
||
class ActionRequest extends BaseActionRequest | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
namespace Litepie\Actions; | ||
|
||
use Illuminate\Support\Arr; | ||
|
||
enum ActionType: string | ||
{ | ||
case List = 'List'; | ||
case Details = 'Details'; | ||
|
||
public function values(): array | ||
{ | ||
return array_column(self::cases(), 'value'); | ||
} | ||
|
||
public function names(): array | ||
{ | ||
return array_column(self::cases(), 'name'); | ||
} | ||
} |
Oops, something went wrong.