UserHandler.php 1.7 KB
Newer Older
1
2
3
4
5
6
<?php

namespace LQDN\Handler;

use Doctrine\DBAL\Connection;
use LQDN\Command\UserUpdateByAdminCommand;
7
8
use LQDN\Command\UserUpdateTotalCommand;
use LQDN\Command\UserUpdateCumulCommand;
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

class UserHandler
{
    private $connection;

    public function __construct(Connection $connection)
    {
        $this->connection = $connection;
    }

    /**
     * Update of a user from the admin.
     *
     * @param UserUpdateByAdminCommand $command
     */
    public function handleUserUpdateByAdminCommand(UserUpdateByAdminCommand $command)
    {
        $this->connection->executeUpdate('UPDATE users SET pseudo = :username, email = :email, commentaire = :comment WHERE id = :id', [
            'username' => $command->getUsername(),
            'email' => $command->getEmail(),
            'comment' => $command->getComment(),
            'id' => $command->getId(),
        ]);
    }
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64

    /**
     * Update the user total
     *
     * @param UserUpdateTotalCommand $command
     */
    public function handleUserUpdateTotalCommand(UserUpdateTotalCommand $command)
    {
        $this->connection->executeUpdate(
            'UPDATE users SET total = :total WHERE id = :id',
            [
                'total' => $command->getTotal(),
                'id'=> $command->getId()
            ]
        );
    }

    /**
     * Update the user cumul
     *
     * @param UserUpdateCumulCommand $command
     */
    public function handleUserUpdateCumulCommand(UserUpdateCumulCommand $command)
    {
        $this->connection->executeUpdate(
            'UPDATE users SET cumul = :cumul WHERE id = :id',
            [
                'cumul' => $command->getCumul(),
                'id' => $command->getId(),
            ]
        );
    }
65
}