Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
PavlosIsaris committed Oct 30, 2024
2 parents 3065cc8 + 964813b commit ef8a431
Show file tree
Hide file tree
Showing 8 changed files with 355 additions and 222 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
namespace App\BusinessLogicLayer\CrowdSourcingProject\Problem;

use App\BusinessLogicLayer\CrowdSourcingProject\CrowdSourcingProjectTranslationManager;
use App\Models\CrowdSourcingProject\Problem\CrowdSourcingProjectProblem;
use App\Models\CrowdSourcingProject\Problem\CrowdSourcingProjectProblemTranslation;
use App\Repository\CrowdSourcingProject\Problem\CrowdSourcingProjectProblemRepository;
use App\ViewModels\CrowdSourcingProject\Problem\CreateEditProblem;
use App\ViewModels\CrowdSourcingProject\Problem\CrowdSourcingProjectProblemsLandingPage;

class CrowdSourcingProjectProblemManager {
Expand Down Expand Up @@ -31,4 +34,46 @@ public function getCrowdSourcingProjectProblemsLandingPageViewModel(string $crow

return new CrowdSourcingProjectProblemsLandingPage($crowdSourcingProject, $crowdSourcingProjectProblems);
}

public function getCreateEditProblemViewModel(?int $id = null): CreateEditProblem {
// if ($id) {
// $project = $this->getCrowdSourcingProject($id);
// } else {
// $project = $this->crowdSourcingProjectRepository->getModelInstance();
// }

// $project = $this->populateInitialValuesForProjectIfNotSet($project);
// $project->colors = $this->crowdSourcingProjectColorsManager->getColorsForCrowdSourcingProjectOrDefault($project->id);
// $statusesLkp = $this->crowdSourcingProjectStatusManager->getAllCrowdSourcingProjectStatusesLkp();

// $contributorBadge = new ContributorBadge(1, true);
// $contributorBadgeVM = new GamificationBadgeVM($contributorBadge);
// $questionnaire = $this->questionnaireRepository->getModelInstance();


// $templateForNotification = (new QuestionnaireResponded(
// $questionnaire->defaultFieldsTranslation,
// $contributorBadge,
// $contributorBadgeVM,
// $project->defaultTranslation,
// app()->getLocale()
// ))->toMail(null)->render();
// $translations = $this->crowdSourcingProjectTranslationManager->getTranslationsForProject($project);

// return new CreateEditCrowdSourcingProject(
// $project,
// $translations,
// $statusesLkp,
// $this->languageRepository->all(),
// $templateForNotification
// );

$problem = new CrowdSourcingProjectProblem;
$problem->default_language_id = 6; // @todo change with lookuptable value - bookmark2
$problem->setRelation('defaultTranslation', new CrowdSourcingProjectProblemTranslation); // bookmark2 - is this an "empty" relationship?
return new CreateEditProblem(
$problem
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
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 App\Utils\FileUploader;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Validator;
use Illuminate\View\View;
use Symfony\Component\HttpFoundation\Response as ResponseAlias;

class CrowdSourcingProjectProblemController extends Controller {
Expand All @@ -19,7 +20,7 @@ public function __construct(CrowdSourcingProjectProblemManager $crowdSourcingPro
$this->crowdSourcingProjectProblemManager = $crowdSourcingProjectProblemManager;
}

public function showProblemsPage(Request $request) {
public function showProblemsPage(Request $request): View {
$validator = Validator::make([
'project_slug' => $request->project_slug,
], [
Expand All @@ -40,7 +41,7 @@ public function showProblemsPage(Request $request) {
/**
* Display a listing of the resource.
*/
public function index() {
public function index(): View {
$viewModel = [];
$viewModel['problems'] = CrowdSourcingProjectProblem::with('translations')->latest()->get();

Expand All @@ -50,49 +51,61 @@ public function index() {
/**
* 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');
public function create(): View {
$viewModel = $this->crowdSourcingProjectProblemManager->getCreateEditProblemViewModel();
return view('loggedin-environment.management.problem.create-edit.form-page', ['viewModel' => $viewModel]);
}

/**
* Store a newly created resource in storage.
*/
public function store(Request $request) {
$validated = $request->validate([ // bookmark2
'problem-title' => ['required'],
'problem-description' => ['required'],
'problem-title' => ['required', 'string', 'max:100'],
'problem-description' => ['required', 'string', 'max:200'],
'problem-status' => ['required'], // bookmark2
'problem-default-language' => ['required'], // bookmark2
'problem-slug' => ['required', 'unique:crowd_sourcing_project_problems,slug'],
'problem-image' => 'nullable|image|mimes:jpeg,png,jpg|max:2048',
'problem-owner-project' => ['required'],
'problem-creator-user-id' => ['required'],
]);

$crowdSourcingProjectProblem = CrowdSourcingProjectProblem::create([
'project_id' => '3', // bookmark2
'user_creator_id' => '2', // bookmark2
'slug' => $request->input('problem-slug'),
'status_id' => $request->input('problem-status'),
'img_url' => 'zxcv', // bookmark2
'default_language_id' => $request->input('problem-default-language'), // bookmark2 - default or generally another translation language?
]);

$crowdSourcingProjectProblemTranslation = $crowdSourcingProjectProblem->defaultTranslation()->create([ // bookmark2 - default or regular translation?
'title' => $request->input('problem-title'),
'description' => $request->input('problem-description'),
]);

return redirect()->route('problems.index');
try {
if (isset($request['problem-image']) && $request['problem-image']->isValid()) {
$imgPath = FileUploader::uploadAndGetPath($request['problem-image'], 'problem_image');
}

$crowdSourcingProjectProblem = CrowdSourcingProjectProblem::create([
'project_id' => $request->input('problem-owner-project'),
'user_creator_id' => $request->input('problem-creator-user-id'),
'slug' => $request->input('problem-slug'),
'status_id' => $request->input('problem-status'),
'img_url' => $imgPath,
'default_language_id' => $request->input('problem-default-language'), // bookmark2 - default or generally another translation language?
]);

$crowdSourcingProjectProblemTranslation = $crowdSourcingProjectProblem->defaultTranslation()->create([ // bookmark2 - default or regular translation?
'title' => $request->input('problem-title'),
'description' => $request->input('problem-description'),
]);

session()->flash('flash_message_success', 'Problem Created Successfully.');

return redirect()->route('problems.index');
} catch (\Exception $e) {
session()->flash('flash_message_error', 'Error: ' . $e->getCode() . ' ' . $e->getMessage());

return back()->withInput();
}
}

/**
* Show the form for editing the specified resource.
*/
public function edit(string $id) {
//
public function edit(int $id): View {
$viewModel = $this->crowdSourcingProjectProblemManager->getCreateEditProblemViewModel($id);
return view('loggedin-environment.management.problem.create-edit.form-page', ['viewModel' => $viewModel]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AuthServiceProvider extends ServiceProvider {
* @var array
*/
protected $policies = [
'App\Model' => 'App\Policies\ModelPolicy',
// 'App\Models\Model' => 'App\Policies\ModelPolicy', // example
];

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
use App\Models\CrowdSourcingProject\Problem\CrowdSourcingProjectProblem;

class CreateEditProblem {
public CrowdSourcingProjectProblem $crowdSourcingProjectProblem;
public CrowdSourcingProjectProblem $problem;

public function __construct(CrowdSourcingProjectProblem $crowdSourcingProjectProblem) {
$this->crowdSourcingProjectProblem = $crowdSourcingProjectProblem;
$this->problem = $crowdSourcingProjectProblem;
}

public function isEditMode(): bool {
return $this->problem->id !== null;
}
}
Empty file.
Loading

0 comments on commit ef8a431

Please sign in to comment.