Skip to content

Commit

Permalink
Added the call-to-action button for problems, in the project landing …
Browse files Browse the repository at this point in the history
…page
  • Loading branch information
PavlosIsaris committed Oct 7, 2024
1 parent dd66b4a commit 178402a
Show file tree
Hide file tree
Showing 20 changed files with 153 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Notifications\QuestionnaireResponded;
use App\Repository\CrowdSourcingProject\CrowdSourcingProjectRepository;
use App\Repository\CrowdSourcingProject\CrowdSourcingProjectStatusHistoryRepository;
use App\Repository\CrowdSourcingProject\Problem\CrowdSourcingProjectProblemRepository;
use App\Repository\LanguageRepository;
use App\Repository\Questionnaire\QuestionnaireRepository;
use App\Repository\Questionnaire\Responses\QuestionnaireResponseRepository;
Expand Down Expand Up @@ -41,6 +42,7 @@ class CrowdSourcingProjectManager {
protected CrowdSourcingProjectColorsManager $crowdSourcingProjectColorsManager;
protected QuestionnaireResponseRepository $questionnaireResponseRepository;
protected CrowdSourcingProjectTranslationManager $crowdSourcingProjectTranslationManager;
protected CrowdSourcingProjectProblemRepository $crowdSourcingProjectProblemRepository;

public function __construct(CrowdSourcingProjectRepository $crowdSourcingProjectRepository,
QuestionnaireRepository $questionnaireRepository,
Expand All @@ -51,7 +53,8 @@ public function __construct(CrowdSourcingProjectRepository $crowdSourcingProject
LanguageRepository $languageRepository,
CrowdSourcingProjectColorsManager $crowdSourcingProjectColorsManager,
QuestionnaireResponseRepository $questionnaireResponseRepository,
CrowdSourcingProjectTranslationManager $crowdSourcingProjectTranslationManager) {
CrowdSourcingProjectTranslationManager $crowdSourcingProjectTranslationManager,
CrowdSourcingProjectProblemRepository $crowdSourcingProjectProblemRepository) {
$this->crowdSourcingProjectRepository = $crowdSourcingProjectRepository;
$this->questionnaireRepository = $questionnaireRepository;
$this->crowdSourcingProjectStatusManager = $crowdSourcingProjectStatusManager;
Expand All @@ -62,6 +65,7 @@ public function __construct(CrowdSourcingProjectRepository $crowdSourcingProject
$this->crowdSourcingProjectColorsManager = $crowdSourcingProjectColorsManager;
$this->questionnaireResponseRepository = $questionnaireResponseRepository;
$this->crowdSourcingProjectTranslationManager = $crowdSourcingProjectTranslationManager;
$this->crowdSourcingProjectProblemRepository = $crowdSourcingProjectProblemRepository;
}

public function getCrowdSourcingProjectsForHomePage(): Collection {
Expand Down Expand Up @@ -94,15 +98,7 @@ public function getCrowdSourcingProjectBySlug($project_slug, $withRelationships
public function getCrowdSourcingProjectViewModelForLandingPage(
$questionnaireIdRequestedInTheURL,
$project_slug): CrowdSourcingProjectForLandingPage {
$userId = null;

// if the user is logged in, get the user id
if (Auth::check()) {
$userId = Auth::id();
} // else, check if the user is anonymous (by checking the cookie) and get the user id
elseif (isset($_COOKIE[UserManager::$USER_COOKIE_KEY]) && intval($_COOKIE[UserManager::$USER_COOKIE_KEY])) {
$userId = intval($_COOKIE[UserManager::$USER_COOKIE_KEY]);
}
$userId = Auth::id() ?? intval($_COOKIE[UserManager::$USER_COOKIE_KEY] ?? 0);

$project = $this->getCrowdSourcingProjectBySlug($project_slug);

Expand All @@ -122,6 +118,7 @@ public function getCrowdSourcingProjectViewModelForLandingPage(
$shareUrlForFacebook = '';
$shareUrlForTwitter = '';
$countAll = 0;
$projectHasPublishedProblems = false;
if ($questionnaire) {
$countAll = $this->questionnaireRepository->countAllResponsesForQuestionnaire($questionnaire->id);
$questionnaireGoalVM = $this->questionnaireGoalManager->getQuestionnaireGoalViewModel($questionnaire, $countAll);
Expand All @@ -131,6 +128,9 @@ public function getCrowdSourcingProjectViewModelForLandingPage(
$shareButtonsModel = new QuestionnaireSocialShareButtons($questionnaire, $idOfUserThatCanShareTheQuestionnaire);
$shareUrlForFacebook = $shareButtonsModel->getSocialShareURL($project, 'facebook');
$shareUrlForTwitter = $shareButtonsModel->getSocialShareURL($project, 'twitter');
} else {
// if there is no questionnaire, we need to check if this project has published problems
$projectHasPublishedProblems = $this->crowdSourcingProjectProblemRepository->projectHasPublishedProblems($project->id);
}
if ($feedbackQuestionnaire) {
$userFeedbackQuestionnaireResponse =
Expand All @@ -143,6 +143,7 @@ public function getCrowdSourcingProjectViewModelForLandingPage(
return new CrowdSourcingProjectForLandingPage($project,
$questionnaire,
$feedbackQuestionnaire,
$projectHasPublishedProblems,
$userResponse,
$userFeedbackQuestionnaireResponse,
$countAll,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
namespace App\Models\CrowdSourcingProject\Problem;

use Awobaz\Compoships\Compoships;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;

class CrowdSourcingProjectProblem extends Model {
use Compoships;
use HasFactory, SoftDeletes;
use SoftDeletes;

protected $table = 'crowd_sourcing_project_problems';
protected $fillable = ['id', 'project_id', 'slug', 'status_id', 'img_url', 'default_language_id'];
Expand All @@ -22,6 +21,6 @@ public function defaultTranslation(): HasOne {
}

public function translations(): HasMany {
return $this->hasMany(CrowdSourcingProjectProblemTranslation::class, 'project_id', 'id');
return $this->hasMany(CrowdSourcingProjectProblemTranslation::class, 'problem_id', 'id');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
use App\Models\CompositeKeysModel;
use App\Models\Language;
use Awobaz\Compoships\Compoships;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class CrowdSourcingProjectProblemTranslation extends CompositeKeysModel {
use Compoships;
use HasFactory;

protected $table = 'crowd_sourcing_project_problem_translations';
protected $fillable = ['problem_id', 'language_id', 'title', 'description'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Repository\CrowdSourcingProject\Problem;

use App\BusinessLogicLayer\lkp\CrowdSourcingProjectProblemStatusLkp;
use App\Models\CrowdSourcingProject\CrowdSourcingProject;
use App\Models\CrowdSourcingProject\Problem\CrowdSourcingProjectProblem;
use App\Repository\Repository;
Expand All @@ -17,4 +18,13 @@ public function getModelClassName() {
public function getProjectWithProblemsByProjectSlug(string $project_slug): CrowdSourcingProject {
return CrowdSourcingProject::where('slug', $project_slug)->with(['problems'])->first();
}

public function projectHasPublishedProblems(int $project_id): bool {
$hasPublishedProblemsWithTranslations = CrowdSourcingProjectProblem::where('project_id', $project_id)
->where('status_id', CrowdSourcingProjectProblemStatusLkp::PUBLISHED)
->whereHas('translations')
->exists();

return $hasPublishedProblemsWithTranslations;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class CrowdSourcingProjectForLandingPage {
public $project;
public $questionnaire;
public $feedbackQuestionnaire;
public $projectHasPublishedProblems;
public $userResponse;
public $userFeedbackQuestionnaireResponse;
public $totalResponses;
Expand All @@ -24,6 +25,7 @@ public function __construct(
$project,
$questionnaire,
$feedbackQuestionnaire,
$projectHasPublishedProblems,
$userResponse,
$userFeedbackQuestionnaireResponse,
$totalResponses,
Expand All @@ -35,6 +37,7 @@ public function __construct(
$this->project = $project;
$this->questionnaire = $questionnaire;
$this->feedbackQuestionnaire = $feedbackQuestionnaire;
$this->projectHasPublishedProblems = $projectHasPublishedProblems;
$this->userResponse = $userResponse;
$this->userFeedbackQuestionnaireResponse = $userFeedbackQuestionnaireResponse;
$this->totalResponses = $totalResponses;
Expand Down
10 changes: 10 additions & 0 deletions resources/lang/bg/project-problems.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

return [
'back' => 'Назад',
'the_topic' => 'Темата:',
'list_of_problems' => 'Списък с проблеми',
'see_all_problems' => 'Виж всички проблеми',
'solutions_for' => 'Решения за',
'project_landing_page_problems_action_button' => 'Виж всички проблеми',
];
10 changes: 10 additions & 0 deletions resources/lang/de/project-problems.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

return [
'back' => 'Zurück',
'the_topic' => 'Das Thema:',
'list_of_problems' => 'Liste der Probleme',
'see_all_problems' => 'Alle Probleme anzeigen',
'solutions_for' => 'Lösungen für',
'project_landing_page_problems_action_button' => 'Alle Probleme anzeigen',
];
1 change: 1 addition & 0 deletions resources/lang/el/project-problems.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
'list_of_problems' => 'Λίστα Προβλημάτων',
'see_all_problems' => 'Δες όλα τα προβλήματα',
'solutions_for' => 'Λύσεις για',
'project_landing_page_problems_action_button' => 'Δες όλα τα προβλήματα',
];
1 change: 1 addition & 0 deletions resources/lang/en/project-problems.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
'list_of_problems' => 'List of Problems',
'see_all_problems' => 'See all problems',
'solutions_for' => 'Solutions for',
'project_landing_page_problems_action_button' => 'See all problems',
];
10 changes: 10 additions & 0 deletions resources/lang/es/project-problems.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

return [
'back' => 'Atrás',
'the_topic' => 'El tema:',
'list_of_problems' => 'Lista de problemas',
'see_all_problems' => 'Ver todos los problemas',
'solutions_for' => 'Soluciones para',
'project_landing_page_problems_action_button' => 'Ver todos los problemas',
];
10 changes: 10 additions & 0 deletions resources/lang/et/project-problems.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

return [
'back' => 'Tagasi',
'the_topic' => 'Teema:',
'list_of_problems' => 'Probleemide loetelu',
'see_all_problems' => 'Vaata kõiki probleeme',
'solutions_for' => 'Lahendused',
'project_landing_page_problems_action_button' => 'Vaata kõiki probleeme',
];
10 changes: 10 additions & 0 deletions resources/lang/fr/project-problems.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

return [
'back' => 'Retour',
'the_topic' => 'Le sujet:',
'list_of_problems' => 'Liste des problèmes',
'see_all_problems' => 'Voir tous les problèmes',
'solutions_for' => 'Solutions pour',
'project_landing_page_problems_action_button' => 'Voir tous les problèmes',
];
10 changes: 10 additions & 0 deletions resources/lang/hu/project-problems.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

return [
'back' => 'Vissza',
'the_topic' => 'A téma:',
'list_of_problems' => 'Problémák listája',
'see_all_problems' => 'Összes probléma megtekintése',
'solutions_for' => 'Megoldások',
'project_landing_page_problems_action_button' => 'Összes probléma megtekintése',
];
10 changes: 10 additions & 0 deletions resources/lang/it/project-problems.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

return [
'back' => 'Indietro',
'the_topic' => 'L\'argomento:',
'list_of_problems' => 'Elenco dei problemi',
'see_all_problems' => 'Vedi tutti i problemi',
'solutions_for' => 'Soluzioni per',
'project_landing_page_problems_action_button' => 'Vedi tutti i problemi',
];
10 changes: 10 additions & 0 deletions resources/lang/lv/project-problems.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

return [
'back' => 'Atpakaļ',
'the_topic' => 'Tēma:',
'list_of_problems' => 'Problēmu saraksts',
'see_all_problems' => 'Skatīt visas problēmas',
'solutions_for' => 'Risinājumi',
'project_landing_page_problems_action_button' => 'Skatīt visas problēmas',
];
10 changes: 10 additions & 0 deletions resources/lang/nl/project-problems.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

return [
'back' => 'Terug',
'the_topic' => 'Het onderwerp:',
'list_of_problems' => 'Lijst met problemen',
'see_all_problems' => 'Bekijk alle problemen',
'solutions_for' => 'Oplossingen voor',
'project_landing_page_problems_action_button' => 'Bekijk alle problemen',
];
10 changes: 10 additions & 0 deletions resources/lang/pt/project-problems.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

return [
'back' => 'Voltar',
'the_topic' => 'O tópico:',
'list_of_problems' => 'Lista de problemas',
'see_all_problems' => 'Ver todos os problemas',
'solutions_for' => 'Soluções para',
'project_landing_page_problems_action_button' => 'Ver todos os problemas',
];
10 changes: 10 additions & 0 deletions resources/lang/sk/project-problems.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

return [
'back' => 'Späť',
'the_topic' => 'Téma:',
'list_of_problems' => 'Zoznam problémov',
'see_all_problems' => 'Zobraziť všetky problémy',
'solutions_for' => 'Riešenia pre',
'project_landing_page_problems_action_button' => 'Zobraziť všetky problémy',
];
10 changes: 10 additions & 0 deletions resources/lang/sr/project-problems.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

return [
'back' => 'Nazad',
'the_topic' => 'Tema:',
'list_of_problems' => 'Lista problema',
'see_all_problems' => 'Pogledaj sve probleme',
'solutions_for' => 'Rešenja za',
'project_landing_page_problems_action_button' => 'Pogledaj sve probleme',
];
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,12 @@ class="btn btn-primary w-100 respond-questionnaire call-to-action
</a>
</div>
@endif
@elseif($viewModel->projectHasPublishedProblems)
<a href="{{ route('project.problems-page', ['project_slug' => $viewModel->project->slug]) }}"
class="btn btn-primary w-100 call-to-action">
{{__("project-problems.project_landing_page_problems_action_button")}} <i
class="fas fa-arrow-right"></i></a>
@else
{{-- PROJECT DOES NOT HAVE AN ACTIVE QUESTIONNAIRE --}}
@include('crowdsourcing-project.partials.external-url')
@endif
</div>
Expand Down

0 comments on commit 178402a

Please sign in to comment.