CounterpartHandler.php 1.63 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php

namespace LQDN\Handler;

use Doctrine\DBAL\Connection;
use LQDN\Command\CounterpartCreateCommand;
use LQDN\Command\CounterpartDeleteCommand;
use LQDN\Command\CounterpartUpdateCommand;
use LQDN\Exception\CounterpartAlreadyExistsException;

class CounterpartHandler
{
    private $connection;

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

    /**
     * Delete a counterpart
     *
     * @param CounterpartDeleteCommand $command
     */
    public function handleCounterpartDeleteCommand(CounterpartDeleteCommand $command)
    {
        $counterpartId = $command->getCounterpartId();
Okhin's avatar
Linting    
Okhin committed
28
29
30
31
        $this->connection->executeUpdate(
            "DELETE FROM counterparts WHERE id = :id",
            ['id' => $counterpartId()]
        );
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
    }

    /**
     * Create a counterpart
     *
     * @param CounterpartCreateCommand $command
     */
    public function handleCounterpartCreateCommand(CounterpartCreateCommand $command)
    {
        $userId = $command->getUserId();
        $adresseId = $command->getAdressId();

        $query =<<<EOF
REPLACE INTO counterparts(datec, user_id, addresse_id, quoi, taille, status)
VALUES (:datec, :user_id, :addresse_id, :quoi, :taille, :status)
EOF;
        $stmt = $this->connection->prepare($query);
        $stmt->bindValue('user_id', $command->getUserId());
        $stmt->bindValue('adresse_id', $command->getAddressId());
        $stmt->bindValue('quoi', $command->getQuoi());
        $stmt->bindValue('taille', $command->getTaille());
        $stmt->bindValue('datec', $command->getDate());
        $stmt->bindValue('status', $command->getStatus());
    }
}