Files
opnform-host-nginx/app/Models/Integration/FormIntegration.php
Boris Lepikhin 24d33a9ebb Google Sheet - OAuth "client" powered integrations (#415)
* fix `helpers.php`

* fix `.eslintrc.cjs`

* spreadsheet manager

* fetch providers. set `oauth_id` for integrations

* create spreadsheet on integration create event

* connect OAuth accounts

* display actions. connect account if missing

* cleanup

* handle form field change

* map integration data object to `SpreadsheetData`

* validate request

* wip

* redirect to integrations page

* fix refresh token

* add helper text

* add extra integration info

* refactor

* refresh google token

* fix validation

* add tests

* Fix linting issue

* Update composer lock file

---------

Co-authored-by: Julien Nahum <julien@nahum.net>
2024-06-05 15:35:46 +02:00

63 lines
1.3 KiB
PHP

<?php
namespace App\Models\Integration;
use App\Events\Models\FormIntegrationCreated;
use App\Models\Forms\Form;
use App\Models\OAuthProvider;
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'
];
protected $casts = [
'data' => 'object',
'logic' => 'object'
];
protected $dispatchesEvents = [
'created' => FormIntegrationCreated::class,
];
/**
* Relationships
*/
public function form()
{
return $this->belongsTo(Form::class);
}
public function events()
{
return $this->hasMany(FormIntegrationsEvent::class, 'integration_id');
}
public function provider()
{
return $this->belongsTo(OAuthProvider::class, 'oauth_id');
}
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;
}
}