You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
1.8 KiB
83 lines
1.8 KiB
<?php
|
|
|
|
namespace App\Utilities;
|
|
|
|
use ArrayAccess;
|
|
use App\Models\Notifiable;
|
|
use Illuminate\Support\Arr;
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Support\Collection;
|
|
use Illuminate\Support\Stringable;
|
|
|
|
class Payload implements ArrayAccess
|
|
{
|
|
public array $payload;
|
|
|
|
public function __construct(array $payload)
|
|
{
|
|
$this->payload = $payload;
|
|
}
|
|
|
|
public function getActor(): ?Notifiable
|
|
{
|
|
return new Notifiable(Arr::get($this->payload, "info.users." . $this['auth']));
|
|
}
|
|
|
|
public function getSubject(): ?Notifiable
|
|
{
|
|
return new Notifiable(
|
|
Arr::get($this->payload, "info.users." . $this['data']['original']['user_id'])
|
|
);
|
|
}
|
|
|
|
public function getOwners(): Collection
|
|
{
|
|
return new Collection(
|
|
Arr::where($this->payload['info']['users'], fn ($user) => $user['level'] === 4)
|
|
);
|
|
}
|
|
|
|
public function getTableName(): ?Stringable
|
|
{
|
|
return Str::of(Arr::get($this->payload, "data.table_name"));
|
|
}
|
|
|
|
public function getActId()
|
|
{
|
|
return Arr::get($this->payload, "data.crud_id");
|
|
}
|
|
|
|
public function getTitle()
|
|
{
|
|
return Arr::get($this->payload, "info.name");
|
|
}
|
|
|
|
public function isPivot(): bool
|
|
{
|
|
return $this->getTableName()->contains("_");
|
|
}
|
|
|
|
public function offsetExists($key)
|
|
{
|
|
return isset($this->payload[$key]);
|
|
}
|
|
|
|
public function offsetGet($key)
|
|
{
|
|
return $this->payload[$key];
|
|
}
|
|
|
|
public function offsetSet($key, $value)
|
|
{
|
|
if (is_null($key)) {
|
|
$this->payload[] = $value;
|
|
} else {
|
|
$this->payload[$key] = $value;
|
|
}
|
|
}
|
|
|
|
public function offsetUnset($key)
|
|
{
|
|
unset($this->payload[$key]);
|
|
}
|
|
}
|