refining custom orderPaper form

This commit is contained in:
Antoine M 2024-04-23 09:30:51 +02:00
parent d4f48f5577
commit e3584c7e5b
9 changed files with 376 additions and 112 deletions

View File

@ -1,62 +0,0 @@
##########################
# SCRIPT DE DÉPLOIEMENT
##########################
include .env_prod
# include .env_dev
RED=\033[0;31m
GREEN=\033[0;32m
YELLOW=\033[0;33m
NC=\033[0m # No Color
deploy: pull-media deploy-theme deploy-plugin
deploy-theme:
@echo "$(GREEN)####Synchronisation des Themes $(NC)"
@rsync -avhp -e 'ssh' ./ $(HOST):$(THEMES_PATH)/$(THEME_FOLDER_NAME) --delete --exclude 'node_modules' --exclude 'Makefile' --exclude 'Makefile_dev' --exclude '.env' --exclude '.env_prod' --exclude '.env_dev' --exclude '.git'
deploy-plugin:
@echo "$(GREEN)####Synchronisation du plugin $(NC)"
@rsync -avhp -e 'ssh' ../../plugins/$(PLUGIN_FOLDER_NAME) $(HOST):$(PLUGINS_PATH) --delete --exclude 'node_modules' --exclude 'Makefile' --exclude 'Makefile_dev' --exclude '.env' --exclude '.env_prod' --exclude '.env_dev' --exclude '.git'
deploy-full-content:
@echo "$(GREEN)####Synchronisation de tout le wp-content$(NC)"
@rsync -avhp -e 'ssh' ../../ $(HOST):$(CONTENT_PATH) --delete --exclude 'node_modules' --exclude 'Makefile' --exclude 'Makefile_dev' --exclude '.env' --exclude '.env_prod' --exclude '.env_dev' --exclude '.git'
pull-media:
@echo "$(GREEN)####Pull des médias $(NC)"
@rsync -avhp -e 'ssh' $(HOST):$(UPLOADS_PATH) ../../uploads --delete
pull-plugins:
@echo "$(GREEN)####Pull des Plugins $(NC)"
@rsync -avhp -e 'ssh' $(HOST):$(PLUGINS_PATH) ../../plugins --delete
bundle:
@echo "$(GREEN)####BUNDLE $(NC)"
@rsync -avh ./* ../$(THEME_DIST_NAME) --delete \
--exclude '.env' \
--exclude '.env_dev' \
--exclude '.env_prod' \
--exclude 'node_modules' \
--exclude 'Makefile' \
--exclude 'Makefile_dev' \
--exclude '.git' \
--exclude '.gitignore' \
--exclude 'composer.json' \
maintenance-on:
@echo "$(YELLOW)####MISE EN MAINTENANCE $(NC)"
@ssh -p $(PORT) $(HOST) "cd $(CONTENT_PATH); cd ..; echo '<?php \$$upgrading = time();' >> .maintenance "
maintenance-off:
@echo "$(GREEN)####MISE EN LIGNE / SUPPRESSION DU MAINTENANCE $(NC)"
@ssh -p $(PORT) $(HOST) "cd $(CONTENT_PATH); cd ..; rm .maintenance "
test-connect:
@echo "$(GREEN)####SIMULATION — TEST DE CONNEXION $(NC)"
@ssh -p $(PORT) $(HOST) "cd $(CONTENT_PATH); pwd"
test-deploy:
@echo "$(RED)####SIMULATION — Synchronisation RSYNC DES FICHIERS $(NC)"
@rsync -avhpn -e 'ssh' ./ $(HOST):$(THEMES_PATH)/$(THEME_FOLDER_NAME)/test --delete --exclude 'node_modules' --exclude 'Makefile' --exclude 'Makefile_dev' --exclude '.git' --exclude '.env' --exclude '.env_prod' --exclude '.env_dev'

View File

@ -2,4 +2,5 @@
require_once(__DIR__ . '/forms/form-OrderPaper.php');
require_once(__DIR__ . '/forms/field-OrderBrochureList.php');
require_once(__DIR__ . '/forms/field-OrderDocumentsList.php');

View File

@ -1,9 +1,9 @@
<?php
if (class_exists('GF_Field')) {
class OrderPaperPublications extends GF_Field_Select
class OrderBrochureList extends GF_Field_Select
{
public $type = 'order_paper_publications';
public $type = 'order_brochures_list';
// public function __construct()
// {
@ -25,13 +25,8 @@ if (class_exists('GF_Field')) {
));
$choices = [];
$sortedBrochuresPosts = sort_posts_per_thematiques_priority($brochures_query);
foreach ($sortedBrochuresPosts->posts as $key => $post) {
array_push($choices, ['text' => $post->post_title, 'slug' => $post->post_name, 'ID' => $post->ID]);
}
@ -40,7 +35,7 @@ if (class_exists('GF_Field')) {
public function get_form_editor_field_title()
{
return esc_attr__('Commande de publications papier', 'txtdomain');
return esc_attr__('Listes des brochures commandable', 'txtdomain');
}
public function get_form_editor_button()
{
@ -84,7 +79,7 @@ if (class_exists('GF_Field')) {
$id = $this->id;
ob_start();
include 'template-form-order-paper.php';
include 'template-field-order-brochures.php';
$table = ob_get_clean();
@ -168,5 +163,5 @@ if (class_exists('GF_Field')) {
return $this->PrettyListBrochureOrder($value);
}
}
GF_Fields::register(new OrderPaperPublications());
GF_Fields::register(new OrderBrochureList());
}

View File

@ -0,0 +1,178 @@
<?php
if (class_exists('GF_Field')) {
class OrderDocumentList extends GF_Field_Select
{
public $type = 'order_documents_list';
public $choices = [
['text' => 'Synthèse des primes'],
['text' => 'Publication 2'],
['text' => 'Publication 3'],
];
// public $choices = [
// [
// 'text' => 'Synthèse des primes',
// 'slug' => "the post name",
// 'ID' => 24
// ],
// [
// 'text' => 'Document 2',
// 'slug' => "the post name",
// 'ID' => 24
// ],
// ];
private function buildChoices()
{
$choices = [
[
'text' => 'La synthèse des primes',
'description' => __("Ce document informe sur les incitants financiers à lachat et à la rénovation des logements en Région de Bruxelles-Capitale, dont les primes RENOLUTION, le crédit ECORENO, la subvention petit patrimoine, la prime gaz, les certificats verts...", "homegrade-theme__texte-fonctionnel"),
'slug' => "the post name",
'ID' => 24
],
[
'text' => 'Document 2',
'slug' => "the post name",
'ID' => 24
],
];
$this->choices = $choices;
}
public function get_form_editor_field_title()
{
return esc_attr__('Listes des documents commandables', 'txtdomain');
}
public function get_form_editor_button()
{
return [
'group' => 'advanced_fields',
'text' => $this->get_form_editor_field_title(),
];
}
public function get_form_editor_field_icon()
{
return 'gform-icon--multi-select';
}
public function get_form_editor_field_settings()
{
return [
'label_setting',
'choices_setting',
'description_setting',
'rules_setting',
'error_message_setting',
'css_class_setting',
'conditional_logic_field_setting'
];
}
public function is_value_submission_array()
{
return true;
}
public function get_field_input($form, $value = '', $entry = null)
{
// $this->buildChoices();
$form_id = $form['id'];
$id = $this->id;
ob_start();
include 'template-field-order-documents.php';
$table = ob_get_clean();
return $table;
}
private function translateValueArray($value)
{
$this->buildChoices();
$table_value = [];
$counter = 0;
foreach ($this->choices as $document) {
$table_value[$document['text']]['quantity_fr'] = $value[$counter] ?? 0;
$table_value[$document['text']]['quantity_nl'] = $value[$counter + 1] ?? 0;
$counter += 2;
}
return $table_value;
}
public function get_value_save_entry($value, $form, $input_name, $lead_id, $lead)
{
if (empty($value)) {
$value = '';
} else {
$table_value = $this->translateValueArray($value);
$value = serialize($table_value);
}
return $value;
}
private function PrettyListBrochureOrder($value)
{
$brochureOrderPreviewHtml = '<ul>';
foreach ($value as $brochure => $quantities) {
$brochureOrderAmount = null;
if ($quantities["quantity_fr"]) {
$brochureOrderAmount .= '<li>' . __("Quantité FR: ", "homegrade-theme__texte-fonctionnel") . '<span class="brochure_quantity">' . $quantities["quantity_fr"] . '</span></li>';
}
if ($quantities["quantity_nl"]) {
$brochureOrderAmount .= '<li>' . __("Quantité NL: ", "homegrade-theme__texte-fonctionnel") . '<span class="brochure_quantity">' . $quantities["quantity_nl"] . '</span></li>';
}
if (!$brochureOrderAmount) continue;
if (!empty($brochureOrderAmount)) {
$brochureOrderPreviewHtml .= '<li><h3>' . $brochure . '</h3><ul class="days">' . $brochureOrderAmount . '</ul></li>';
}
}
$brochureOrderPreviewHtml .= '</ul>';
return $brochureOrderPreviewHtml;
}
public function get_value_entry_list($value, $entry, $field_id, $columns, $form)
{
return __('Enter details to see delivery details', 'txtdomain');
}
public function get_value_entry_detail($value, $currency = '', $use_text = false, $format = 'html', $media = 'screen')
{
$value = maybe_unserialize($value);
if (empty($value)) {
return;
}
$str = $this->PrettyListBrochureOrder($value);
return $str;
}
public function get_value_merge_tag($value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br)
{
return $this->PrettyListBrochureOrder($value);
}
}
GF_Fields::register(new OrderDocumentList());
}

View File

@ -0,0 +1,47 @@
<?php
?>
<fieldset class="field-order-paper-publications">
<?php
?>
<?php foreach ($this->choices as $index => $brochurePost) : ?>
<?php
$thematique = getPostMainThematique($brochurePost['ID']);
$thematiqueCover = get_field('taxonomy_pictures', "thematiques_" . $thematique->term_id);
?>
<div class=" gchoice brochure-order-field">
<div class="thematique-tag thematique-tag--<?php echo $thematique->slug ?>">
<?php if ($thematiqueCover && $thematiqueCover['icon']) : ?>
<img class="thematique-icon" src="<?php echo $thematiqueCover['icon']['url'] ?>" alt="">
<?php endif; ?>
<p>
<?php echo $thematique->name ?>
</p>
</div>
<legend class="brochure-legend gform-field-label gform-field-label--type-inline"><?php echo $brochurePost['text'] ?></legend>
<a class="preview-brochure" href="<?php echo get_the_permalink($brochurePost['ID']) ?>" target="_blank"><?php echo __("Voir la brochure", "homegrade-theme__texte-fonctionnel") ?></a>
<div class="inputs-container">
<div class="publications-amount-fr">
<label id="publications-amount__label-fr" for="<?php echo 'input_' . $id . '[]' ?>" title="<?php echo __("Quantité désiré de brochures en Français", "homegrade-theme__texte-fonctionnel") ?>">fr</label>
<input type="number" size="1" min="0" name="<?php echo 'input_' . $id . '[]' ?>" />
</div>
<div class="publications-amount publications-amount-nl">
<label id="publications-amount__label-nl" for="<?php echo 'input_' . $id . '[]' ?>" title="<?php echo __("Quantité désiré de brochures en Néerlandais", "homegrade-theme__texte-fonctionnel") ?>">nl</label>
<input type="number" size="1" min="0" name="<?php echo 'input_' . $id . '[]' ?>" />
</div>
</div>
</div>
<div class="gchoice brochure-order-field">
</div>
<?php endforeach; ?>
</fieldset>

View File

@ -0,0 +1,55 @@
<?php
?>
<fieldset class="field-order-paper-publications">
<?php
?>
<?php foreach ($this->choices as $index => $document) : ?>
<?php
$test = get_term(143, 'thematiques');
$thematiqueCover = get_field('taxonomy_pictures', "thematiques_" . "143");
write_log($thematiqueCover);
?>
<div class=" gchoice brochure-order-field">
<div class="thematique-tag thematique-tag--general">
<?php if ($thematiqueCover && $thematiqueCover['icon']) : ?>
<img class="thematique-icon" src="<?php echo $thematiqueCover['icon']['url'] ?>" alt="">
<?php endif; ?>
<p>
<?php echo __("Autre", "homegrade-theme__texte-fonctionnel") ?>
</p>
</div>
<legend class="brochure-legend gform-field-label gform-field-label--type-inline"><?php echo $document['text'] ?></legend>
<a class="preview-brochure" href="<?php echo get_the_permalink($document['ID']) ?>" target="_blank"><?php echo __("Voir le document", "homegrade-theme__texte-fonctionnel") ?></a>
<div class="inputs-container">
<div class="publications-amount-fr">
<label id="publications-amount__label-fr" for="<?php echo 'input_' . $id . '[]' ?>" title="<?php echo __("Quantité désiré de brochures en Français", "homegrade-theme__texte-fonctionnel") ?>">fr</label>
<input type="number" size="1" min="0" name="<?php echo 'input_' . $id . '[]' ?>" />
</div>
<div class="publications-amount publications-amount-nl">
<label id="publications-amount__label-nl" for="<?php echo 'input_' . $id . '[]' ?>" title="<?php echo __("Quantité désiré de brochures en Néerlandais", "homegrade-theme__texte-fonctionnel") ?>">nl</label>
<input type="number" size="1" min="0" name="<?php echo 'input_' . $id . '[]' ?>" />
</div>
</div>
<?php if ($document['value']) : ?>
<p class="legend"><?php echo $document['value'] ?></p>
<?php endif; ?>
</div>
<div class="gchoice brochure-order-field">
</div>
<?php endforeach; ?>
</fieldset>

View File

@ -1,37 +0,0 @@
<?php
?>
<fieldset class="field-order-paper-publications">
<?php
?>
<?php foreach ($this->choices as $index => $brochurePost) : ?>
<?php
$thematique = getPostMainThematique($brochurePost['ID']);
$thematiqueCover = get_field('taxonomy_pictures', "thematiques_" . $thematique->term_id);
?>
<div class=" gchoice brochure-order-field">
<div class="thematique-tag thematique-tag--<?php echo $thematique->slug ?>">
<?php if ($thematiqueCover && $thematiqueCover['icon']) : ?>
<img class="thematique-icon" src="<?php echo $thematiqueCover['icon']['url'] ?>" alt="">
<?php endif; ?>
<p>
<?php echo $thematique->name ?>
</p>
</div>
<legend class="brochure-legend gform-field-label gform-field-label--type-inline"><?php echo $brochurePost['text'] ?></legend>
<a class="preview-brochure" href="<?php echo get_the_permalink($brochurePost['ID']) ?>" target="_blank">voir la brochure</a>
<div class="publications-amount-fr">
<label id="publications-amount__label-fr" for="<?php echo 'input_' . $id . '[]' ?>" title="<?php echo __("Quantité désiré de brochures en Français", "homegrade-theme__texte-fonctionnel") ?>">fr</label>
<input type="number" size="1" min="0" name="<?php echo 'input_' . $id . '[]' ?>" />
</div>
<div class="publications-amount publications-amount-nl">
<label id="publications-amount__label-nl" for="<?php echo 'input_' . $id . '[]' ?>" title="<?php echo __("Quantité désiré de brochures en Néerlandais", "homegrade-theme__texte-fonctionnel") ?>">nl</label>
<input type="number" size="1" min="0" name="<?php echo 'input_' . $id . '[]' ?>" />
</div>
</div>
<?php endforeach; ?>
</fieldset>

View File

@ -112,3 +112,67 @@
.block-editor-link-control__search-item-top {
word-break: break-all;
}
.field-order-paper-publications {
@apply !grid gap-x-12 gap-y-2;
.brochure-order-field {
@apply grid justify-end gap-3 items-center;
grid-template-columns: auto 1fr 1fr auto;
.thematique-tag,
legend {
@apply mt-6;
}
.thematique-tag {
@apply !py-1 !px-4 !rounded-lg mr-4 flex items-center shrink-0;
line-height: 1.7;
}
.thematique-icon {
@apply w-8 mr-3 my-2;
}
legend {
@apply block ml-0 !mr-auto !font-normal;
font-weight: revert !important;
}
.preview-brochure {
@apply !text-neutral-700 flex justify-center items-center w-fit mx-auto;
&:after {
content: ' ';
@apply w-4 h-4 block ml-3 bg-no-repeat bg-center bg-contain;
background-image: url('../resources/img/graphic-assets/icone-external-link.svg');
}
}
.inputs-container {
@apply flex gap-4;
}
.publications-amount-fr,
.publications-amount-nl {
label {
@apply block mx-auto;
}
input[type='number'] {
@apply h-2 !w-16 !py-5;
}
#publications-amount__label-nl,
#publications-amount__label-fr {
@apply !text-neutral-600 uppercase !text-sm text-center;
}
}
}
}
#gform_wrapper_18 {
@apply max-w-screen-lg;
input[type='submit'] {
@apply !mx-auto mt-6;
}
.gsection_description {
@apply pt-2;
}
.gfield--type-section {
border-bottom: 1px solid !important;
@apply !border-neutral-400;
}
}

View File

@ -185,7 +185,8 @@ form:not(.metabox-location-side):not(.metabox-location-normal):not(
@apply !grid gap-x-12 gap-y-2;
.brochure-order-field {
@apply flex justify-end gap-3 items-center max-w-screen-md;
@apply grid justify-end gap-3 items-center;
grid-template-columns: auto 1fr 1fr auto;
.thematique-tag,
legend {
@apply mt-6;
@ -202,13 +203,16 @@ form:not(.metabox-location-side):not(.metabox-location-normal):not(
font-weight: revert !important;
}
.preview-brochure {
@apply !text-neutral-700 flex justify-center items-center;
@apply !text-neutral-700 flex justify-center items-center w-fit mx-auto;
&:after {
content: ' ';
@apply w-4 h-4 block ml-3 bg-no-repeat bg-center bg-contain;
background-image: url('../resources/img/graphic-assets/icone-external-link.svg');
}
}
.inputs-container {
@apply flex gap-4;
}
.publications-amount-fr,
.publications-amount-nl {
@ -223,5 +227,24 @@ form:not(.metabox-location-side):not(.metabox-location-normal):not(
@apply !text-neutral-600 uppercase !text-sm text-center;
}
}
.legend {
@apply col-start-2 col-span-2 text-neutral-500;
line-height: 1.5;
}
}
}
#gform_wrapper_18 {
@apply max-w-screen-lg;
input[type='submit'] {
@apply !mx-auto mt-6;
}
.gsection_description {
@apply pt-2;
}
.gfield--type-section {
border-bottom: 1px solid !important;
@apply !border-neutral-300 pb-4;
}
}