Commit f9fb9e05 authored by okhin's avatar okhin 🚴

Merge branch '77-merge-des-utilisateurs' into 'preprod'

Resolve "Merge des utilisateurs"

Closes #77

See merge request !109
parents 4b6a8a0c f61d5cd1
Pipeline #2552 passed with stages
in 1 minute and 27 seconds
......@@ -881,6 +881,77 @@ class Admin extends Controller
$f3->reroute("/admin/users/$user_id");
}
public function user_merge($f3, $args)
{
$id = array_key_exists('id', $args) ? \Utils::asl($args['id']) : '';
$f3->set('id', $id);
if ($f3->get('VERB') == 'GET') {
$merger = $f3->get('container')['user_finder']->findById($id);
$email_merged = \Utils::asl($f3->get('GET.merged'));
$user = $f3->get('container')['user_finder']->findById($id);
$merged = $f3->get('container')['user_finder']->findByEmail($email_merged);
// Now, we're going to list all pledges and counterparts of merged user
// to display them to the admin.
$counterparts = $f3->get('container')['counterpart_finder']->findByUserId($merged['id']);
$donations = $f3->get('container')['donation_finder']->findByUserId($merged['id']);
// Augment the context
$f3->set('merger', $merger);
$f3->set('merged', $merged);
$f3->set('total', (int)$merged['total'] + (int)$merger['total']);
$f3->set('cumul', (int)$merged['cumul'] + (int)$merger['cumul']);
$f3->set('counterparts', $counterparts);
$f3->set('donations', $donations);
$f3->set('block_content', 'backend/fusion_user.html');
} elseif ($f3->get('VERB') == 'POST') {
$merger_id = \Utils::asl($f3->get('POST.merger_id'));
$merged_id = \Utils::asl($f3->get('POST.merged_id'));
// Retrieving the associated users
$merger = $f3->get('container')['user_finder']->findById($merger_id);
$merged = $f3->get('container')['user_finder']->findById($merged_id);
// Update total and cumul values
$f3->get('container')['command_handler']->handle(new UserUpdateByAdminCommand(
$merger_id,
$merger['pseudo'],
$merger['email'],
$merger['commentaire'] + $merged['commentaire'],
(int) $merger['total'] + (int) $merged['total'],
(int) $merger['cumul'] + (int) $merged['cumul']
));
$db = $f3->get('DB');
// Now, let's change all counterparts of merged
$db->query("UPDATE contreparties
SET user_id = '" . $merger_id ."'
WHERE user_id = '" . $merged_id ."'");
// The donations
$db->query("UPDATE dons
SET user_id = '" . $merger_id ."'
WHERE user_id = '" . $merged_id ."'");
// The identifiers
$db->query("UPDATE identifiers
SET user_id = '" . $merger_id . "'
WHERE user_id = '" . $merged_id . "'");
// The adresses
$db->query("UPDATE adresses
SET user_id = '" . $merger_id . "'
WHERE user_id = '" . $merged_id . "'");
// Remove the merged user
$db->query("DELETE FROM users WHERE id = '" . $merged_id . "'");
// Reroute to the merger
$f3->reroute('/admin/users/'.$merger_id);
};
}
public function user($f3, $args)
{
$id = array_key_exists('id', $args) ? \Utils::asl($args['id']) : '';
......
......@@ -45,6 +45,7 @@ GET|POST @users:/admin/users=Controller\Admin->users
POST @add_user:/admin/users/add=Controller\Admin->user
GET @user_info:/admin/users/@id=Controller\Admin->user
POST @modify_user:/admin/users/@id=Controller\Admin->user
GET|POST @fusion_user:/admin/users/fusion/@id=Controller\Admin->user_merge
POST @adresse:/admin/adresses=Controller\Admin->adresse
......
<section id="fusion">
<h2>Fusion de deux utilisateurs</h2>
<p> Fusionner l'utilisateur #{{ @merged.id }} avec l'utilisateur #{{ @merger.id }}</p>
<h3>Utilisateur {{ @merger.pseudo }} après fusion&nbsp;:</h3>
<dl>
<dt>Pseudo</dt>
<dd>{{ @merger.pseudo }}</dd>
<dt>Email</dt>
<dd>{{ @merger.email }}</dd>
<dt>Total</dt>
<dd>{{ @total }}</dd>
<dt>Cumul</dt>
<dd>{{ @cumul }}</dd>
</dl>
</section>
<section id="counterparts">
<h2>Les contreparties suivantes seront ajoutées à {{ @merger.pseudo }}</h2>
<table>
<thead>
<tr>
<th>Id</th>
<th>Id du parent</th>
<th>Date</th>
<th>Quoi</th>
<th>Taille/Piplome</th>
<th>Statut</th>
<th>Commentaire</th>
</tr>
</thead>
<tbody>
<repeat group="{{ @counterparts }}" value="{{ @row }}">
<tr>
<td>{{ @row.id }}</td>
<td>{{ @row.parent }}</td>
<td>{{ @row.datec }}</td>
<td>{{ @row.quoi }}</td>
<td>
<check if="{{ @row.quoi=='piplome' }}">
<true>
<a href="{{ @PIPLOME_URL }}{{ @row.pdf_url }}.pdf">{{ @row.pdf_url }}</a>
({{ @row.pdf_nom }})
</true>
<false>
<check if="{{ @row.quoi=='pibag' }}">
<true>
&nbsp;
</true>
<false>
{{ @atailles[@row.taille] }}
</false>
</check>
</false>
</check>
</td>
<td>
{{ @row.status }}
</td>
<td>
{{ @row.commentaire }}
</td>
</repeat>
</tr>
</tbody>
</table>
</section>
<section id="donations">
<h2>Les dons suivants seront ajoutés à {{ @merger.pseudo }}</h2>
<table>
<thead>
<th>Id</th>
<th>Date</th>
<th>Don</th>
<th>Adresse</th>
<th>PDF</th>
<th>Statut</th>
</thead>
<tbody>
<repeat group="{{ @donations }}" value="{{ @row }}">
<tr>
<td>{{ @row.id }}</td>
<td class="inline">{{ @row.datec }}</td>
<td>{{ @row.somme }}</td>
<td>{{ @row.pdf }}</td>
<td class="inline">{{ @row.status }}</td>
</tr>
</repeat>
</tbody>
</table>
</section>
<section id="form">
<h2>Fusionner les utilisateurs #{{ @merger.id }} et #{{ @merged.id }}&nbsp;</h2>
<form name="merge" method="POST" action="{{ 'fusion_user' | alias }}">
<input type="hidden" id="csrf" name="csrf" value="{{ @CSRF }}" />
<input type="hidden" id="merger_id" name="merger_id" value="{{ @merger.id }}" />
<input type="hidden" id="merged_id" name="merged_id" value="{{ @merged.id }}" />
<input type="submit" value="Fusionner les utilisateurs" />
</form>
</section>
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment