Skip to content

Commit

Permalink
Merge pull request #87 from scify/project_lp_cta
Browse files Browse the repository at this point in the history
Project Landing Page call-to-action button
  • Loading branch information
PavlosIsaris authored Oct 7, 2024
2 parents 0509834 + 019ccc0 commit 79ba1fc
Show file tree
Hide file tree
Showing 23 changed files with 253 additions and 70 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
99 changes: 99 additions & 0 deletions database/seeders/AirQualityProjectSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

namespace Database\Seeders;

use App\BusinessLogicLayer\lkp\CrowdSourcingProjectStatusLkp;
use App\Models\CrowdSourcingProject\CrowdSourcingProject;
use App\Models\CrowdSourcingProject\CrowdSourcingProjectTranslation;
use App\Repository\CrowdSourcingProject\CrowdSourcingProjectRepository;
use App\Repository\CrowdSourcingProject\CrowdSourcingProjectTranslationRepository;
use App\Utils\Helpers;
use Illuminate\Database\Seeder;

class AirQualityProjectSeeder extends Seeder {
protected $projectRepository;
protected $projectTranslationRepository;

public function __construct(CrowdSourcingProjectRepository $crowdSourcingProjectRepository,
CrowdSourcingProjectTranslationRepository $crowdSourcingProjectTranslationRepository) {
$this->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' => '<p>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.</p>',
'footer' => '<p style="font-size: 12px;">© SCIFY ' . now()->year . '&nbsp;|&nbsp;
<a href="https://www.scify.gr/site/en/" target="_blank" title="Read more">Terms of use</a>&nbsp;|&nbsp;
<a href="https://www.scify.gr/site/en/" target="_blank" title="Read more">Privacy Policy</a>&nbsp;|&nbsp;
<a href="https://www.scify.gr/site/en/" target="_blank" title="Read more">Cookie Policy</a>',
'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' => '<p>Thanks to your contribution we are one step closer to understanding the problem.<br></p>',
'questionnaire_response_email_outro_text' => '<p>Thank you for your time and effort.<br></p>',
],
[
'id' => 7,
'language_id' => 12,
'project_id' => 4,
'name' => 'Η Ποιότητα του Αέρα στην Ευρώπη',
'motto_title' => 'Παρακαλούμε μοιραστείτε μαζί μας την άποψή σας για την ποιότητα του αέρα στην Ευρώπη. Η φωνή σας μετράει!',
'motto_subtitle' => 'Μπορείς να κάνεις διαφορά! Μοιραστείτε την άποψή σας μαζί μας!',
'description' => 'Lorem ipsum dolor site amet',
'about' => '<p>Συμβάλλετε στην επίλυση των προβλημάτων ποιότητας του αέρα στην Αθήνα και σε όλη την Ευρώπη. Γράψτε επιχειρήματα υπέρ και κατά των προτεινόμενων λύσεων. Η συμβολή σας θα είναι πολύτιμη για τη διαμόρφωση επίσημης πολιτικής για τη βελτίωση της ποιότητας του αέρα στην Αθήνα και σε όλη την Ευρώπη.</p>',
'footer' => '<p style="font-size: 12px;">© SCIFY ' . now()->year . '&nbsp;|&nbsp;
<a href="https://www.scify.gr/site/en/" target="_blank" title="Read more">Πολιτική Ορθής Χρήσης</a>&nbsp;|&nbsp;
<a href="https://www.scify.gr/site/en/" target="_blank" title="Read more">Πολιτική Ιδιωτικότητας</a>&nbsp;|&nbsp;
<a href="https://www.scify.gr/site/en/" target="_blank" title="Read more">Πολιτική Cookies</a>',
'sm_title' => 'Η Ποιότητα του Αέρα στην Ευρώπη',
'sm_description' => 'Παρακαλούμε μοιραστείτε μαζί μας την άποψή σας για την ποιότητα του αέρα στην Ευρώπη. Η φωνή σας μετράει!',
'sm_keywords' => 'Social Media Keywords',
'questionnaire_response_email_intro_text' => '<p>Χάρη στη συνεισφορά σας είμαστε ένα βήμα πιο κοντά στην κατανόηση του προβλήματος.<br></p>',
'questionnaire_response_email_outro_text' => '<p>Σας ευχαριστούμε για το χρόνο και την προσπάθειά σας.<br></p>',
],
];

$project = $this->projectRepository->updateOrCreate(['id' => $project['id']],
Helpers::getFilteredAttributes($project, (new CrowdSourcingProject)->getFillable()));
if (app()->environment() !== 'testing') {
echo "\nAdded Project: " . $project['name'] . ' with slug: ' . $project->slug . "\n";
}

foreach ($project_translations as $project_translation) {
$this->projectTranslationRepository->updateOrCreate(['id' => $project_translation['id']],
Helpers::getFilteredAttributes($project_translation, (new CrowdSourcingProjectTranslation)->getFillable()));
if (app()->environment() !== 'testing') {
echo "\nAdded Project Translation: " . $project_translation['name'] . ' with id: ' . $project_translation['id'] . "\n";
}
}
}
}
1 change: 1 addition & 0 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function run() {
LanguagesLkpTableSeeder::class,
CrowdSourcingProjectStatusesLkpTableSeeder::class,
DefaultProjectSeeder::class,
AirQualityProjectSeeder::class,
QuestionnaireStatusesLkpTableSeeder::class,
QuestionnaireStatisticsPageVisibilityLkpSeeder::class,
MailChimpListsTableSeeder::class,
Expand Down
Loading

0 comments on commit 79ba1fc

Please sign in to comment.