Skip to content

Commit

Permalink
[CommitteeElection] adjust voting platform for supervisor election (#…
Browse files Browse the repository at this point in the history
…8354)

* [CommitteeElection] adjust voting platform for supervisor election

* Fix tests
  • Loading branch information
ottaviano authored Mar 21, 2023
1 parent 84cc162 commit 4620a48
Show file tree
Hide file tree
Showing 18 changed files with 90 additions and 131 deletions.
14 changes: 10 additions & 4 deletions src/Command/VotingPlatform/ConfigureCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private function configureCommitteeSupervisorElections(Designation $designation)

if (
$designation->getVoteStartDate() < $now->modify('+10 minutes')
&& !$committeeElection->countConfirmedCandidacies()
&& !$election->countCandidateGroups()
) {
$this->configureCandidatesGroupsForCommitteeSupervisorElection($committeeElection, $election);
}
Expand Down Expand Up @@ -518,13 +518,19 @@ private function configureCandidatesGroupsForCommitteeSupervisorElection(
return;
}

$pools = [
$pool = new ElectionPool(ElectionPoolCodeEnum::COMMITTEE_SUPERVISOR),
$pools = $election->getElectionPools() ?: [
new ElectionPool(ElectionPoolCodeEnum::COMMITTEE_SUPERVISOR),
];

$pool = current($pools);

foreach ($committeeElection->getCandidaciesGroups() as $candidaciesGroup) {
if (empty($candidaciesGroup->getCandidacies())) {
continue;
}

$pool->addCandidateGroup($group = new CandidateGroup());
foreach ($candidaciesGroup as $candidacy) {
foreach ($candidaciesGroup->getCandidacies() as $candidacy) {
$group->addCandidate($this->createCommitteeSupervisorCandidate($candidacy));
}
}
Expand Down
12 changes: 11 additions & 1 deletion src/Command/VotingPlatform/SendVoteReminderCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Command\VotingPlatform;

use App\Entity\VotingPlatform\Designation\Designation;
use App\Entity\VotingPlatform\Election;
use App\Entity\VotingPlatform\Vote;
use App\Repository\CommitteeMembershipRepository;
Expand Down Expand Up @@ -85,6 +86,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->io->progressStart();

foreach ($elections as $election) {
if (
!$election->getDesignation()->isNotificationVoteReminderEnabled()
|| !$election->isNotificationAlreadySent(Designation::NOTIFICATION_VOTE_REMINDER)
) {
continue;
}

$this->sendElectionVoteReminders($election);

$this->io->progressAdvance();
Expand Down Expand Up @@ -114,12 +122,14 @@ private function sendElectionVoteReminders(Election $election): void
$this->dispatcher->dispatch(new VotingPlatformVoteReminderEvent($election, $adherent));

$adherent->notifyForElection();
$this->entityManager->flush();
}
} else {
foreach ($this->voterRepository->findVotersToRemindForElection($election) as $voter) {
$this->dispatcher->dispatch(new VotingPlatformVoteReminderEvent($election, $voter->getAdherent()));
}
}

$election->markSentNotification(Designation::NOTIFICATION_VOTE_REMINDER);
$this->entityManager->flush();
}
}
4 changes: 1 addition & 3 deletions src/DataFixtures/ORM/LoadCommitteeV2CandidaciesGroupData.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ public function load(ObjectManager $manager)

$election1->addCandidaciesGroups($list = new CommitteeCandidaciesGroup(Uuid::fromString(self::CANDIDACIES_GROUP_1_UUID)));
$list->addCandidacy($candidate = new CommitteeCandidacy($election1, Genders::FEMALE, Uuid::fromString(self::CANDIDACY_1_UUID)));

$candidate->setCommitteeMembership($adherent5->getMembershipFor($committee));

$election1->addCandidaciesGroups($list = new CommitteeCandidaciesGroup(Uuid::fromString(self::CANDIDACIES_GROUP_2_UUID)));
$election1->addCandidaciesGroups(new CommitteeCandidaciesGroup(Uuid::fromString(self::CANDIDACIES_GROUP_2_UUID)));

/** @var CommitteeElection $election2 */
$election2 = $this->getReference('committee-election-2');
Expand Down
88 changes: 16 additions & 72 deletions src/DataFixtures/ORM/LoadVotingPlatformElectionData.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\DataFixtures\ORM;

