Skip to content

Commit

Permalink
IP-188: all subtasks done
Browse files Browse the repository at this point in the history
  • Loading branch information
papandrk committed Nov 8, 2024
1 parent 059ad29 commit e26e5d8
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -456,4 +456,10 @@ public function getCrowdSourcingProjectsWithActiveProblems(): Collection {

return $projects;
}

public function getAllCrowdSourcingProjectsWithDefaultTranslation(): Collection {
$projects = $this->crowdSourcingProjectRepository->getAllProjectsWithDefaultTranslation();

return $projects;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,37 @@

namespace App\BusinessLogicLayer\CrowdSourcingProject\Problem;

use App\BusinessLogicLayer\CrowdSourcingProject\CrowdSourcingProjectManager;
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\Repository\LanguageRepository;
use App\ViewModels\CrowdSourcingProject\Problem\CreateEditProblem;
use App\ViewModels\CrowdSourcingProject\Problem\CrowdSourcingProjectProblemsLandingPage;

class CrowdSourcingProjectProblemManager {
protected CrowdSourcingProjectProblemRepository $crowdSourcingProjectProblemRepository;
protected CrowdSourcingProjectTranslationManager $crowdSourcingProjectTranslationManager;
protected CrowdSourcingProjectProblemTranslationManager $crowdSourcingProjectProblemTranslationManager;
protected CrowdSourcingProjectProblemStatusManager $crowdSourcingProjectProblemStatusManager;
protected LanguageRepository $languageRepository;
protected CrowdSourcingProjectManager $crowdSourcingProjectManager;

public function __construct(
CrowdSourcingProjectProblemRepository $crowdSourcingProjectProblemRepository,
CrowdSourcingProjectTranslationManager $crowdSourcingProjectTranslationManager,
CrowdSourcingProjectProblemTranslationManager $crowdSourcingProjectProblemTranslationManager
CrowdSourcingProjectProblemTranslationManager $crowdSourcingProjectProblemTranslationManager,
CrowdSourcingProjectProblemStatusManager $crowdSourcingProjectProblemStatusManager,
LanguageRepository $languageRepository,
CrowdSourcingProjectManager $crowdSourcingProjectManager
) {
$this->crowdSourcingProjectProblemRepository = $crowdSourcingProjectProblemRepository;
$this->crowdSourcingProjectTranslationManager = $crowdSourcingProjectTranslationManager;
$this->crowdSourcingProjectProblemTranslationManager = $crowdSourcingProjectProblemTranslationManager;
$this->crowdSourcingProjectProblemStatusManager = $crowdSourcingProjectProblemStatusManager;
$this->languageRepository = $languageRepository;
$this->crowdSourcingProjectManager = $crowdSourcingProjectManager;
}

public function getCrowdSourcingProjectProblemsLandingPageViewModel(string $crowdSouringProjectSlug): CrowdSourcingProjectProblemsLandingPage {
Expand All @@ -43,37 +54,24 @@ public function getCreateEditProblemViewModel(?int $id = null): CreateEditProble
// }

// $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();
$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?
$translations = $this->crowdSourcingProjectProblemTranslationManager->getTranslationsForProblem($problem);

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

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

$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?
$projects = $this->crowdSourcingProjectManager->getAllCrowdSourcingProjectsWithDefaultTranslation();

return new CreateEditProblem(
$problem
$problem,
$translations,
$statusesLkp,
$languagesLkp,
$projects
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\BusinessLogicLayer\CrowdSourcingProject\Problem;

use App\Repository\CrowdSourcingProject\Problem\CrowdSourcingProjectProblemStatusLkpRepository;

class CrowdSourcingProjectProblemStatusManager {
protected $crowdSourcingProjectProblemStatusLkpRepository;

public function __construct(CrowdSourcingProjectProblemStatusLkpRepository $crowdSourcingProjectProblemStatusLkpRepository) {
$this->crowdSourcingProjectProblemStatusLkpRepository = $crowdSourcingProjectProblemStatusLkpRepository;
}

public function getAllCrowdSourcingProjectProblemStatusesLkp() {
return $this->crowdSourcingProjectProblemStatusLkpRepository->all();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Models\CrowdSourcingProject\Problem\CrowdSourcingProjectProblemTranslation;
use App\Repository\CrowdSourcingProject\Problem\CrowdSourcingProjectProblemTranslationRepository;
use App\Repository\LanguageRepository;
use Illuminate\Support\Collection;

class CrowdSourcingProjectProblemTranslationManager {
protected $crowdSourcingProjectProblemTranslationRepository;
Expand All @@ -29,4 +30,12 @@ public function getFieldsTranslationForProjectProblem(CrowdSourcingProjectProble

return $fieldsTranslation ?: $projectProblem->defaultTranslation;
}

public function getTranslationsForProblem(CrowdSourcingProjectProblem $problem): Collection {
if (!$problem->id) {
return new Collection;
}

return $this->crowdSourcingProjectProblemTranslationRepository->allWhere(['problem_id' => $problem->id]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
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\Support\Str;
use Illuminate\View\View;
use Symfony\Component\HttpFoundation\Response as ResponseAlias;

Expand Down Expand Up @@ -68,7 +70,6 @@ public function store(Request $request) {
'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'],
]);

try {
Expand All @@ -78,8 +79,8 @@ public function store(Request $request) {

$crowdSourcingProjectProblem = CrowdSourcingProjectProblem::create([
'project_id' => $request->input('problem-owner-project'),
'user_creator_id' => $request->input('problem-creator-user-id'),
'slug' => $request->input('problem-slug'),
'user_creator_id' => Auth::user()->id,
'slug' => Str::slug($request->input('problem-title')),
'status_id' => $request->input('problem-status'),
'img_url' => $imgPath,
'default_language_id' => $request->input('problem-default-language'), // bookmark2 - default or generally another translation language?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,14 @@ public function getActiveProjectsWithAtLeastOnePublishedProblemWithStatus(

return $builder->get();
}

public function getAllProjectsWithDefaultTranslation($additionalRelationships = []): Collection {
$builder = CrowdSourcingProject::where(['status_id' => CrowdSourcingProjectStatusLkp::PUBLISHED]);

if (count($additionalRelationships)) {
$builder = $builder->with($additionalRelationships);
}

return $builder->get();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace App\Repository\CrowdSourcingProject\Problem;

use App\Models\CrowdSourcingProject\Problem\CrowdSourcingProjectProblemStatusLkp;
use App\Repository\Repository;

class CrowdSourcingProjectProblemStatusLkpRepository extends Repository {
/**
* {@inheritDoc}
*/
public function getModelClassName() {
return CrowdSourcingProjectProblemStatusLkp::class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,40 @@
namespace App\ViewModels\CrowdSourcingProject\Problem;

use App\Models\CrowdSourcingProject\Problem\CrowdSourcingProjectProblem;
use App\Models\Language;
use Illuminate\Support\Collection;

class CreateEditProblem {
public CrowdSourcingProjectProblem $problem;
public $translations;
public $problemStatusesLkp;
public $languagesLkp;
public $defaultLanguageCode = 'en';
public $projects;

public function __construct(CrowdSourcingProjectProblem $crowdSourcingProjectProblem) {
public function __construct(
CrowdSourcingProjectProblem $crowdSourcingProjectProblem,
Collection $translations,
Collection $problemStatusesLkp,
Collection $languagesLkp,
Collection $projects
) {
$this->problem = $crowdSourcingProjectProblem;
$this->translations = $translations;
$this->problemStatusesLkp = $problemStatusesLkp;
$this->languagesLkp = $languagesLkp;
$this->projects = $projects;
}

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

public function shouldLanguageBeSelected(Language $language): bool {
if ($this->problem->default_language_id) {
return $this->problem->default_language_id == $language->id;
}

return $language->language_code === $this->defaultLanguageCode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<div class="container-fluid p-0">
<div class="row p-0">
<div class="col-lg-2 col-md-3 col-sm-12">
<input class="btn btn-primary btn-lg w-100 mb-3"
<input class="btn btn-primary btn-slim w-100 mb-3"
id="submit-form"
type="submit" value="Save">
</div>
Expand Down
Loading

0 comments on commit e26e5d8

Please sign in to comment.