diff --git a/app/BusinessLogicLayer/CrowdSourcingProject/CrowdSourcingProjectManager.php b/app/BusinessLogicLayer/CrowdSourcingProject/CrowdSourcingProjectManager.php index eeaee7ed..08e90996 100644 --- a/app/BusinessLogicLayer/CrowdSourcingProject/CrowdSourcingProjectManager.php +++ b/app/BusinessLogicLayer/CrowdSourcingProject/CrowdSourcingProjectManager.php @@ -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; @@ -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, @@ -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; @@ -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 { @@ -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); @@ -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); @@ -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 = @@ -143,6 +143,7 @@ public function getCrowdSourcingProjectViewModelForLandingPage( return new CrowdSourcingProjectForLandingPage($project, $questionnaire, $feedbackQuestionnaire, + $projectHasPublishedProblems, $userResponse, $userFeedbackQuestionnaireResponse, $countAll, diff --git a/app/Models/CrowdSourcingProject/Problem/CrowdSourcingProjectProblem.php b/app/Models/CrowdSourcingProject/Problem/CrowdSourcingProjectProblem.php index 10950ba7..446194d8 100644 --- a/app/Models/CrowdSourcingProject/Problem/CrowdSourcingProjectProblem.php +++ b/app/Models/CrowdSourcingProject/Problem/CrowdSourcingProjectProblem.php @@ -3,7 +3,6 @@ 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; @@ -11,7 +10,7 @@ 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']; @@ -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'); } } diff --git a/app/Models/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemTranslation.php b/app/Models/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemTranslation.php index 7f8931c6..e63ee730 100644 --- a/app/Models/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemTranslation.php +++ b/app/Models/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemTranslation.php @@ -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']; diff --git a/app/Repository/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemRepository.php b/app/Repository/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemRepository.php index 125ddd23..7f73786e 100644 --- a/app/Repository/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemRepository.php +++ b/app/Repository/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemRepository.php @@ -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; @@ -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; + } } diff --git a/app/ViewModels/CrowdSourcingProject/CrowdSourcingProjectForLandingPage.php b/app/ViewModels/CrowdSourcingProject/CrowdSourcingProjectForLandingPage.php index 07b2525f..bb2fd122 100644 --- a/app/ViewModels/CrowdSourcingProject/CrowdSourcingProjectForLandingPage.php +++ b/app/ViewModels/CrowdSourcingProject/CrowdSourcingProjectForLandingPage.php @@ -9,6 +9,7 @@ class CrowdSourcingProjectForLandingPage { public $project; public $questionnaire; public $feedbackQuestionnaire; + public $projectHasPublishedProblems; public $userResponse; public $userFeedbackQuestionnaireResponse; public $totalResponses; @@ -24,6 +25,7 @@ public function __construct( $project, $questionnaire, $feedbackQuestionnaire, + $projectHasPublishedProblems, $userResponse, $userFeedbackQuestionnaireResponse, $totalResponses, @@ -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; diff --git a/database/seeders/AirQualityProjectSeeder.php b/database/seeders/AirQualityProjectSeeder.php new file mode 100644 index 00000000..ee66b506 --- /dev/null +++ b/database/seeders/AirQualityProjectSeeder.php @@ -0,0 +1,99 @@ +projectRepository = $crowdSourcingProjectRepository; + $this->projectTranslationRepository = $crowdSourcingProjectTranslationRepository; + } + + /** + * Run the database seeds. + */ + public function run(): void { + $project = [ + 'id' => 4, + 'slug' => 'air-quality-europe', + 'external_url' => 'https://www.scify.gr/site/en/', + 'img_path' => '/images/projects/air-quality-europe/logo-bg.webp', + 'logo_path' => '/images/projects/air-quality-europe/logo.webp', + 'user_creator_id' => 1, + 'language_id' => 6, + 'should_send_email_after_questionnaire_response' => 1, + 'lp_primary_color' => '#707070', + 'lp_questionnaire_image_path' => '/images/projects/air-quality-europe/logo.webp', + 'lp_show_speak_up_btn' => 1, + 'sm_featured_img_path' => '/images/projects/air-quality-europe/logo.webp', + 'display_landing_page_banner' => 1, + 'status_id' => CrowdSourcingProjectStatusLkp::PUBLISHED, + ]; + + $project_translations = [ + [ + 'id' => 6, + 'language_id' => 6, + 'project_id' => 4, + 'name' => 'Air Quality in Europe', + 'motto_title' => 'Please share with us your opinion on the air quality in Europe. Your voice matters!', + 'motto_subtitle' => 'You can make an impact! Share your opinion with us!', + 'description' => 'Lorem ipsum dolor site amet', + 'about' => '
Contribute to solving air quality problems in Athens and across Europe. Write points for and against the proposed solutions. Your contributions will be a valuable contribution to official policy to improve air quality in Athens and across Europe.
', + 'footer' => '© SCIFY ' . now()->year . ' | + Terms of use | + Privacy Policy | + Cookie Policy', + 'sm_title' => 'Air Quality in Europe', + 'sm_description' => 'Please share with us your opinion on the air quality in Europe. Your voice matters!', + 'sm_keywords' => 'Social Media Keywords', + 'questionnaire_response_email_intro_text' => '
Thanks to your contribution we are one step closer to understanding the problem.
Thank you for your time and effort.
Συμβάλλετε στην επίλυση των προβλημάτων ποιότητας του αέρα στην Αθήνα και σε όλη την Ευρώπη. Γράψτε επιχειρήματα υπέρ και κατά των προτεινόμενων λύσεων. Η συμβολή σας θα είναι πολύτιμη για τη διαμόρφωση επίσημης πολιτικής για τη βελτίωση της ποιότητας του αέρα στην Αθήνα και σε όλη την Ευρώπη.
', + 'footer' => '© SCIFY ' . now()->year . ' | + Πολιτική Ορθής Χρήσης | + Πολιτική Ιδιωτικότητας | + Πολιτική Cookies', + 'sm_title' => 'Η Ποιότητα του Αέρα στην Ευρώπη', + 'sm_description' => 'Παρακαλούμε μοιραστείτε μαζί μας την άποψή σας για την ποιότητα του αέρα στην Ευρώπη. Η φωνή σας μετράει!', + 'sm_keywords' => 'Social Media Keywords', + 'questionnaire_response_email_intro_text' => '
Χάρη στη συνεισφορά σας είμαστε ένα βήμα πιο κοντά στην κατανόηση του προβλήματος.
Σας ευχαριστούμε για το χρόνο και την προσπάθειά σας.
Thanks to your contribution we are one step closer to understanding the problem.
Thank you for your time and effort.
Contribute to solving air quality problems in Athens and across Europe. Write points for and against the proposed solutions. Your contributions will be a valuable contribution to official policy to improve air quality in Athens and across Europe.
', - 'footer' => '© SCIFY ' . now()->year . ' | - Terms of use | - Privacy Policy | - Cookie Policy', - 'sm_title' => 'Air Quality in Europe', - 'sm_description' => 'Please share with us your opinion on the air quality in Europe. Your voice matters!', - 'sm_keywords' => 'Social Media Keywords', - 'questionnaire_response_email_intro_text' => '
Thanks to your contribution we are one step closer to understanding the problem.
Thank you for your time and effort.
Συμβάλλετε στην επίλυση των προβλημάτων ποιότητας του αέρα στην Αθήνα και σε όλη την Ευρώπη. Γράψτε επιχειρήματα υπέρ και κατά των προτεινόμενων λύσεων. Η συμβολή σας θα είναι πολύτιμη για τη διαμόρφωση επίσημης πολιτικής για τη βελτίωση της ποιότητας του αέρα στην Αθήνα και σε όλη την Ευρώπη.
', - 'footer' => '© SCIFY ' . now()->year . ' | - Πολιτική Ορθής Χρήσης | - Πολιτική Ιδιωτικότητας | - Πολιτική Cookies', - 'sm_title' => 'Η Ποιότητα του Αέρα στην Ευρώπη', - 'sm_description' => 'Παρακαλούμε μοιραστείτε μαζί μας την άποψή σας για την ποιότητα του αέρα στην Ευρώπη. Η φωνή σας μετράει!', - 'sm_keywords' => 'Social Media Keywords', - 'questionnaire_response_email_intro_text' => '
Χάρη στη συνεισφορά σας είμαστε ένα βήμα πιο κοντά στην κατανόηση του προβλήματος.
Σας ευχαριστούμε για το χρόνο και την προσπάθειά σας.