diff --git a/includes/forms.php b/includes/forms.php
index f4a6191..dfbb79a 100644
--- a/includes/forms.php
+++ b/includes/forms.php
@@ -1,38 +1,5 @@
type != 'checkbox' || strpos($field->inputName, 'publication-list') === false) {
- continue;
- }
-
- // you can add additional parameters here to alter the posts that are retrieved
- // more info: http://codex.wordpress.org/Template_Tags/get_posts
- $brochures_query = new WP_Query(array(
- 'post_type' => 'brochures',
- 'posts_per_page' => -1,
- 'post_status' => 'publish',
- ));
-
- // $posts = get_posts('numberposts=-1&post_status=publish&post_type=brochures');
-
- $choices = array();
-
- foreach ($brochures_query->posts as $post) {
- $choices[] = array('text' => $post->post_title, 'value' => $post->post_title);
- }
-
- // update 'Select a Post' to whatever you'd like the instructive option to be
- $field->placeholder = 'Select a Post';
- $field->choices = $choices;
- }
-
- return $form;
-}
+require_once(__DIR__ . '/forms/form-OrderPaper.php');
diff --git a/includes/forms/__form-OrderPaperOld.php b/includes/forms/__form-OrderPaperOld.php
new file mode 100644
index 0000000..d8816b5
--- /dev/null
+++ b/includes/forms/__form-OrderPaperOld.php
@@ -0,0 +1,124 @@
+ 'brochures',
+ 'posts_per_page' => -1,
+ 'post_status' => 'publish',
+ ));;
+ $this->brochures_query = $post_query;
+
+ $choices = [];
+ foreach ($this->brochures_query->posts as $post) {
+ $choices[] = ['text' => $post->post_title];
+ }
+ }
+
+ public function get_form_editor_field_title()
+ {
+ return esc_attr__('Commande de publications papier', '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 $choices = [
+ ['text' => 'Publication 1'],
+ ['text' => 'Publication 2'],
+ ['text' => 'Publication 3'],
+ ];
+ public function is_value_submission_array()
+ {
+ return true;
+ }
+
+ public function get_field_input($form, $value = '', $entry = null)
+ {
+
+ // if ($this->is_form_editor()) {
+ // return '';
+ // }
+ $form_id = $form['id'];
+ $is_entry_detail = $this->is_entry_detail();
+ $id = (int) $this->id;
+
+ write_log($id);
+ write_log($form_id);
+
+ ob_start();
+?>
+
+
+
+
+choices as $course) {
+ foreach ($this->delivery_days as $day) {
+ $table_value[$course['text']][$day] = $value[$counter++];
+ }
+ }
+ return $table_value;
+ }
+ }
+ GF_Fields::register(new OrderPaperPublications());
+}
diff --git a/includes/forms/__form-food-delivery.php b/includes/forms/__form-food-delivery.php
new file mode 100644
index 0000000..627311b
--- /dev/null
+++ b/includes/forms/__form-food-delivery.php
@@ -0,0 +1,146 @@
+ 'Food Choice 1' ],
+ [ 'text' => 'Food Choice 2' ],
+ [ 'text' => 'Food Choice 3' ],
+ ];
+
+ private $delivery_days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'];
+
+ public function get_form_editor_field_title() {
+ return esc_attr__('Food Delivery', 'txtdomain');
+ }
+
+ public function get_form_editor_button() {
+ return [
+ 'group' => 'advanced_fields',
+ 'text' => $this->get_form_editor_field_title(),
+ ];
+ }
+
+ 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) {
+ if ($this->is_form_editor()) {
+ return '';
+ }
+
+ $id = (int) $this->id;
+
+ if ($this->is_entry_detail()) {
+ $table_value = maybe_unserialize($value);
+ } else {
+ $table_value = $this->translateValueArray($value);
+ }
+
+ $table = '';
+
+ return $table;
+ }
+
+ private function translateValueArray($value) {
+ if (empty($value)) {
+ return [];
+ }
+ $table_value = [];
+ $counter = 0;
+ foreach ($this->choices as $course) {
+ foreach ($this->delivery_days as $day) {
+ $table_value[$course['text']][$day] = $value[$counter++];
+ }
+ }
+ 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 prettyListOutput($value) {
+ $str = '';
+ foreach ($value as $course => $days) {
+ $week = '';
+ foreach ($days as $day => $delivery_number) {
+ if (!empty($delivery_number)) {
+ $week .= '- ' . $day . ': ' . $delivery_number . '
';
+ }
+ }
+ // Only add week if there were any requests at all
+ if (!empty($week)) {
+ $str .= '' . $course . '
';
+ }
+ }
+ $str .= '
';
+ return $str;
+ }
+
+ 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 $value;
+ }
+ $str = $this->prettyListOutput($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->prettyListOutput($value);
+ }
+
+ public function is_value_submission_empty($form_id) {
+ $value = rgpost('input_' . $this->id);
+ foreach ($value as $input) {
+ if (strlen(trim($input)) > 0) {
+ return false;
+ }
+ }
+ return true;
+ }
+ }
+ GF_Fields::register(new FoodDelivery());
+}
\ No newline at end of file
diff --git a/includes/forms/__form-populate.php b/includes/forms/__form-populate.php
new file mode 100644
index 0000000..e439cd3
--- /dev/null
+++ b/includes/forms/__form-populate.php
@@ -0,0 +1,38 @@
+type != 'checkbox' || strpos($field->inputName, 'publication-list') === false) {
+ continue;
+ }
+
+ // you can add additional parameters here to alter the posts that are retrieved
+ // more info: http://codex.wordpress.org/Template_Tags/get_posts
+ $brochures_query = new WP_Query(array(
+ 'post_type' => 'brochures',
+ 'posts_per_page' => -1,
+ 'post_status' => 'publish',
+ ));
+
+ // $posts = get_posts('numberposts=-1&post_status=publish&post_type=brochures');
+
+ $choices = array();
+
+ foreach ($brochures_query->posts as $post) {
+ $choices[] = array('text' => $post->post_title, 'value' => $post->post_title);
+ }
+
+ // update 'Select a Post' to whatever you'd like the instructive option to be
+ $field->placeholder = 'Select a Post';
+ $field->choices = $choices;
+ }
+
+ return $form;
+}
diff --git a/includes/forms/form-OrderPaper.php b/includes/forms/form-OrderPaper.php
new file mode 100644
index 0000000..acc43ea
--- /dev/null
+++ b/includes/forms/form-OrderPaper.php
@@ -0,0 +1,162 @@
+buildChoices();
+ // }
+
+ private function buildChoices()
+ {
+ $brochures_query = new WP_Query(array(
+ 'post_type' => 'brochures',
+ 'posts_per_page' => -1,
+ 'post_status' => 'publish',
+ ));
+ $choices = [];
+
+ foreach ($brochures_query->posts as $key => $post) {
+ array_push($choices, ['text' => $post->post_title, 'slug' => $post->post_name]);
+ }
+ $this->choices = $choices;
+ }
+
+
+
+ public function get_form_editor_field_title()
+ {
+ return esc_attr__('Commande de publications papier', '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 $choices = [
+ // ['text' => 'Publication 1'],
+ // ['text' => 'Publication 2'],
+ // ['text' => 'Publication 3'],
+ // ];
+
+ 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-form-order-paper.php';
+ $table = ob_get_clean();
+
+
+ return $table;
+ }
+
+ private function translateValueArray($value)
+ {
+ $this->buildChoices();
+
+ $table_value = [];
+ $counter = 0;
+
+ foreach ($this->choices as $brochure) {
+ $table_value[$brochure['text']]['quantity_fr'] = $value[$counter] ?? 0;
+ $table_value[$brochure['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 = '';
+
+ foreach ($value as $brochure => $quantities) {
+
+ $brochureOrderAmount = null;
+
+
+ if ($quantities["quantity_fr"]) {
+ $brochureOrderAmount .= '- ' . __("Quantité FR: ", "homegrade-theme__texte-fonctionnel") . '' . $quantities["quantity_fr"] . '
';
+ }
+ if ($quantities["quantity_nl"]) {
+ $brochureOrderAmount .= '- ' . __("Quantité NL: ", "homegrade-theme__texte-fonctionnel") . '' . $quantities["quantity_nl"] . '
';
+ }
+
+ if (!$brochureOrderAmount) continue;
+
+
+ if (!empty($brochureOrderAmount)) {
+ $brochureOrderPreviewHtml .= '' . $brochure . '
' . $brochureOrderAmount . '
';
+ }
+ }
+ $brochureOrderPreviewHtml .= '
';
+ 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 OrderPaperPublications());
+}
diff --git a/includes/forms/template-form-order-paper.php b/includes/forms/template-form-order-paper.php
new file mode 100644
index 0000000..fa0fe91
--- /dev/null
+++ b/includes/forms/template-form-order-paper.php
@@ -0,0 +1,21 @@
+
+
+
\ No newline at end of file
diff --git a/resources/css/components/forms.css b/resources/css/components/forms.css
index 4908ff4..76cab3e 100644
--- a/resources/css/components/forms.css
+++ b/resources/css/components/forms.css
@@ -173,3 +173,30 @@ form:not(.metabox-location-side):not(.metabox-location-normal):not(
@apply max-w-5xl !mx-auto;
}
}
+
+/* .publications-amount-fr,
+.publications-amount-nl {
+ @apply !hidden;
+} */
+
+.field-order-paper-publications {
+ @apply !grid !grid-cols-2 gap-x-12 gap-y-2;
+
+ .brochure-order-field {
+ @apply flex justify-end gap-3 items-center;
+ label {
+ @apply block !mr-auto;
+ }
+
+ .publications-amount-fr,
+ .publications-amount-nl {
+ input {
+ @apply h-2 !w-12;
+ }
+ #publications-amount__label-nl,
+ #publications-amount__label-fr {
+ @apply !text-neutral-600 uppercase !text-sm text-center;
+ }
+ }
+ }
+}