Compare commits

...

13 Commits

Author SHA1 Message Date
393c4c16bb breadcrumb changes
Some checks failed
continuous-integration/drone/push Build is failing
2024-12-02 12:33:07 +01:00
c0578b4db3 refining search style 2024-12-02 12:32:53 +01:00
0ea3b2b022 few padding tweaks 2024-12-02 12:32:02 +01:00
4fd82c9b30 removing uncessary write_log 2024-12-02 12:31:48 +01:00
2c9cec5176 few appaerance tweaks 2024-12-02 12:31:36 +01:00
1b3c5dc54a handling search 2024-12-02 12:31:25 +01:00
d094d52647 refining sidebar & no-content 2024-12-02 12:31:15 +01:00
142d4fc197 handling chantier list in backend 2024-12-02 12:30:24 +01:00
898751f746 introducing icons 2024-12-02 12:30:09 +01:00
e028ff47f3 dedicated artisans page 2024-12-02 12:29:56 +01:00
de37ae1e7d handling search 2024-12-02 12:29:28 +01:00
6bcc5a0499 handling search & suggestions 2024-12-02 12:29:17 +01:00
41abd525f5 dedicated chantier page 2024-12-02 12:28:53 +01:00
17 changed files with 412 additions and 40 deletions

View File

@ -6,6 +6,7 @@ require_once(__DIR__ . '/includes/errorlog.php');
require_once(__DIR__ . '/includes/init.php');
require_once(__DIR__ . '/includes/post_types.php');
require_once(__DIR__ . '/includes/artisans.php');
require_once(__DIR__ . '/includes/chantiers.php');
require_once(__DIR__ . '/includes/admin.php');
require_once(__DIR__ . '/includes/taxonomy.php');
require_once(__DIR__ . '/includes/api.php');

View File

@ -71,15 +71,6 @@ jQuery(document).ready(function() {
add_action('post_submitbox_misc_actions', 'add_to_post_status_dropdown');
add_action('edit_form_after_title', function () {
// Vérifie si on est sur le bon post type
$screen = get_current_screen();
if ($screen && $screen->post_type === 'artisans') {
echo '<h1 class="admin-artisan-title">' . get_the_title() . '</h1>';
}
});
// Ajouter un filtre pour afficher les posts avec le statut 'offline'
add_filter('views_edit-artisans', function ($views) {
global $wpdb;

View File

@ -31,19 +31,20 @@ function build_search_artisan_posts_cards($request)
$taxonomyIds = explode(',', $StringifiedTaxonomyIds);
$taxonomyIds = array_map('intval', $taxonomyIds);
$search_value = sanitize_text_field($request->get_param('search')) ?? null;
$activePage = is_numeric($previousActivePage) ? $previousActivePage + 1 : 1;
$taxQuery = array(
array(
$taxQuery = [];
if ($taxonomy && !empty($taxonomyIds)) {
$taxQuery[] = array(
'taxonomy' => $taxonomy,
'terms' => $taxonomyIds,
'field' => 'term_id',
)
);
);
}
$metaQuery = [];
if ($localisation && $localisation !== 'all') {
$localisationArray = explode(',', $localisation); // Séparer les localisations par des virgules
$metaQuery[] = array(
@ -53,8 +54,6 @@ function build_search_artisan_posts_cards($request)
);
}
do_action('wpml_switch_language', $currentLanguage);
$args = array(
@ -62,12 +61,13 @@ function build_search_artisan_posts_cards($request)
"post_type" => "artisans",
"posts_per_page" => -1,
"paged" => $activePage,
"tax_query" => $taxQuery,
"tax_query" => $taxQuery,
// "meta_query" => [],
"meta_query" => $metaQuery,
's' => $search_value,
);
$newsPostsDatas = new WP_Query($args);
// write_log($newsPostsDatas->posts);
ob_start();
@ -95,6 +95,11 @@ function build_search_artisan_posts_cards($request)
$html_template = ob_get_clean();
if ($newsPostsDatas->found_posts === 0) {
$html_template = "<div class='no-results'><h3>" . __("Aucun résultat trouvé", "metiers-patrimoine-theme") . "</h3><p>" . __("Essayez d'ajouter un filtre supplémentaire pour trouver plus de résultats", "metiers-patrimoine-theme") . "</p></div>";
}
$response_data = array(
'html_template' => $html_template,
'total_posts_found' => $newsPostsDatas->found_posts,
@ -131,9 +136,11 @@ function debugQueryTest()
"status" => "publish",
"post_type" => "artisans",
"posts_per_page" => -1,
"tax_query" => $taxQuery,
"meta_query" => $metaQuery,
// "tax_query" => $taxQuery,
// "meta_query" => $metaQuery,
's' => "Atelier Schrauwen",
);
$newsPostsDatas = new WP_Query($args);
// write_log($newsPostsDatas->posts);
}
// debugQueryTest();
debugQueryTest();

View File

@ -54,3 +54,70 @@ function metiers_patrimoine_chantiers_post_updater($post_id)
wp_update_post($my_post);
}
add_action('acf/save_post', 'metiers_patrimoine_chantiers_post_updater', 20);
/* ---------------------------
CUSTOM CODE FOR TITLE
---------------------------*/
add_action('edit_form_after_title', function () {
// Vérifie si on est sur le bon post type
$screen = get_current_screen();
if ($screen && $screen->post_type === 'artisans') {
echo '<h1 class="admin-artisan-title">' . get_the_title() . '</h1>';
}
});
/* ---------------------------
CUSTOM CHANTIER META BOX AT THE END OF THE PAGE
---------------------------*/
add_action('add_meta_boxes', function () {
// Ajout de la metabox uniquement pour le post type 'artisans'
add_meta_box(
'admin_artisan_chantier_list', // ID de la metabox
'Chantiers réalisé par l\'entreprise', // Titre de la metabox
'render_custom_chantier_box_content', // Fonction de rendu
'artisans', // Post type
'normal', // Contexte
'low' // Priorité
);
});
/**
* Fonction de rendu du contenu de la metabox.
*/
function render_custom_chantier_box_content($post)
{
$args = array(
'post_type' => 'chantiers',
'posts_per_page' => -1,
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'artisan',
'value' => $post->ID,
'compare' => '=',
),
),
);
$chantiers = new WP_Query($args);
// Afficher les chantiers
if ($chantiers->have_posts()) {
echo '<ul>';
while ($chantiers->have_posts()) {
$chantiers->the_post();
$chantier_name = get_field('chantier_name');
echo '<li><a href="' . get_edit_post_link() . '"> <img src=' . get_stylesheet_directory_uri() . '/resources/img/icons/document-inspect.svg' . ' /> ' . $chantier_name . '</a></li>';
}
echo '</ul>';
} else {
echo '<p style="font-size: 1rem;">Aucun chantier pour cette entreprise.</p>';
}
}

