Skip to content

Commit

Permalink
feat: engagements i've joined page
Browse files Browse the repository at this point in the history
  • Loading branch information
jobara committed Mar 20, 2024
1 parent bdecd16 commit b4a973a
Show file tree
Hide file tree
Showing 16 changed files with 782 additions and 39 deletions.
107 changes: 107 additions & 0 deletions app/Http/Controllers/UserEngagementsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

namespace App\Http\Controllers;

use App\Enums\ProjectInvolvement;
use App\Enums\UserContext;
use App\Models\User;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Auth;

class UserEngagementsController extends Controller
{
public function show(): Response|View|RedirectResponse
{
$user = Auth::user();

if ($user->context === UserContext::Organization->value && ! $user->organization) {
return redirect(localized_route('organizations.show-type-selection'));
}

if ($this->isParticipant($user)) {
$section = ProjectInvolvement::Participating->value;
$activeEngagements = $user->{$user->context}->engagements()->active()->get();
$completeEngagements = $user->{$user->context}->engagements()->complete()->get();
} elseif ($this->isConnector($user)) {
$section = ProjectInvolvement::Contracted->value;
$activeEngagements = $user->{$user->context}->connectingEngagements()->active()->get();
$completeEngagements = $user->{$user->context}->connectingEngagements()->complete()->get();
} else {
abort(404);
}

return view('engagements.joined', [
'section' => $section ?? '',
'showParticipating' => $this->isParticipant($user),
'showConnecting' => $this->isConnector($user),
'activeEngagements' => $activeEngagements ?? [],
'completeEngagements' => $completeEngagements ?? [],
]);
}

public function showContracted(): Response|View|RedirectResponse
{
$user = Auth::user();

if ($user->context === UserContext::Organization->value && ! $user->organization) {
return redirect(localized_route('organizations.show-type-selection'));
}

if ($this->isConnector($user)) {
$activeEngagements = $user->{$user->context}->connectingEngagements()->active()->get();
$completeEngagements = $user->{$user->context}->connectingEngagements()->complete()->get();

return view('engagements.joined', [
'title' => __('Engagements I’ve joined as a Community Connector'),
'section' => 'contracted',
'showParticipating' => $this->isParticipant($user),
'showConnecting' => true,
'activeEngagements' => $activeEngagements,
'completeEngagements' => $completeEngagements,
]);
}

abort(404);
}

public function showParticipating(): Response|View|RedirectResponse
{
$user = Auth::user();

if ($user->context === UserContext::Organization->value && ! $user->organization) {
return redirect(localized_route('organizations.show-type-selection'));
}

if ($this->isParticipant($user)) {
$activeEngagements = $user->{$user->context}->engagements()->active()->get();
$completeEngagements = $user->{$user->context}->engagements()->complete()->get();

return view('engagements.joined', [
'title' => __('Engagements I’ve joined as a Consultation Participant'),
'section' => 'participating',
'showParticipating' => true,
'showConnecting' => $this->isConnector($user),
'activeEngagements' => $activeEngagements,
'completeEngagements' => $completeEngagements,
]);
}

abort(404);
}

public function isParticipant(User $user): bool
{
$userContext = $user->{$user->context};

return $userContext && ($userContext->isParticipant() || $userContext->engagements()->count());
}

public function isConnector(User $user): bool
{
$userContext = $user->{$user->context};

return $userContext && ($userContext->isConnector() || $userContext->connectingEngagements()->count());
}
}
40 changes: 40 additions & 0 deletions app/Models/Engagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -604,4 +604,44 @@ public function scopeLocations($query, $locations)

return $query;
}

public function scopeActive($query)
{
$query->whereHas('project', function (Builder $projectQuery) {
$projectQuery->where('end_date', '>', now());
})
->where(function (Builder $engagementQuery) {
$engagementQuery->whereDoesntHave('meetings')
->orWhereHas('meetings', function (Builder $meetingQuery) {
$meetingQuery->where('date', '>', now());
});
})
->where(function (Builder $engagementQuery) {
$engagementQuery->whereNull('complete_by_date')
->orWhere('complete_by_date', '>', now());
})
->where(function (Builder $engagementQuery) {
$engagementQuery->whereNull('window_end_date')
->orWhere('window_end_date', '>', now());
});

return $query;
}

public function scopeComplete($query)
{
$query->whereHas('project', function (Builder $projectQuery) {
$projectQuery->where('end_date', '<', now());
})
->orWhere(function (Builder $engagementQuery) {
$engagementQuery->whereHas('meetings')
->whereDoesntHave('meetings', function (Builder $meetingQuery) {
$meetingQuery->where('date', '>', now());
});
})
->orWhere('complete_by_date', '<', now())
->orWhere('window_end_date', '<', now());

return $query;
}
}
4 changes: 2 additions & 2 deletions app/Models/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,15 @@ public function upcomingProjects(): MorphMany
->orderBy('start_date');
}

