diff options
Diffstat (limited to 'src/view/PostBlockBuilder.php')
| -rw-r--r-- | src/view/PostBlockBuilder.php | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/view/PostBlockBuilder.php b/src/view/PostBlockBuilder.php new file mode 100644 index 0000000..fadae31 --- /dev/null +++ b/src/view/PostBlockBuilder.php | |||
| @@ -0,0 +1,77 @@ | |||
| 1 | <?php | ||
| 2 | // src/view/PostBlockBuilder.php | ||
| 3 | |||
| 4 | declare(strict_types=1); | ||
| 5 | |||
| 6 | use App\Entity\Node; | ||
| 7 | |||
| 8 | class PostBlockBuilder extends AbstractBuilder | ||
| 9 | { | ||
| 10 | public function __construct(Node $node) | ||
| 11 | { | ||
| 12 | parent::__construct($node); | ||
| 13 | |||
| 14 | // à remplacer par list.php/grid.php (une vue par stratégie) le jour ou ou a besoin de les différencier | ||
| 15 | //$viewFile = self::VIEWS_PATH . $node->getName() . '.php'; | ||
| 16 | $viewFile = self::VIEWS_PATH . 'post_block.php'; // actuellement identique à news_block.php | ||
| 17 | |||
| 18 | if(file_exists($viewFile)) | ||
| 19 | { | ||
| 20 | if(!empty($node->getNodeData()->getData())) | ||
| 21 | { | ||
| 22 | extract($node->getNodeData()->getData()); | ||
| 23 | } | ||
| 24 | |||
| 25 | $presentation = $node->getNodeData()->getPresentation()->getName(); // affichage list ou grid | ||
| 26 | |||
| 27 | // exécution de la stratégie (utilisation d'une méthode ou d'une classe) | ||
| 28 | $section_class = $presentation; | ||
| 29 | $section_child_class = $presentation === 'grid' ? 'grid_columns' : ''; | ||
| 30 | |||
| 31 | // ajouter un article | ||
| 32 | $new_article = ''; | ||
| 33 | if($_SESSION['admin']) | ||
| 34 | { | ||
| 35 | $id = 'n' . $this->id_node; | ||
| 36 | |||
| 37 | $share_button = '<p class="share hidden"><img class="action_icon" src="assets/share.svg"></p>'; | ||
| 38 | |||
| 39 | $new_button = '<p id="new-' . $id . '">' . "\n" . '<button onclick="openEditor(\'' . $id . '\')"><img class="action_icon" src="assets/edit.svg">Nouvel article</button></p>'; | ||
| 40 | |||
| 41 | $modify_js = 'onclick="openEditor(\'' . $id . '\')"'; | ||
| 42 | $modify_article = '<p id="edit-' . $id . '" class="hidden"><img class="action_icon" src="assets/edit.svg" ' . $modify_js . '></p>' . "\n"; | ||
| 43 | |||
| 44 | $up_js = 'onclick="switchPositions(\'' . $id . '\', \'up\')"'; | ||
| 45 | $up_button = '<p id="position_up-' . $id . '" class="hidden"><img class="action_icon" src="assets/arrow-up.svg" ' . $up_js . '></p>' . "\n"; | ||
| 46 | |||
| 47 | $down_js = 'onclick="switchPositions(\'' . $id . '\', \'down\')"'; | ||
| 48 | $down_button = '<p id="position_down-' . $id . '" class="hidden"><img class="action_icon" src="assets/arrow-down.svg" ' . $down_js . '></p>' . "\n"; | ||
| 49 | |||
| 50 | $delete_js = 'onclick="deleteArticle(\'' . $id . '\')"'; | ||
| 51 | $delete_article = '<p id="delete-' . $id . '" class="hidden"><img class="action_icon" src="assets/delete-bin.svg" ' . $delete_js . '></p>' . "\n"; | ||
| 52 | |||
| 53 | $close_js = 'onclick="closeEditor(\'' . $id . '\')"'; | ||
| 54 | $close_editor = '<p id="cancel-' . $id . '" class="hidden"><button ' . $close_js . '>Annuler</button></p>'; | ||
| 55 | |||
| 56 | $submit_js = 'onclick="submitArticle(\'' . $id . '\', \'\', clone' . $this->id_node . ')"'; | ||
| 57 | $submit_article = '<p id="submit-' . $id . '" class="hidden"><button ' . $submit_js . '>Valider</button></p>'; | ||
| 58 | |||
| 59 | $html = ''; | ||
| 60 | $admin_buttons = $new_button . $modify_article . $up_button . $down_button . $delete_article . $close_editor . $submit_article; | ||
| 61 | |||
| 62 | // squelette d'un nouvel article | ||
| 63 | ob_start(); | ||
| 64 | require self::VIEWS_PATH . 'post.php'; | ||
| 65 | $new_article = ob_get_clean(); | ||
| 66 | } | ||
| 67 | |||
| 68 | // articles existants | ||
| 69 | $this->useChildrenBuilder($node); | ||
| 70 | $content = $this->html; | ||
| 71 | |||
| 72 | ob_start(); | ||
| 73 | require $viewFile; | ||
| 74 | $this->html = ob_get_clean(); // pas de concaténation ici, on écrase | ||
| 75 | } | ||
| 76 | } | ||
| 77 | } \ No newline at end of file | ||