use App\Entity\CommitteeCandidacy;
use App\Entity\CommitteeElection;
use App\Entity\LocalElection\LocalElection;
use App\Entity\TerritorialCouncil\Candidacy;
use App\Entity\TerritorialCouncil\TerritorialCouncil;
Expand All @@ -21,7 +22,6 @@
use App\Entity\VotingPlatform\VotersList;
use App\ValueObject\Genders;
use App\VotingPlatform\Designation\DesignationTypeEnum;
use App\VotingPlatform\Designation\MajorityVoteMentionEnum;
use App\VotingPlatform\Election\ResultCalculator;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
Expand Down Expand Up @@ -197,14 +197,7 @@ public function load(ObjectManager $manager)
$election->setElectionEntity(new ElectionEntity($this->getReference('committee-15')));
$this->loadCommitteeSupervisorElectionCandidates($election);
$this->manager->persist($votersList = $this->loadCommitteeSupervisorElectionVoters($election));
$this->loadMajorityVotes($round, $votersList, [
[4, 1, 1],
[4, 4, 0],
[1, 2, 3],
[4, 0, 1],
[2, 3, 4],
]);
$this->resultCalculator->computeElectionResult($election);
$this->loadResults($round, $votersList);

// -------------------------------------------

Expand Down Expand Up @@ -269,47 +262,23 @@ private function loadCommitteeSupervisorElectionCandidates(Election $election):
$election->addElectionPool($pool);

$committee = $election->getElectionEntity()->getCommittee();
/** @var CommitteeElection $committeeElection */
$committeeElection = $committee->getCurrentElection();

foreach ($committeeElection->getCandidacies() as $committeeCandidacy) {
/** @var CommitteeCandidacy $committeeCandidacy */
if (!$committeeCandidacy->isConfirmed() || $committeeCandidacy->isTaken()) {
continue;
}

$group = new CandidateGroup();

$group->addCandidate($candidate = new Candidate(
$committeeCandidacy->getFirstName(),
$committeeCandidacy->getLastName(),
$committeeCandidacy->getGender(),
$committeeCandidacy->getAdherent()
));
$candidate->setImagePath($committeeCandidacy->getImagePath());
$candidate->setBiography($committeeCandidacy->getBiography());
$candidate->setFaithStatement($committeeCandidacy->getFaithStatement());
$committeeCandidacy->take();

if ($committeeCandidaciesGroup = $committeeCandidacy->getCandidaciesGroup()) {
foreach ($committeeCandidaciesGroup->getCandidacies() as $committeeCandidacy) {
if ($committeeCandidacy->isTaken()) {
continue;
}
foreach ($committeeElection->getCandidaciesGroups() as $candidacyGroup) {
$pool->addCandidateGroup($group = new CandidateGroup());

$group->addCandidate($candidate = new Candidate(
$committeeCandidacy->getFirstName(),
$committeeCandidacy->getLastName(),
$committeeCandidacy->getGender(),
$committeeCandidacy->getAdherent()
));
$candidate->setImagePath($committeeCandidacy->getImagePath());
$candidate->setBiography($committeeCandidacy->getBiography());
$candidate->setFaithStatement($committeeCandidacy->getFaithStatement());
$committeeCandidacy->take();
}
foreach ($candidacyGroup->getCandidacies() as $committeeCandidacy) {
$group->addCandidate($candidate = new Candidate(
$committeeCandidacy->getFirstName(),
$committeeCandidacy->getLastName(),
$committeeCandidacy->getGender(),
$committeeCandidacy->getAdherent()
));
$candidate->setImagePath($committeeCandidacy->getImagePath());
$candidate->setBiography($committeeCandidacy->getBiography());
$candidate->setFaithStatement($committeeCandidacy->getFaithStatement());
}

$pool->addCandidateGroup($group);
}
}

Expand Down Expand Up @@ -390,7 +359,7 @@ private function loadResults(ElectionRound $electionRound, VotersList $votersLis

foreach ($votersList->getVoters() as $i => $voter) {
// simulate abstention
if (0 === $i % 7 || \in_array($voter, $this->voters, true)) {
if (0 === $i % 7) {
continue;
}

Expand Down Expand Up @@ -561,29 +530,4 @@ public function getDependencies()
LoadLocalElectionData::class,
];
}

private function loadMajorityVotes(ElectionRound $electionRound, VotersList $votersList, array $votesData): void
{
$voters = $votersList->getVoters();
shuffle($voters);

foreach ($votesData as $voteRow) {
$voter = array_shift($voters);
$this->manager->persist(new Vote($voter, $electionRound));

$result = new VoteResult($electionRound, VoteResult::generateVoterKey());

foreach ($electionRound->getElectionPools() as $pool) {
foreach ($voteRow as $i => $mentionIndex) {
$result->addVoteChoice($choice = new VoteChoice($pool));
$choice->setMention(MajorityVoteMentionEnum::ALL[$mentionIndex]);
$choice->setCandidateGroup($pool->getCandidateGroups()[$i]);
}
}

$this->manager->persist($result);
}

$this->manager->flush();
}
}
7 changes: 7 additions & 0 deletions src/Entity/CommitteeCandidacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,11 @@ public function getCommittee(): Committee
{
return $this->committeeElection->getCommittee();
}

public function candidateWith(CandidacyInterface $candidacy): void
{
parent::candidateWith($candidacy);

$this->candidaciesGroup->setElection($candidacy->getElection());
}
}
7 changes: 2 additions & 5 deletions src/Entity/VotingPlatform/Designation/Designation.php
Original file line number Diff line number Diff line change
Expand Up @@ -724,10 +724,7 @@ public function isExecutiveOfficeType(): bool