72
includes/chantiers.php Normal file
View File

@ -0,0 +1,72 @@
<?php
/* ---------------------------
CUSTOM CHANTIER META BOX AT THE END OF THE PAGE
---------------------------*/
add_action('add_meta_boxes', function () {
// Ajout de la metabox uniquement pour le post type 'artisans'
add_meta_box(
'admin_chantier_artisan_ref', // ID de la metabox
'Artisan du chantier', // Titre de la metabox
'render_artisan_box_content', // Fonction de rendu
'chantiers', // Post type
'normal', // Contexte
'high' // Priorité
);
});
/**
* Fonction de rendu du contenu de la metabox.
*/
function render_artisan_box_content($post)
{
$args = array(
'post_type' => 'chantiers',
'posts_per_page' => -1,
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'artisan',
'value' => $post->ID,
'compare' => '=',
),
),
);
$chantiers = new WP_Query($args);
// Afficher les chantiers
if ($chantiers->have_posts()) {
echo '<ul>';
while ($chantiers->have_posts()) {
$chantiers->the_post();
$chantier_name = get_field('chantier_name');
echo '<li><a href="' . get_edit_post_link() . '"> <img src=' . get_stylesheet_directory_uri() . '/resources/img/icons/document-inspect.svg' . ' /> ' . $chantier_name . '</a></li>';
}
echo '</ul>';
} else {
echo '<p style="font-size: 1rem;">Ce chantier n\'est relié à aucun artisan</p>';
}
}
add_action('acf/render_field', function ($field) {
// Vérifiez si le champ est celui que vous voulez personnaliser
if ($field['key'] === 'field_6719065f58122') {
if (did_action('acf/render_field/key=field_6719065f58122') % 2 === 0) {
return;
}
$field['rendered'] = true;
$linked_post_id = get_field($field['key']);
if ($linked_post_id) {
$edit_link = get_edit_post_link($linked_post_id);
echo '<a href="' . esc_url($edit_link) . '" target="_blank" class="edit-fiche-artisan-link"><img src=' . get_stylesheet_directory_uri() . '/resources/img/icons/tools.svg' . ' /> Voir la fiche de l\'artisan </a>';
}
}
}, 10, 1);

View File

