diff --git a/app/Http/Controllers/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemController.php b/app/Http/Controllers/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemController.php index c5b400a9..952a9441 100644 --- a/app/Http/Controllers/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemController.php +++ b/app/Http/Controllers/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemController.php @@ -4,6 +4,9 @@ use App\BusinessLogicLayer\CrowdSourcingProject\Problem\CrowdSourcingProjectProblemManager; use App\Http\Controllers\Controller; +use App\Models\CrowdSourcingProject\Problem\CrowdSourcingProjectProblem; +use App\Models\CrowdSourcingProject\Problem\CrowdSourcingProjectProblemTranslation; +use App\ViewModels\CrowdSourcingProject\Problem\CreateEditProblem; use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Http\Request; use Illuminate\Support\Facades\Validator; @@ -33,4 +36,79 @@ public function showProblemsPage(Request $request) { abort(ResponseAlias::HTTP_NOT_FOUND); } } + + /** + * Display a listing of the resource. + */ + public function index() + { + $viewModel = []; + $viewModel['problems'] = CrowdSourcingProjectProblem::with('translations')->latest()->get(); + return view('loggedin-environment.management.problem.index', ['viewModel' => $viewModel]); + } + + /** + * Show the form for creating a new resource. + */ + public function create() + { + $newProblem = new CrowdSourcingProjectProblem(); + $newProblem->default_language_id = 6; // @todo change with lookuptable value - bookmark2 + $newProblem->setRelation('defaultTranslation', new CrowdSourcingProjectProblemTranslation()); // bookmark2 - is this an "empty" relationship? + $viewModel = new CreateEditProblem($newProblem); + return view('loggedin-environment.management.problem.create-edit.form-page'); + } + + /** + * Store a newly created resource in storage. + */ + public function store(Request $request) + { + request()->validate([ // bookmark2 + 'problem-title' => ['required'], + 'problem-description' => ['required'], + 'problem-status' => ['required'], // bookmark2 + 'problem-default-language' => ['required'], // bookmark2 + ]); + + $crowdSourcingProjectProblem = CrowdSourcingProjectProblem::create([ + 'project_id' => '3', // bookmark2 + 'user_creator_id' => '2', // bookmark2 + 'slug' => 'test-slug-1', // bookmark2 + 'status_id' => request('problem-status'), // bookmark2 + 'img_url' => 'zxcv', // bookmark2 + 'default_language_id' => request('problem-default-language'), // bookmark2 - default or generally another translation language? + ]); + + $crowdSourcingProjectProblemTranslation = $crowdSourcingProjectProblem->defaultTranslation()->create([ // bookmark2 - default or regular translation? + 'title' => request('problem-title'), + 'description' => request('problem-description'), + ]); + + return redirect()->route('problems.index'); + } + + /** + * Show the form for editing the specified resource. + */ + public function edit(string $id) + { + // + } + + /** + * Update the specified resource in storage. + */ + public function update(Request $request, string $id) + { + // + } + + /** + * Remove the specified resource from storage. + */ + public function destroy(string $id) + { + // + } } diff --git a/app/Models/CrowdSourcingProject/Problem/CrowdSourcingProjectProblem.php b/app/Models/CrowdSourcingProject/Problem/CrowdSourcingProjectProblem.php index 7182bb0f..9868472b 100644 --- a/app/Models/CrowdSourcingProject/Problem/CrowdSourcingProjectProblem.php +++ b/app/Models/CrowdSourcingProject/Problem/CrowdSourcingProjectProblem.php @@ -15,7 +15,7 @@ class CrowdSourcingProjectProblem extends Model { use SoftDeletes; protected $table = 'crowd_sourcing_project_problems'; - protected $fillable = ['id', 'project_id', 'slug', 'status_id', 'img_url', 'default_language_id']; + protected $fillable = ['id', 'project_id', 'user_creator_id', 'slug', 'status_id', 'img_url', 'default_language_id']; public function defaultTranslation(): HasOne { return $this->hasOne(CrowdSourcingProjectProblemTranslation::class, diff --git a/app/ViewModels/CrowdSourcingProject/Problem/CreateEditProblem.php b/app/ViewModels/CrowdSourcingProject/Problem/CreateEditProblem.php new file mode 100644 index 00000000..4fef6f32 --- /dev/null +++ b/app/ViewModels/CrowdSourcingProject/Problem/CreateEditProblem.php @@ -0,0 +1,13 @@ +crowdSourcingProjectProblem = $crowdSourcingProjectProblem; + } + +} \ No newline at end of file diff --git a/resources/views/loggedin-environment/management/crowdsourcing-project/create-edit/partials/basic-details.blade.php b/resources/views/loggedin-environment/management/crowdsourcing-project/create-edit/partials/basic-details.blade.php index 8c0c78f2..e8135bc2 100644 --- a/resources/views/loggedin-environment/management/crowdsourcing-project/create-edit/partials/basic-details.blade.php +++ b/resources/views/loggedin-environment/management/crowdsourcing-project/create-edit/partials/basic-details.blade.php @@ -90,7 +90,7 @@
- + + {{ $errors->first('problem-title') }} +
+
+
+ +
+ +
+
+ + {{ $errors->first('problem-description') }} +
+
+
+ +
+ +
+
+ + {{ $errors->first('problem-status') }} +
+
+
+ + + +
+ +
+
+ + {{ $errors->first('problem-default-language') }} +
+
+
+ + + + {{--
+ +
+
+ + {{ $errors->first('slug') }} +
+
+
--}} + + + + + + + + + + diff --git a/resources/views/loggedin-environment/management/problem/index.blade.php b/resources/views/loggedin-environment/management/problem/index.blade.php new file mode 100644 index 00000000..53e33d27 --- /dev/null +++ b/resources/views/loggedin-environment/management/problem/index.blade.php @@ -0,0 +1,20 @@ +@php + // var_dump($viewModel); +@endphp + +
    + @foreach ($viewModel['problems'] as $problem) +
  1. + id: {{ $problem->id }}
    + slug: {{ $problem->slug }}
    + default_language_id: {{ $problem->default_language_id }}
    + @foreach ($problem->translations as $translation) + @if ($translation->language_id === $problem->default_language_id) + default_lang_title: {{ $translation->title }}
    + default_lang_desc: {{ $translation->description }}
    + @endif + @endforeach +
  2. +
    + @endforeach +
diff --git a/routes/web.php b/routes/web.php index 3ea750f5..e446dc66 100644 --- a/routes/web.php +++ b/routes/web.php @@ -73,6 +73,7 @@ Route::post('/questionnaire/update-status', [QuestionnaireController::class, 'saveQuestionnaireStatus'])->name('questionnaire.update-status'); Route::get('/questionnaires/{questionnaire}/colors', [QuestionnaireStatisticsController::class, 'showEditStatisticsColorsPage'])->name('questionnaire.statistics-colors'); Route::post('/questionnaires/{questionnaire}/colors', [QuestionnaireStatisticsController::class, 'saveStatisticsColors'])->name('questionnaire.statistics-colors.store'); + Route::resource('problems', CrowdSourcingProjectProblemController::class)->except(['show']); }); Route::group(['middleware' => ['auth', 'can:moderate-content-by-users']], function () {