public function isMajorityType(): bool
{
return \in_array($this->type, [
DesignationTypeEnum::COMMITTEE_SUPERVISOR,
DesignationTypeEnum::NATIONAL_COUNCIL,
], true);
return DesignationTypeEnum::NATIONAL_COUNCIL === $this->type;
}

public function isRenaissanceElection(): bool
Expand Down Expand Up @@ -761,7 +758,7 @@ public function setDenomination(string $denomination): void

public function isDenominationEditable(): bool
{
return !$this->isLocalElectionTypes();
return !$this->isLocalElectionTypes() && !$this->isCommitteeSupervisorType();
}

public function equals(self $other): bool
Expand Down
5 changes: 5 additions & 0 deletions src/Entity/VotingPlatform/Election.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,9 @@ public function isNotificationAlreadySent(int $notification): bool
{
return 0 !== ($this->notificationsSent & $notification);
}

public function countCandidateGroups(): int
{
return array_sum($this->electionPools->map(fn (ElectionPool $pool) => $pool->countCandidateGroups())->toArray());
}
}
14 changes: 6 additions & 8 deletions templates/committee_designation/votes_list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,13 @@
{% endfor %}
{% endfor %}
{% else %}
{% for pool_code in constant('App\\ValueObject\\Genders::MALE_FEMALE') %}
{% for choice in choices|sort((a, b) => a.electionPool.code <=> b.electionPool.code) %}
<td>
{% for choice in choices|filter(choice => pool_code == choice.electionPool.code) %}
{% if choice.isBlank %}
~
{% else %}
{{ choice.candidateGroup.candidates|first.fullName }}
{% endif %}
{% endfor %}
{% if choice.isBlank %}
~
{% else %}
{{ choice.candidateGroup.candidates|first.fullName }}
{% endif %}
</td>
{% endfor %}
{% endif %}
Expand Down
2 changes: 2 additions & 0 deletions templates/voting_platform/_layout_committee_base.html.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{% extends 'voting_platform/_layout_base.html.twig' %}

{% set committee = election.electionEntity.committee %}

{% block banner %}
<div class="space--10-0 background--blue">
<div class="l__wrapper--wide">
Expand Down
19 changes: 17 additions & 2 deletions templates/voting_platform/_layout_committee_supervisor.html.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
{% extends 'voting_platform/_layout_committee_base.html.twig' %}

{% block vote_step_pool_title %}
Évaluez votre satisfaction vis-à-vis de chaque candidature
{% block election_sub_title '' %}
{% block vote_step_pool_title '' %}

{% block banner %}
<div class="max-w-8xl mx-auto py-3 px-4 md:px-6">
<a href="{{ path('app_renaissance_committee_election_candidacies_lists_view', {uuid: committee.getUuid()}) }}" class="text-base text-gray-500 hover:text-gray-900">
← Retourner
</a>
</div>
{% endblock %}