@ -1,3 +1,5 @@
@import './base/filters.css';
body.post-type-chantiers,
body.post-type-artisans {
#titlediv {
@ -255,3 +257,23 @@ body.post-type-artisans {
.block-editor-link-control__search-item-top {
word-break: break-all;
}
#admin_artisan_chantier_list {
h3 {
@apply pl-0 font-normal;
}
ul a {
@apply text-patrimoine-sante-securite text-lg flex items-center gap-2;
filter: brightness(80%);
img {
@apply w-6 h-6 object-contain filter-patrimoine-sante-securite;
}
}
}
.edit-fiche-artisan-link {
@apply pt-3 text-patrimoine-sante-securite !font-semibold flex items-center gap-2;
img {
@apply w-6 h-6 object-contain filter-patrimoine-sante-securite;
}
}

View File

@ -20,6 +20,8 @@
/* COMPONENTS */
@import './components/heading-box.css';
@import './components/previous-next-posts.css';
@import './components/nav.css';
@import './components/search-module.css';
/* BLOCKS */
@import './blocks/search-artisan-btn.css';

View File

@ -1,17 +1,21 @@
.page-redirector {
@apply px-12 py-12 rounded-xl mb-8;
@apply flex justify-between items-center;
@apply flex flex-col-reverse md:flex-row justify-between md:items-center;
h3 {
@apply pt-0 mt-0 !text-base uppercase tracking-widest;
}
.subtitle {
@apply !text-3xl font-bold max-w-xl;
@apply text-xl sm:text-2xl md:!text-3xl leading-tight font-bold max-w-xl;
}
.cta {
@apply mt-8 md:mt-6;
}
&__details-container {
}
&__thumbnail {
@apply max-w-80;
@apply max-w-44 md:max-w-80 mb-4 md:mb-0;
}
&--patrimoine {
@ -36,7 +40,7 @@
}
.page-redirector__thumbnail {
@apply max-w-40;
@apply max-w-20 md:max-w-40;
}
}
}

View File

@ -1,9 +1,17 @@
.metiers-patrimoine-page-container--repertoire-metiers,
.metiers-patrimoine-page-container--single-artisans {
.heading-box {
@apply !mt-8 pb-6;
@apply mt-12 lg:!mt-8 pb-6;
&__description {
@apply text-3xl max-w-screen-xl font-bold;
}
}
.heading-box--classic__page-icon {
@apply w-20;
@screen lg {
@apply w-28;
/* width: unset; */
}
}
}

View File

@ -0,0 +1,31 @@
.breadcrumbs_navigation {
ol {
@apply w-full inline-flex;
white-space: normal;
li:before {
@apply block absolute;
}
li:not(:nth-child(1)) a {
@apply block ml-3;
}
@media screen and (max-width: 800px) {
li {
/* flex-grow: 1; */
@apply w-fit;
}
li:not(:nth-child(1)) a {
flex-grow: 1;
width: 100px !important;
max-width: calc(100% - 1rem);
word-wrap: break-word;
white-space: normal;
}
li:nth-child(1) {
flex-grow: 0;
}
}
}
}

View File

@ -0,0 +1,19 @@
.artisan-search-bar {
@apply flex mt-6;
#search-input {
@apply block border border-solid !border-neutral-700 !rounded-full md:!rounded-r-none p-4 py-3 w-full;
}
button[type='submit'] {
@apply bg-patrimoine-sante-securite text-white shrink-0 flex justify-center items-center gap-3 rounded-full md:rounded-l-none px-6 py-3 focus-visible:ring-primary focus-visible:ring-2;
max-width: 300px;
outline: none !important;
transform: translateX(-1px);
&:active {
filter: saturate(70%) brightness(90%);
}
.search_icon {
@apply invert;
}
}
}

View File

