diff options
Diffstat (limited to 'src/view/NewBuilder.php')
-rw-r--r-- | src/view/NewBuilder.php | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/src/view/NewBuilder.php b/src/view/NewBuilder.php new file mode 100644 index 0000000..605c174 --- /dev/null +++ b/src/view/NewBuilder.php | |||
@@ -0,0 +1,93 @@ | |||
1 | <?php | ||
2 | // src/view/NewBuilder.php | ||
3 | |||
4 | use App\Entity\Node; | ||
5 | |||
6 | class NewBuilder extends AbstractBuilder | ||
7 | { | ||
8 | public function __construct(Node $node) | ||
9 | { | ||
10 | $viewFile = self::VIEWS_PATH . $node->getName() . '.php'; | ||
11 | |||
12 | if(file_exists($viewFile)) | ||
13 | { | ||
14 | // id (timestamp) | ||
15 | if(!empty($node->getAttributes())) | ||
16 | { | ||
17 | extract($node->getAttributes()); | ||
18 | } | ||
19 | |||
20 | // html, date | ||
21 | $title = $node->getArticle()->getTitle(); | ||
22 | $preview = $node->getArticle()->getPreview(); | ||
23 | $id = $node->getArticleTimestamp(); | ||
24 | $content = ''; | ||
25 | |||
26 | // page article unique | ||
27 | if(Director::$page_path->getLast()->getEndOfPath() === 'article') | ||
28 | { | ||
29 | $content = $node->getArticle()->getContent(); | ||
30 | $from_to_button = '<p><a class="link_to_article" href="' . new URL(['page' => 'accueil']) . '"><button>Retour page d\'accueil</button></a></p>'; | ||
31 | } | ||
32 | // page d'accueil (avec des news) | ||
33 | else | ||
34 | { | ||
35 | $from_to_button = '<p><a class="link_to_article" href="' . new URL(['page' => 'article', 'id' => $id]) . '"><button><img class="action_icon" src="assets/book-open.svg">Lire la suite</button></a></p>'; | ||
36 | } | ||
37 | |||
38 | |||
39 | $date_object = $node->getArticle()->getDateTime(); // class DateTime | ||
40 | $date = 'le ' . str_replace(':', 'h', $date_object->format('d-m-Y à H:i')); | ||
41 | |||
42 | // partage | ||
43 | $share_link = new URL(['page' => CURRENT_PAGE], $id); | ||
44 | isset($_GET['id']) ? $share_link->addParams(['id' => $_GET['id']]) : ''; | ||
45 | $share_js = 'onclick="copyInClipBoard(\'' . $share_link . '\')"'; | ||
46 | $share_button = '<p><a href="' . $share_link . '" ' . $share_js . '><img class="action_icon" src="assets/share.svg"></a></p>' . "\n"; | ||
47 | |||
48 | // modifier un article | ||
49 | $admin_buttons = ''; | ||
50 | if($_SESSION['admin']) | ||
51 | { | ||
52 | if(Director::$page_path->getLast()->getEndOfPath() === 'article'){ | ||
53 | $modify_js = 'onclick="openEditor(\'' . $id . '\')"'; | ||
54 | $modify_article = '<p id="edit-' . $id . '"><a href="#"><img class="action_icon" src="assets/edit.svg" ' . $modify_js . '></a></p>' . "\n"; | ||
55 | |||
56 | $up_button = '<p id="position_up-' . $id . '"></p>' . "\n"; | ||
57 | $down_button = '<p id="position_down-' . $id . '"></p>' . "\n"; | ||
58 | |||
59 | $delete_js = 'onclick="deleteArticle(\'' . $id . '\', \'' . CURRENT_PAGE . '\')"'; | ||
60 | $delete_article = '<p id="delete-' . $id . '"><a href="#"><img class="action_icon" src="assets/delete-bin.svg" ' . $delete_js . '></a></p>' . "\n"; | ||
61 | |||
62 | $close_js = 'onclick="closeEditor(\'' . $id . '\')"'; | ||
63 | $close_editor = '<p id="cancel-' . $id . '" class="hidden"><a href="#"><button ' . $close_js . '>Annuler</button></a></p>'; | ||
64 | |||
65 | $submit_js = 'onclick="submitArticle(\'' . $id . '\')"'; | ||
66 | $submit_article = '<p id="submit-' . $id . '" class="hidden"><a href="#"><button ' . $submit_js . '>Valider</button></a></p>'; | ||
67 | } | ||
68 | else{ | ||
69 | $modify_article = '<p id="edit-' . $id . '"></p>' . "\n"; | ||
70 | |||
71 | $up_link = new URL(['page' => CURRENT_PAGE, 'id' => $id, 'action' => 'position_up']); | ||
72 | $up_button = '<p id="position_up-' . $id . '"><a href="' . $up_link . '"><img class="action_icon" src="assets/arrow-up.svg"></a></p>' . "\n"; | ||
73 | |||
74 | $down_link = new URL(['page' => CURRENT_PAGE, 'id' => $id, 'action' => 'position_down']); | ||
75 | $down_button = '<p id="position_down-' . $id . '"><a href="' . $down_link . '"><img class="action_icon" src="assets/arrow-down.svg"></a></p>' . "\n"; | ||
76 | |||
77 | $delete_js = 'onclick="deleteArticle(\'' . $id . '\')"'; | ||
78 | $delete_article = '<p id="delete-' . $id . '"><a href="#"><img class="action_icon" src="assets/delete-bin.svg" ' . $delete_js . '></a></p>' . "\n"; | ||
79 | |||
80 | $close_editor = '<p id="cancel-' . $id . '" class="hidden"></p>'; | ||
81 | $submit_article = '<p id="submit-' . $id . '" class="hidden"></p>'; | ||
82 | |||
83 | $submit_article = '<p id="submit-' . $id . '" class="hidden"></p>'; | ||
84 | } | ||
85 | $admin_buttons = $modify_article . $up_button . $down_button . $delete_article . $close_editor . $submit_article; | ||
86 | } | ||
87 | |||
88 | ob_start(); | ||
89 | require($viewFile); | ||
90 | $this->html .= ob_get_clean(); | ||
91 | } | ||
92 | } | ||
93 | } | ||