{% block vote_finish_action_block %}
<div class="b__nudge--bottom-large b__nudge--top-large">
<a href="{{ path('app_renaissance_committee_election_candidacies_lists_view', {uuid: committee.getUuid()}) }}" class="btn btn--blue">
Retour au comité
</a>
</div>
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{% include 'voting_platform/confirmation/candidate_box/burex_content.html.twig' %}
{% elseif designation.isPollType() %}
{% include 'voting_platform/confirmation/candidate_box/poll_content.html.twig' %}
{% elseif designation.isLocalElectionTypes() %}
{% elseif designation.isLocalElectionTypes() or designation.isCommitteeSupervisorType() %}
{% include 'voting_platform/confirmation/candidate_box/local_election_content.html.twig' %}
{% else %}
{% include 'voting_platform/confirmation/candidate_box/default_content.html.twig' %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
{{ first.getFirstName() }}
<span class="uppercase font-medium"> {{ first.getLastName() }}</span>
</li>
<li class="text-gray-500">+ {{ candidates|length - 1 }} candidature{{ candidates|length - 1 > 1 ? 's' }}</li>
{% if candidates|length > 1 %}
<li class="text-gray-500">+ {{ candidates|length - 1 }} candidature{{ candidates|length - 1 > 1 ? 's' }}</li>
{% endif %}
</ul>
{% endif %}
{% else %}
Expand Down
2 changes: 1 addition & 1 deletion templates/voting_platform/finish.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</div>
</div>
<h1 class="text--larger b__nudge--bottom-large">
{% if designation.isExecutiveOfficeType() or designation.isLocalElectionTypes() %}
{% if designation.isExecutiveOfficeType() or designation.isLocalElectionTypes() or designation.isCommitteeSupervisorType() %}
Félicitations, votre bulletin est dans l'urne !
{% elseif designation.isPollType() %}
Félicitations, votre vote est bien enregistré !
Expand Down
19 changes: 1 addition & 18 deletions templates/voting_platform/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,7 @@
<h2>Pour les territoires avec un nombre de membres supplémentaires voté par le Conseil territorial pour respecter la règle de parité au sein du Comité politique :</h2>
<p>A l’issue du vote des 5 binômes paritaires pour le Comité politique, seront élus individuellement (le(s) femme(s) ou le(es)’hommes(s)) figurant dans les binômes ayant obtenu le plus de voix en valeur absolue, tous types de binômes confondus, à la suite des binômes paritaires élus.</p>
{% elseif election.designationType == constant('App\\VotingPlatform\\Designation\\DesignationTypeEnum::COMMITTEE_SUPERVISOR') %}
<h2>Un choix innovant pour voter : le « jugement majoritaire »</h2>
<p>Le jugement majoritaire est représentatif des valeurs que porte le Mouvement, il permet de favoriser le consensus et la bienveillance. </p>

<p>Lors du vote, vous allez ainsi donner votre avis sur un ou plusieurs binômes candidats en leur attribuant cinq mentions : Excellent; Très bien; Bien ; Passable; Insuffisant.</p>

<p>👉 Le binôme qui obtiendra le meilleur score auprès de 50% du corps électoral sera élu.</p>

<h2>Retrouvez tous les détails expliqués par Justine Henry</h2>

<p class="text--center">
<iframe width="560" height="315" src="https://www.youtube.com/embed/5M8Whm27tFc" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</p>

<h2>Mon choix est-il anonyme ?</h2>
<p>Ici, vous êtes comme dans l’isoloir. Votre choix ne sera connu que de vous seul. Lors de votre vote, vous recevrez un numéro anonymisé qui vous permettra de retrouver votre choix lors de l’affichage des résultats dans l’espace de votre comité.</p>

<h2>Quand et comment seront affichés les résultats ?</h2>
<p>A la fin de la période de vote, vous recevrez un mail avec l’annonce des résultats. Ces informations seront également disponibles dans l’espace de votre comité.</p>
<p>{{ designation.getDescription() }}</p>
{% elseif election.designationType == constant('App\\VotingPlatform\\Designation\\DesignationTypeEnum::NATIONAL_COUNCIL') %}
<p>Pour assurer une meilleure représentativité et poursuivre nos objectifs de démocratie interne et de parité dans nos instances, nous vous invitions à désigner un trio composé d'un élu local, d'un animateur local et d'un adhérent qui constituera un quatuor paritaire avec le référent territorial. Le trio désigné siégera au Conseil national pendant 2 ans.</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{% if designation.isExecutiveOfficeType() %}
{% include 'voting_platform/vote_step/candidate_box/burex_content.html.twig' %}
{% elseif designation.isLocalElectionTypes() %}
{% elseif designation.isLocalElectionTypes() or designation.isCommitteeSupervisorType() %}
{% include 'voting_platform/vote_step/candidate_box/local_election_content.html.twig' %}
{% else %}
{% include 'voting_platform/vote_step/candidate_box/default_content.html.twig' %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
{{ first.getFirstName() }}
<span class="uppercase font-medium"> {{ first.getLastName() }}</span>
</li>
<li class="text-gray-500">+ {{ candidates|length - 1 }} candidature{{ candidates|length - 1 > 1 ? 's' }}</li>
{% if candidates|length > 1 %}
<li class="text-gray-500">+ {{ candidates|length - 1 }} candidature{{ candidates|length - 1 > 1 ? 's' }}</li>
{% endif %}
</ul>

<div class="flex items-center justify-between text-base !text-gray-500">
Expand Down
Loading

0 comments on commit 4620a48

Please sign in to comment.