public function participatingEngagements(): HasMany
public function engagements(): HasMany
{
return $this->hasMany(Engagement::class);
}

public function participatingProjects(): HasManyDeep
{
return $this->hasManyDeepFromRelations(
$this->participatingEngagements(),
$this->engagements(),
(new Engagement())->project()
);
}
Expand Down
8 changes: 8 additions & 0 deletions app/Policies/EngagementPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Policies;

use App\Enums\UserContext;
use App\Models\Engagement;
use App\Models\User;
use App\Traits\UserCanViewOwnedContent;
Expand Down Expand Up @@ -63,6 +64,13 @@ public function viewAny(User $user): bool
return $this->canViewPublishedContent($user);
}

public function viewJoined(User $user): Response
{
return ($user->context === UserContext::Individual->value || $user->context === UserContext::Organization->value)
? Response::allow()
: Response::denyAsNotFound();
}

public function viewOwned(User $user): bool
{
return $this->canViewOwnedContent($user);
Expand Down
3 changes: 2 additions & 1 deletion database/factories/IndividualFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Database\Factories;

use App\Enums\IndividualRole;
use App\Models\Individual;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
Expand All @@ -26,7 +27,7 @@ public function definition(): array
return User::find($attributes['user_id'])->name;
},
'region' => $this->faker->provinceAbbr(),
'roles' => ['participant'],
'roles' => [IndividualRole::ConsultationParticipant->value],
'languages' => ['en', 'fr'],
'first_language' => function (array $attributes) {
return User::find($attributes['user_id'])->locale;
Expand Down
3 changes: 2 additions & 1 deletion database/factories/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Database\Factories;

use App\Enums\UserContext;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -30,7 +31,7 @@ public function definition(): array
'remember_token' => Str::random(10),
'locale' => config('app.locale'),
'theme' => 'system',
'context' => 'individual',
'context' => UserContext::Individual->value,
'preferred_contact_person' => 'me',
'preferred_contact_method' => 'email',
'preferred_notification_method' => 'email',
Expand Down
20 changes: 20 additions & 0 deletions database/seeders/data/Interpretations.json
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,26 @@
}
]
},
"engagements.joined": {
"interpretations": [
{
"name": "Engagements I’ve joined",
"namespace": "engagements-joined"
},
{
"name": "Joined as a Community Connector",
"namespace": "engagements-joined"
},
{
"name": "Joined as a Consultation Participant",
"namespace": "engagements-joined"
},
{
"name": "Completed engagements",
"namespace": "engagements-joined"
}
]
},
"engagements.add-connector": {
"interpretations": [
{
Expand Down
7 changes: 5 additions & 2 deletions resources/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@
"Completed": "Completed",
"completed": "completed",
"Completed documents are due by:": "Completed documents are due by:",
"Completed engagements": "Completed engagements",
"Completed materials are due by": "Completed materials are due by",
"Confirm": "Confirm",
"Confirm and sign up": "Confirm and sign up",
Expand Down Expand Up @@ -577,6 +578,8 @@
"Engagements": "Engagements",
"Engagements by organizations that I have saved on my notification list": "Engagements by organizations that I have saved on my notification list",
"Engagements I’ve joined": "Engagements I’ve joined",
"Engagements I’ve joined as a Community Connector": "Engagements I’ve joined as a Community Connector",
"Engagements I’ve joined as a Consultation Participant": "Engagements I’ve joined as a Consultation Participant",
"Engagements that are looking for people that my organization represents or supports": "Engagements that are looking for people that my organization represents or supports",
"Engagements that are looking for someone with my lived experience": "Engagements that are looking for someone with my lived experience",
"Engagement translations": "Engagement translations",
Expand Down Expand Up @@ -813,6 +816,8 @@
"I work for a private business, the federal government, or a public sector organization regulated under the Accessible Canada Act.": "I work for a private business, the federal government, or a public sector organization regulated under the Accessible Canada Act.",
"I would like to speak to someone to discuss additional access needs or concerns": "I would like to speak to someone to discuss additional access needs or concerns",
"I’ve gone to orientation, why isn’t this updated?": "I’ve gone to orientation, why isn’t this updated?",
"Joined as a Community Connector": "Joined as a Community Connector",
"Joined as a Consultation Participant": "Joined as a Consultation Participant",
"Join our accessibility community": "Join our accessibility community",
"Keeping my information up to date": "Keeping my information up to date",
"Language": "Language",
Expand Down Expand Up @@ -1299,8 +1304,6 @@
"Projects I am contracted for": "Projects I am contracted for",
"Projects I am participating in": "Projects I am participating in",
"Projects I am running": "Projects I am running",
"Projects involved in as a Community Connector": "Projects involved in as a Community Connector",
"Projects involved in as a Consultation Participant": "Projects involved in as a Consultation Participant",
"Projects I’m running": "Projects I’m running",
"projects notification setting": "projects notification setting",
"Project start date": "Project start date",
Expand Down
9 changes: 6 additions & 3 deletions resources/lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@
"Completed": "Terminé",
"completed": "complété",
"Completed documents are due by:": "Les documents dûment complétés doivent être remis au plus tard le : ",
"Completed engagements": "",
"Completed materials are due by": "Les documents dûment complétés doivent être remis au plus tard le",
"Confirm": "Confirmer",
"Confirm and sign up": "Confirmer et s’inscrire",
Expand Down Expand Up @@ -577,6 +578,8 @@
"Engagements": "Consultations",
"Engagements by organizations that I have saved on my notification list": "Consultations menées par les organisations que j’ai enregistrés dans ma liste de notifications",
"Engagements I’ve joined": "",
"Engagements I’ve joined as a Community Connector": "",
"Engagements I’ve joined as a Consultation Participant": "",
"Engagements that are looking for people that my organization represents or supports": "Consultations qui recherchent des personnes que mon organisation représente ou soutient",
"Engagements that are looking for someone with my lived experience": "Consultations qui sont à la recherche de personnes avec mon expérience vécue",
"Engagement translations": "Traductions de la consultation",
Expand Down Expand Up @@ -813,6 +816,8 @@
"I work for a private business, the federal government, or a public sector organization regulated under the Accessible Canada Act.": "Je travaille pour une entreprise privée, le gouvernement fédéral ou une organisation du secteur public réglementée par la Loi canadienne sur l’accessibilité.",
"I would like to speak to someone to discuss additional access needs or concerns": "Je voudrais parler à une personne afin de discuter de mes besoins ou préoccupations supplémentaires en matière d’accessibilité",
"I’ve gone to orientation, why isn’t this updated?": "J’ai déjà participé à la séance d’information et d’orientation, pourquoi cela n’apparait-il pas?",
"Joined as a Community Connector": "",
"Joined as a Consultation Participant": "",
"Join our accessibility community": "Rejoignez notre communauté en faveur de l’accessibilité",
"Keeping my information up to date": "Maintenir mes informations à jour",
"Language": "Langue",
Expand Down Expand Up @@ -1299,8 +1304,6 @@
"Projects I am contracted for": "Projets pour lesquels je suis sous contrat",
"Projects I am participating in": "Projets auxquels je participe",
"Projects I am running": "Projets que je dirige",
"Projects involved in as a Community Connector": "Mes projets à titre de personne facilitatrice communautaire",
"Projects involved in as a Consultation Participant": "Mes projets à titre de personne participant à des consultations",
"Projects I’m running": "Projets que je dirige",
"projects notification setting": "paramètres des notifications pour le projet",
"Project start date": "Date de début du projet",
Expand Down Expand Up @@ -2160,4 +2163,4 @@
"“About your organization” (English)": "« À propos de votre organisation » (en anglais)",
"“About your organization” (French)": "À propos de votre organisation",
"“About your organization” must be provided in either English or French.": "À propos de votre organisation doit être fournis en anglais ou en français."
}
}
21 changes: 8 additions & 13 deletions resources/views/dashboard/individual.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,27 @@
@endif
</li>
@endif
@can('viewAny', App\Models\Project::class)
@if ($user->individual->isConnector() || $user->individual->inProgressContractedProjects()->count())
<li>
<a
href="{{ localized_route('projects.my-contracted-projects') }}">{{ __('Projects involved in as a Community Connector') }}</a>
</li>
@endif
@endcan
@if (!$user->oriented_at)
<li>
<a href="{{ orientation_link($user->context) }}">{{ __('Sign up for an orientation session') }}</a>
</li>
@endif
@can('viewAny', App\Models\Project::class)
@if ($user->individual->isParticipant() || $user->individual->inProgressParticipatingProjects()->count())
@can('viewJoined', 'App\Models\Engagement')
@if (
$user->individual->isParticipant() ||
$user->individual->isConnector() ||
$user->individual->engagements()->count() ||
$user->individual->connectingEngagements()->count())
<li>
<a
href="{{ localized_route('projects.my-participating-projects') }}">{{ __('Projects involved in as a Consultation Participant') }}</a>
<a href="{{ localized_route('engagements.joined') }}">{{ __('Engagements I’ve joined') }}</a>
</li>
@endif
@endcan
<li>
<a href="{{ localized_route('dashboard.trainings') }}">{{ __('My trainings') }}</a>
</li>
</x-quick-links>
<div class="border-divider mt-14 mb-12 border-x-0 border-t-3 border-b-0 border-solid pt-6">
<div class="border-divider mb-12 mt-14 border-x-0 border-b-0 border-t-3 border-solid pt-6">
@include('dashboard.partials.notifications', [
'notifications' => $user->allUnreadNotifications(),
])
Expand Down
Loading

0 comments on commit b4a973a

Please sign in to comment.