@ -1,19 +1,31 @@
.artisans-posts {
@apply flex gap-4 pt-8;
@apply md:flex gap-4 pt-8;
&__grid {
@apply flex flex-col lg:grid grid-cols-1 lg:grid-cols-2 gap-6 w-full h-fit;
.no-results {
@apply col-span-2 text-center pt-4;
h3 {
@apply text-patrimoine-sante-securite;
}
p {
@apply text-neutral-900 tracking-wide;
}
}
}
.card-artisans {
/* @apply h-fit; */
}
}
/* .sidebar-container {
@apply pb-12;
} */
.metier-patrimoine-searchbar {
@apply w-80 lg:w-80 shrink-0;
@apply w-80 lg:w-80 shrink-0 h-fit sticky top-0;
h4 {
@apply my-0;
}
.checkbox-choice {
@apply pl-0 pt-1;
@apply flex flex-wrap;
@ -76,7 +88,7 @@
@apply block text-neutral-400 uppercase !text-base tracking-wider mb-4;
}
.search-radio-card {
@apply bg-white rounded-lg p-4 shadowed flex justify-between;
@apply bg-white rounded-lg p-4 shadowed flex justify-between cursor-pointer;
label {
@apply font-bold;
}
@ -130,6 +142,10 @@
@apply block;
/* @apply opacity-40; */
}
.search-radio-card--metiers {
@apply opacity-60;
}
}
/* HIDE ELEMENTS BATIMENTS FILTERS WHEN SEARCH IS ON METIERS */
@ -142,5 +158,24 @@
@apply block;
/* @apply opacity-40; */
}
.search-radio-card--building-elements {
@apply opacity-60;
}
}
.card-suggest-artisan {
@apply p-3 w-fit gap-3 bg-white shadowed
font-bold rounded-2xl flex items-center justify-center my-5;
transition: transform 0.3s;
&:after {
@apply content-[''] w-3 h-3 block bg-no-repeat bg-center bg-contain mt-1 mr-3;
background-image: url('../resources/img/pictogrammes/Homegrade_back_icon.svg');
rotate: 180deg;
}
&:hover {
@apply translate-x-2;
}
}
}

View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 0 0-3.375-3.375h-1.5A1.125 1.125 0 0 1 13.5 7.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H8.25m5.231 13.481L15 17.25m-4.5-15H5.625c-.621 0-1.125.504-1.125 1.125v16.5c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 0 0-9-9Zm3.75 11.625a2.625 2.625 0 1 1-5.25 0 2.625 2.625 0 0 1 5.25 0Z" />
</svg>

After

Width:  |  Height:  |  Size: 544 B

View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M11.42 15.17 17.25 21A2.652 2.652 0 0 0 21 17.25l-5.877-5.877M11.42 15.17l2.496-3.03c.317-.384.74-.626 1.208-.766M11.42 15.17l-4.655 5.653a2.548 2.548 0 1 1-3.586-3.586l6.837-5.63m5.108-.233c.55-.164 1.163-.188 1.743-.14a4.5 4.5 0 0 0 4.486-6.336l-3.276 3.277a3.004 3.004 0 0 1-2.25-2.25l3.276-3.276a4.5 4.5 0 0 0-6.336 4.486c.091 1.076-.071 2.264-.904 2.95l-.102.085m-1.745 1.437L5.909 7.5H4.5L2.25 3.75l1.5-1.5L7.5 4.5v1.409l4.26 4.26m-1.745 1.437 1.745-1.437m6.615 8.206L15.75 15.75M4.867 19.125h.008v.008h-.008v-.008Z" />
</svg>

After

Width:  |  Height:  |  Size: 723 B

View File

