2024-03-28 18:14:30 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models\Integration;
|
|
|
|
|
|
2024-06-05 15:35:46 +02:00
|
|
|
use App\Events\Models\FormIntegrationCreated;
|
2024-03-28 18:14:30 +01:00
|
|
|
use App\Models\Forms\Form;
|
2024-06-05 15:35:46 +02:00
|
|
|
use App\Models\OAuthProvider;
|
2024-03-28 18:14:30 +01:00
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
|
|
class FormIntegration extends Model
|
|
|
|
|
{
|
|
|
|
|
use HasFactory;
|
|
|
|
|
public const STATUS_ACTIVE = 'active';
|
|
|
|
|
public const STATUS_INACTIVE = 'inactive';
|
|
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'form_id',
|
|
|
|
|
'status',
|
|
|
|
|
'integration_id',
|
|
|
|
|
'logic',
|
|
|
|
|
'data',
|
|
|
|
|
'oauth_id'
|
|
|
|
|
];
|
|
|
|
|
|
2024-06-10 16:10:14 +02:00
|
|
|
protected function casts(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'data' => 'object',
|
|
|
|
|
'logic' => 'object'
|
|
|
|
|
];
|
|
|
|
|
}
|
2024-03-28 18:14:30 +01:00
|
|
|
|
2024-06-05 15:35:46 +02:00
|
|
|
protected $dispatchesEvents = [
|
|
|
|
|
'created' => FormIntegrationCreated::class,
|
|
|
|
|
];
|
|
|
|
|
|
2024-03-28 18:14:30 +01:00
|
|
|
/**
|
|
|
|
|
* Relationships
|
|
|
|
|
*/
|
|
|
|
|
public function form()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Form::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function events()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(FormIntegrationsEvent::class, 'integration_id');
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-05 15:35:46 +02:00
|
|
|
public function provider()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(OAuthProvider::class, 'oauth_id');
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-28 18:14:30 +01:00
|
|
|
public static function getAllIntegrations()
|
|
|
|
|
{
|
|
|
|
|
return json_decode(file_get_contents(resource_path('data/forms/integrations.json')), true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function getIntegration($key)
|
|
|
|
|
{
|
|
|
|
|
return self::getAllIntegrations()[$key] ?? null;
|
|
|
|
|
}
|
|
|
|
|
}
|