From 822f526fd7f4e89043e64b435961720b622bdb6e Mon Sep 17 00:00:00 2001 From: polo Date: Wed, 29 Oct 2025 12:08:28 +0100 Subject: =?UTF-8?q?gestion=20r=C3=A9seaux=20sociaux=20pr=C3=A9sents/absent?= =?UTF-8?q?s,=20partie=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/css/head.css | 5 ---- public/js/Input.js | 12 +++++++-- src/controller/HeadFootController.php | 7 ++--- src/model/entities/NodeData.php | 2 ++ src/view/HeaderBuilder.php | 51 ++++++++++++++++++----------------- src/view/templates/header.php | 8 +----- src/view/templates/modify_block.php | 1 + 7 files changed, 44 insertions(+), 42 deletions(-) diff --git a/public/css/head.css b/public/css/head.css index 3d9d6ca..b5f1bd1 100644 --- a/public/css/head.css +++ b/public/css/head.css @@ -88,11 +88,6 @@ header a flex-wrap: wrap; } #header_social_content img -{ - width: 28px; - -} -#header_social_content a img { width: 28px; background-color: #ffffffb3; diff --git a/public/js/Input.js b/public/js/Input.js index 6c5af10..54872d1 100644 --- a/public/js/Input.js +++ b/public/js/Input.js @@ -76,11 +76,19 @@ class InputText extends InputToggler{ class InputTextSocialNetwork extends InputText{ open(){ - this.input_elem.value = this.content_elem.parentNode.href; + const elem_parent = this.content_elem.parentNode; + if(elem_parent.tagName.toLowerCase() === 'a'){ + this.input_elem.value = elem_parent.href; + } super.open(); } onSuccess(data){ - this.content_elem.parentNode.href = this.input_elem.value; + if(this.input_elem.value){ + this.content_elem.parentNode.href = this.input_elem.value; + } + else{ + this.content_elem.parentNode.removeAttribute('href'); + } } } diff --git a/src/controller/HeadFootController.php b/src/controller/HeadFootController.php index ffa33bc..7597683 100644 --- a/src/controller/HeadFootController.php +++ b/src/controller/HeadFootController.php @@ -3,14 +3,13 @@ declare(strict_types=1); +use App\Entity\NodeData; use App\Entity\NodeDataAsset; use App\Entity\Asset; use Doctrine\ORM\EntityManager; class HeadFootController { - static array $social_networks = ['facebook', 'instagram', 'linkedin', 'github']; // à completer - static public function setTextData(EntityManager $entityManager, string $request_params, array $json): void { $params_array = explode('_', $request_params); // header_title, header_description, footer_name, footer_address, footer_email @@ -22,7 +21,8 @@ class HeadFootController $model = new Model($entityManager); if($model->findWhateverNode('name_node', $params_array[0])){ $node_data = $model->getNode()->getNodeData(); - if(in_array($params_array[1], self::$social_networks)){ + + if(in_array($params_array[1], NodeData::$social_networks)){ $social = $node_data->getData()['social']; $social[$params_array[1]] = $json['new_text']; $node_data->updateData('social', $social); @@ -30,6 +30,7 @@ class HeadFootController else{ $node_data->updateData($params_array[1], $json['new_text']); // $params_array[1] n'est pas contrôlé } + $entityManager->flush(); echo json_encode(['success' => true]); } diff --git a/src/model/entities/NodeData.php b/src/model/entities/NodeData.php index ed94f1b..b0aaef9 100644 --- a/src/model/entities/NodeData.php +++ b/src/model/entities/NodeData.php @@ -13,6 +13,8 @@ use Doctrine\Common\Collections\Collection; // interface #[ORM\Table(name: TABLE_PREFIX . "node_data")] class NodeData { + static array $social_networks = ['facebook', 'instagram', 'linkedin', 'github']; // à completer + #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: "integer")] diff --git a/src/view/HeaderBuilder.php b/src/view/HeaderBuilder.php index 4fbf941..1cc4fc3 100644 --- a/src/view/HeaderBuilder.php +++ b/src/view/HeaderBuilder.php @@ -4,6 +4,7 @@ declare(strict_types=1); use App\Entity\Node; +use App\Entity\NodeData; use App\Entity\Asset; class HeaderBuilder extends AbstractBuilder @@ -47,6 +48,7 @@ class HeaderBuilder extends AbstractBuilder $header_logo = Asset::USER_PATH . $node_data->getAssetByRole('header_logo')?->getFileName() ?? ''; $header_background_name = $node_data->getAssetByRole('header_background')?->getFileName(); $header_background = $header_background_name ? Asset::USER_PATH . $header_background_name : ''; + $social_networks = ''; // boutons mode admin if($_SESSION['admin']){ @@ -66,6 +68,7 @@ class HeaderBuilder extends AbstractBuilder '; + // texte dans classe header_content $admin_header_title = ' @@ -78,29 +81,23 @@ class HeaderBuilder extends AbstractBuilder // icônes réseaux sociaux $header_social_flex_direction = 'column'; - $admin_social_networks = []; - foreach(array_keys($social) as $one_key){ - // - // sinon plutôt qu'on bouton nouveau réseau, utiliser le foreach avec HeadFootController::$social_networks pour tous les parcourir et placer des cases à cocher - // les icones seront ajoutées par mes soins - $admin_social_networks[$one_key] = ' - - - - '; - } - //$admin_social_new_network = '
nouveau réseau
'; - $admin_social_new_network = ''; + // boucle sur la liste complète de réseaux sociaux + foreach(NodeData::$social_networks as $network){ + $checked = (isset($social_show[$network]) && $social_show[$network]) ? 'checked' : ''; + $href = isset($social[$network]) ? 'href="' . $social[$network] . '"' : ''; - /*$social_networks_inputs = '';*/ } else{ $admin_favicon = ''; @@ -108,12 +105,16 @@ class HeaderBuilder extends AbstractBuilder $admin_header_logo = ''; $admin_header_title = ''; $admin_header_description = ''; + $header_social_flex_direction = 'row'; - $admin_social_networks = []; - foreach(array_keys($social) as $one_key){ - $admin_social_networks[$one_key] = ''; + if(isset($social_show)){ + // boucle sur les réseaux sociaux "activés" + foreach(array_keys($social_show) as $network){ + $social_networks .= '
+ '. $network . '_alt +
'; + } } - $admin_social_new_network = ''; } ob_start(); diff --git a/src/view/templates/header.php b/src/view/templates/header.php index 89cdd4b..4c39cfd 100644 --- a/src/view/templates/header.php +++ b/src/view/templates/header.php @@ -36,13 +36,7 @@
- -
- <?= $one_key ?>_alt - -
- - +
diff --git a/src/view/templates/modify_block.php b/src/view/templates/modify_block.php index 6b7ceb0..d855a4a 100644 --- a/src/view/templates/modify_block.php +++ b/src/view/templates/modify_block.php @@ -1,3 +1,4 @@ +