Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions app/Http/Controllers/FormController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace App\Http\Controllers;

use App\Models\Form;
use Illuminate\Http\Request;

class FormController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}

/**
* Display the specified resource.
*
* @param \App\Models\Form $form
* @return \Illuminate\Http\Response
*/
public function show(Form $form)
{
//
}

/**
* Show the form for editing the specified resource.
*
* @param \App\Models\Form $form
* @return \Illuminate\Http\Response
*/
public function edit(Form $form)
{
//
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\Form $form
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Form $form)
{
//
}

/**
* Remove the specified resource from storage.
*
* @param \App\Models\Form $form
* @return \Illuminate\Http\Response
*/
public function destroy(Form $form)
{
//
}
}
85 changes: 85 additions & 0 deletions app/Http/Controllers/FormFieldController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace App\Http\Controllers;

use App\Models\FormField;
use Illuminate\Http\Request;

class FormFieldController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}

/**
* Display the specified resource.
*
* @param \App\Models\FormField $formField
* @return \Illuminate\Http\Response
*/
public function show(FormField $formField)
{
//
}

/**
* Show the form for editing the specified resource.
*
* @param \App\Models\FormField $formField
* @return \Illuminate\Http\Response
*/
public function edit(FormField $formField)
{
//
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\FormField $formField
* @return \Illuminate\Http\Response
*/
public function update(Request $request, FormField $formField)
{
//
}

/**
* Remove the specified resource from storage.
*
* @param \App\Models\FormField $formField
* @return \Illuminate\Http\Response
*/
public function destroy(FormField $formField)
{
//
}
}
29 changes: 29 additions & 0 deletions app/Http/Resources/FormFieldsResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class FileResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'type' => 'FormFields',
'attributes' => [
'slug' => $this->slug,
'label' => $this->label,
'widget' => $this->widget,
'ui_data' => $this->ui_data,
'form_id' => $this->form_id,
]
];
}
}
26 changes: 26 additions & 0 deletions app/Http/Resources/FormsResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class FileResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'type' => 'Forms',
'attributes' => [
'slug' => $this->slug,
'organization_id' => $this->organization_id,
]
];
}
}
37 changes: 37 additions & 0 deletions app/Models/Form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace App\Models;

use App\Models\Concerns\BelongsToOrganization;
use App\Models\Organization;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Form extends Model
{
use HasFactory,
BelongsToOrganization;

protected $fillable = ['slug'];

static public function build(?string $slug = null, Organization $organization): self
{
$form = self::where('slug', $slug)
->where('organization_id', $organization->id)
->first();

if (!$form)
{
$form = new self;
$form->slug = $slug;
$form->organization_id = $organization->id;
}

return $form;
}

public function formFields(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(\App\Models\FormField::class);
}
}
44 changes: 44 additions & 0 deletions app/Models/FormField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class FormField extends Model
{
use HasFactory;

const TEXT_WIDGET = 1;
const TEXT_AREA_WIDGET = 2;
const DATETIME_WIDGET = 3;
const SELECT_WIDGET = 4;
const FILE_UPDATE_WIDGET = 5;

protected $fillable = ['slug', 'label', 'widget', 'ui_data'];

protected $casts = [
'ui_data' => 'array'
];

static public function build(?string $slug = null, ?string $label = null, ?string $widget = null, ?string $form_id = null): self
{
$formField = self::where('slug', $slug)
->where('label', $label)
->where('widget', $widget)
->where('form_id', $form_id)
->first();

if (!$formField)
{
$formField = new self;
$formField->slug = $slug;
$formField->label = $label;
$formField->widget = $widget;
$formField->form_id = $form_id;
}

return $formField;
}

}
5 changes: 5 additions & 0 deletions app/Models/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public function cards(): \Illuminate\Database\Eloquent\Relations\HasMany
return $this->hasMany(\App\Models\Card::class);
}

public function forms(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(\App\Models\Form::class);
}

public function news(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(\App\Models\News::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function up()
$table->text('file_path');
$table->text('content');
$table->unsignedBigInteger('organization_id');
$table->foreign('organization_id')->references('id')->on('organizations');
$table->timestamps();
});
}
Expand Down
34 changes: 34 additions & 0 deletions database/migrations/2022_01_23_041212_create_forms_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateFormsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('forms', function (Blueprint $table) {
$table->id();
$table->string('slug');
$table->unsignedBigInteger('organization_id');
$table->foreign('organization_id')->references('id')->on('organizations');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('forms');
}
}
Loading