@ -21,6 +21,29 @@ function formatFormDataArray(formData) {
}
return formObjectDatas;
}
function formatSearchDataArray(formData) {
let formObjectDatas = {};
for (const [name, value] of formData) {
formObjectDatas[cleanName] = value;
}
return formObjectDatas;
}
function handleRadioCardClick(card) {
card.addEventListener('click', (e) => {
const radioInput = card.querySelector(
'input[type="radio"]'
);
radioInput.checked = true;
const artisanPosts = document.querySelector(
'.artisans-posts'
);
if (!artisanPosts) return;
artisanPosts.scrollIntoView({ behavior: 'smooth' });
});
}
async function hydrateFields(formObjectDatas) {
const currentLanguage = document
.querySelector('body')
@ -51,6 +74,29 @@ async function hydrateFields(formObjectDatas) {
// );
}
async function hydrateSearch(searchValue) {
const currentLanguage = document
.querySelector('body')
.getAttribute('current-language');
const response = await fetch(
`/wp-json/metiers-patrimoine-datas/v1/build/artisans?search=${searchValue}`
);
const searchArtisansDatas = await response.json();
console.log(searchArtisansDatas);
const artisansGrid = document.querySelector(
'.artisans-posts__grid'
);
artisansGrid.innerHTML =
searchArtisansDatas.html_template;
brochureRows.setAttribute(
'current-post-count',
brochuresDatas.total_posts_found
);
}
function handleHierarchicalTaxonomyCheckboxRelation(e) {
// If parent is checked, check all children
if (
@ -144,6 +190,38 @@ function handleFormChange(e) {
let formObjectDatas = formatFormDataArray(formData);
hydrateFields(formObjectDatas);
}
function handleSearchSubmit(e) {
e.preventDefault();
const searchBy = document.querySelector(
'.metier-patrimoine-searchbar__search-by'
);
const elementsBatimentsCheckbox = document.querySelector(
'#elements_batiments_checkbox'
);
const metiersCheckbox = document.querySelector(
'#metiers_checkbox'
);
metiersCheckbox.checked = false;
elementsBatimentsCheckbox.checked = false;
console.log(metiersCheckbox);
const form = e.target.closest('form');
const searchValue =
form.querySelector('#search-input').value;
hydrateSearch(searchValue);
const artisanPosts = document.querySelector(
'.artisans-posts'
);
if (!artisanPosts) return;
artisanPosts.scrollIntoView({ behavior: 'smooth' });
}
export default function dynamicSearch() {
const form = document.querySelector(
'.metier-patrimoine-searchform'
@ -153,4 +231,18 @@ export default function dynamicSearch() {
return;
}
form.addEventListener('change', handleFormChange);
const searchRadioCards = document.querySelectorAll(
'.search-radio-card'
);
searchRadioCards.forEach((card) => {
handleRadioCardClick(card);
});
const searchForm = document.querySelector(
'.artisan-search-bar'
);
searchForm.addEventListener('submit', handleSearchSubmit);
}

View File

@ -8,9 +8,7 @@ $company_members = get_field('company_members', $postID);
$phoneNumber = get_field('phone_number', $postID);
$faxNumber = get_field('fax_number', $postID);
$formattedPhoneNumber = preg_replace('/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/', '+$1$2$3$4$5', $phoneNumber);
write_log('Formatted phone: ' . $formattedPhoneNumber);
write_log($phoneNumber);
write_log($formattedPhoneNumber);
$formattedFaxNumber = preg_replace('/^(\+\d{2})(\d{3})(\d{2})(\d{2})(\d{2})/', '$1 $2 $3 $4 $5', $faxNumber);
$email = get_field('email', $postID);
$website = get_field('website', $postID);

View File

@ -62,12 +62,12 @@ $pageIcon = get_field('page_icon', get_queried_object_id()) ?? null;
<fieldset class="metier-patrimoine-searchbar__search-by">
<legend><?php echo __("Rechercher par", "metiers-patrimoine-theme") ?></legend>
<div class="search-radio-card">
<div class="search-radio-card search-radio-card--building-elements">
<label for="building_elements"><?php echo __("Éléments du bâtiment", "metiers-patrimoine-theme") ?></label>
<input type="radio" id="elements_batiments_checkbox" name="search_by" value="elementsbatiments" />
</div>
<div class="search-radio-card">
<div class="search-radio-card search-radio-card--metiers">
<label for="job_types"><?php echo __("Métiers du patrimoine", "metiers-patrimoine-theme") ?></label>
<input type="radio" id="metiers_checkbox" name="search_by" value="metiers" />
</div>
@ -155,7 +155,6 @@ $pageIcon = get_field('page_icon', get_queried_object_id()) ?? null;
</fieldset>
<fieldset class="metier-patrimoine-searchbar__geographic-filters">
<div class="fieldset-titling">
<img class="fieldset-icon" src="<?php echo get_stylesheet_directory_uri() . '/resources/img/pictogrammes/Homegrade_repertoire-elements.svg' ?>" alt=''>
<h4 class="filter-title"><?php echo __("Localisation", "metiers-patrimoine-theme") ?></h4>
@ -182,10 +181,28 @@ $pageIcon = get_field('page_icon', get_queried_object_id()) ?? null;
</fieldset>
</form>
<!-- search bar -->
<form class="artisan-search-bar">
<!-- <label for="search-input" class="sr-only"><?php echo __("Rechercher", "metiers-patrimoine-theme") ?></label> -->
<input type="search" id="search-input" placeholder="<?php echo __("Rechercher", "metiers-patrimoine-theme") ?>" />
<button class="search-button" type="submit">
<img class="search_icon" src='<?php echo get_template_directory_uri() ?>/resources/img/graphic-assets/search-icon.svg' alt="Lancer la recherche">
</button>
</form>
<?php
$suggestArtisanPageId = 309;
$suggestArtisanPageIcon = get_field('page_icon', $suggestArtisanPageId) ?? null;
?>
<a class="card-suggest-artisan card block" href="<?php echo get_the_permalink($suggestArtisanPageId) ?>">
<img class="search-artisan-btn__page-icon" src="<?php echo $suggestArtisanPageIcon['sizes']['medium_large'] ?> " alt="">
<p><?php echo __("Communiquer une entreprise ou un artisan", "metiers-patrimoine-theme") ?></p>
</a>
</aside>
<div class="artisans-posts__grid">
<div class=" artisans-posts__grid">
<?php
$initialPosts = new WP_Query([
"status" => "publish",