aboutsummaryrefslogtreecommitdiff
path: root/src/view/ShowEmailsBuilder.php
blob: 3d2d6a9387ce392fce0b453bd389c2e84f94e849 (plain)
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
28
29
30
31
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
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
// src/view/ShowEmailsBuilder.php

declare(strict_types=1);

use App\Entity\Node;
use App\Entity\Page;

class ShowEmailsBuilder extends AbstractBuilder
{
    public function __construct(Node $node = null)
    {
        //parent::__construct($node);
        $viewFile = self::VIEWS_PATH . $node->getName() . '.php';
        if(file_exists($viewFile))
        {
            // objets Email groupés par destinataire
            $emails_by_recipient = [];
            foreach($node->getNodeData()->getEmails() as $email){
                $recipient = $email->getRecipient();
                $emails_by_recipient[$recipient][] = $email;
            }

            // affiche une table par destinataire
            $emails = '';
            foreach($emails_by_recipient as $recipient => $emails_list){
                $html = '<h4>Destinataire: ' . $recipient . '</h4>
                    <table>
                        <thead>
                            <tr>
                                <th>Expéditeur</th>
                                <th>Adresse</th>
                                <th>Contenu</th>
                                <th>Date</th>
                                <th>Effacement prévu le</th>
                                <th>Sensible</th>
                                <th class="email_delete_button"></th>
                            </tr>
                        </thead>
                        <tbody>';

                // insère les données
                foreach($emails_list as $email){
                    $html .= '<tr id="' . $email->getId() . '">
                        <td>' . htmlspecialchars($email->getSenderName()) . '</td>
                        <td>' . htmlspecialchars($email->getSenderAddress()) . '</td>
                        <td>' . htmlspecialchars($email->getContent()) . '</td>
                        <td>' . $email->getDateTime()->format('d/m/Y') . '</td>
                        <td class="deletion_date">' . $email->getDeletionDate()->format('d/m/Y') . '</td>
                        <td><input class="make_checkbox_sensitive" type="checkbox" ' . ($email->isSensitive() ? 'checked' : '') . ' onclick="toggleSensitiveEmail(' . $email->getId() . ')"></td>
                        <td class="email_delete_button"><img class="action_icon" src="assets/delete-bin.svg" onclick="deleteEmail(' . $email->getId() . ')"></td>
                    </tr>';
                }

                $html .= '</tbody>
                    </table>';
                $emails .= $html;
            }

            ob_start();
            require $viewFile; // insertion de $this->html généré par unfoldMenu
            $this->html = ob_get_clean(); // pas de concaténation .= cette fois on écrase
        }
        else{
            header('Location: ' . new URL(['error' => 'show_emails_view_not_found']));
            die;
        }
    }
}