From dd194cbad84701b4d4453327ee6f6b07f16366f2 Mon Sep 17 00:00:00 2001 From: Laurent GAY Date: Fri, 10 May 2024 12:06:39 +0200 Subject: [PATCH] =?UTF-8?q?1141=20image=20par=20d=C3=A9faut=20dans=20les?= =?UTF-8?q?=20formulaires=20bazar=20(#1143)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add default image select in image component * extract from forumlar & save default image in jpg file * use default image if need in bazar item * remove default image & refresh it * fix(imageField): declare new properties to avoid deprecated errors * create style class for remove button default image + rename PHP method (camelCase) + check max size of default image * Update tools/bazar/presentation/javascripts/form-edit-template/fields/image.js Co-authored-by: Jérémy Dufraisse * Update tools/bazar/fields/ImageField.php Co-authored-by: Jérémy Dufraisse --------- Co-authored-by: Florian Schmitt Co-authored-by: Jérémy Dufraisse --- includes/services/DbService.php | 27 ++-- tools/bazar/fields/ImageField.php | 10 +- tools/bazar/lang/bazarjs_en.inc.php | 1 + tools/bazar/lang/bazarjs_fr.inc.php | 1 + .../form-edit-template/fields/image.js | 26 ++-- .../form-edit-template/form-builder-helper.js | 17 ++ .../form-edit-template/form-edit-template.js | 65 +++++++- .../styles/form-edit-template.css | 11 +- tools/bazar/services/BazarListService.php | 33 ++++ tools/bazar/services/FormManager.php | 147 ++++++++++++++++-- 10 files changed, 297 insertions(+), 41 deletions(-) diff --git a/includes/services/DbService.php b/includes/services/DbService.php index 9e2017079..cf92b9663 100644 --- a/includes/services/DbService.php +++ b/includes/services/DbService.php @@ -65,6 +65,14 @@ public function getQueryLog() return $this->queryLog; } + public function addQueryLog($query, $time) + { + $this->queryLog[] = array( + 'query' => $query, + 'time' => $time + ); + } + public function prefixTable($tableName) { return ' ' . $this->params->get('table_prefix') . $tableName . ' '; @@ -87,18 +95,15 @@ public function query($query) $start = $this->getMicroTime(); } - if (!$result = mysqli_query($this->link, $query)) { - throw new Exception('Query failed: ' . $query . ' (' . mysqli_error($this->link) . ')'); - } - - if ($this->params->get('debug')) { - $time = $this->getMicroTime() - $start; - $this->queryLog[] = array( - 'query' => $query, - 'time' => $time - ); + try { + if (!$result = mysqli_query($this->link, $query)) { + throw new Exception('Query failed: ' . $query . ' (' . mysqli_error($this->link) . ')'); + } + } finally { + if ($this->params->get('debug')) { + $this->addQueryLog($query, $this->getMicroTime() - $start); + } } - return $result; } diff --git a/tools/bazar/fields/ImageField.php b/tools/bazar/fields/ImageField.php index 19642b67e..f648c8656 100644 --- a/tools/bazar/fields/ImageField.php +++ b/tools/bazar/fields/ImageField.php @@ -17,12 +17,14 @@ class ImageField extends FileField protected $imageHeight; protected $imageWidth; protected $imageClass; + protected $imageDefault; protected const FIELD_THUMBNAIL_HEIGHT = 3; protected const FIELD_THUMBNAIL_WIDTH = 4; protected const FIELD_IMAGE_HEIGHT = 5; protected const FIELD_IMAGE_WIDTH = 6; protected const FIELD_IMAGE_CLASS = 7; + protected const FIELD_IMAGE_DEFAULT = 13; public function __construct(array $values, ContainerInterface $services) { @@ -34,6 +36,7 @@ public function __construct(array $values, ContainerInterface $services) $this->imageHeight = $values[self::FIELD_IMAGE_HEIGHT]; $this->imageWidth = $values[self::FIELD_IMAGE_WIDTH]; $this->imageClass = $values[self::FIELD_IMAGE_CLASS]; + $this->imageDefault = $values[self::FIELD_IMAGE_DEFAULT]; // We can have no default for images $this->default = null; @@ -162,7 +165,12 @@ public function formatValuesBeforeSave($entry) protected function renderStatic($entry) { $value = $this->getValue($entry); - + if (!isset($value) || $value == '') { + $default_image_filename = "defaultimage{$entry['id_typeannonce']}_{$this->name}.jpg"; + if (file_exists($this->getBasePath(). $default_image_filename)) { + $value=$default_image_filename; + } + } if (isset($value) && $value != '' && file_exists($this->getBasePath(). $value)) { return $this->getWiki()->render('@attach/display-image.twig', [ 'baseUrl' => $this->getWiki()->GetBaseUrl().'/', diff --git a/tools/bazar/lang/bazarjs_en.inc.php b/tools/bazar/lang/bazarjs_en.inc.php index 8b1620a37..781dbb985 100644 --- a/tools/bazar/lang/bazarjs_en.inc.php +++ b/tools/bazar/lang/bazarjs_en.inc.php @@ -133,6 +133,7 @@ // 'BAZ_FORM_EDIT_IMAGE_WIDTH' => 'Largeur Vignette', // 'BAZ_FORM_EDIT_IMAGE_WIDTH_RESIZE' => 'Largeur redimension', // 'BAZ_FORM_EDIT_IMAGE_HEIGHT_RESIZE' => 'Hauteur redimension', + 'BAZ_FORM_EDIT_IMAGE_DEFAULT' => 'Default image', 'BAZ_FORM_EDIT_METADATA_THEME_LABEL' => 'Theme name', 'BAZ_FORM_EDIT_METADATA_SQUELETON_LABEL' => 'Squeleton', 'BAZ_FORM_EDIT_METADATA_STYLE_LABEL' => 'Style', diff --git a/tools/bazar/lang/bazarjs_fr.inc.php b/tools/bazar/lang/bazarjs_fr.inc.php index 094725dca..36c9b7177 100644 --- a/tools/bazar/lang/bazarjs_fr.inc.php +++ b/tools/bazar/lang/bazarjs_fr.inc.php @@ -133,6 +133,7 @@ 'BAZ_FORM_EDIT_IMAGE_WIDTH' => 'Largeur vignette', 'BAZ_FORM_EDIT_IMAGE_WIDTH_RESIZE' => 'Largeur redimension', 'BAZ_FORM_EDIT_IMAGE_HEIGHT_RESIZE' => 'Hauteur redimension', + 'BAZ_FORM_EDIT_IMAGE_DEFAULT' => 'Image par défaut', 'BAZ_FORM_EDIT_METADATA_THEME_LABEL' => 'Nom du thème', 'BAZ_FORM_EDIT_METADATA_SQUELETON_LABEL' => 'Squelette', 'BAZ_FORM_EDIT_METADATA_STYLE_LABEL' => 'Style', diff --git a/tools/bazar/presentation/javascripts/form-edit-template/fields/image.js b/tools/bazar/presentation/javascripts/form-edit-template/fields/image.js index b1484e5c4..4b83eaee2 100644 --- a/tools/bazar/presentation/javascripts/form-edit-template/fields/image.js +++ b/tools/bazar/presentation/javascripts/form-edit-template/fields/image.js @@ -15,9 +15,16 @@ export default { resize_height: { label: _t('BAZ_FORM_EDIT_IMAGE_HEIGHT_RESIZE'), value: '600' }, resize_width: { label: _t('BAZ_FORM_EDIT_IMAGE_WIDTH_RESIZE'), value: '800' }, align: { - label: _t('BAZ_FORM_EDIT_IMAGE_ALIGN_LABEL'), - value: 'right', - options: { left: _t('LEFT'), right: _t('RIGHT') } + label: _t("BAZ_FORM_EDIT_IMAGE_ALIGN_LABEL"), + value: "right", + options: { left: _t("LEFT"), right: _t("RIGHT") }, + }, + default_image: { + label: _t("BAZ_FORM_EDIT_IMAGE_DEFAULT"), + class: "default-file", + value: "", + type: "file", + accept: "image/*", }, maxsize: { label: _t('BAZ_FORM_EDIT_FILE_MAXSIZE_LABEL'), value: '' }, read: readConf, @@ -29,12 +36,13 @@ export default { attributesMapping: { ...defaultMapping, ...{ - 1: 'name', - 3: 'thumb_height', - 4: 'thumb_width', - 5: 'resize_height', - 6: 'resize_width', - 7: 'align', + 1: "name", + 3: "thumb_height", + 4: "thumb_width", + 5: "resize_height", + 6: "resize_width", + 7: "align", + 13: "default_image", 14: 'maxsize' } }, diff --git a/tools/bazar/presentation/javascripts/form-edit-template/form-builder-helper.js b/tools/bazar/presentation/javascripts/form-edit-template/form-builder-helper.js index 4a3323c52..23bcc6524 100644 --- a/tools/bazar/presentation/javascripts/form-edit-template/form-builder-helper.js +++ b/tools/bazar/presentation/javascripts/form-edit-template/form-builder-helper.js @@ -69,3 +69,20 @@ export function adjustJqueryBuilderUI($field) { $field.find('a[type=copy].formbuilder-icon-copy').attr('title', _t('DUPLICATE')) $field.find('a[type=edit].formbuilder-icon-pencil').attr('title', _t('BAZ_FORM_EDIT_HIDE')) } + +export function convertToBytes(base64content) { + const byteCharacters = base64content; + const sliceSize = 512; + var byteNumbers; + var slice; + const byteArrays = new [].constructor(); + for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) { + slice = byteCharacters.slice(offset, offset + sliceSize); + byteNumbers = new [].constructor(slice.length); + for (var idx = 0; idx < slice.length; idx++) { + byteNumbers[idx] = slice.charCodeAt(idx); + } + byteArrays.push(new Uint8Array(byteNumbers)); + } + return byteArrays; +} diff --git a/tools/bazar/presentation/javascripts/form-edit-template/form-edit-template.js b/tools/bazar/presentation/javascripts/form-edit-template/form-edit-template.js index 6346f0b03..5fe77cc4b 100644 --- a/tools/bazar/presentation/javascripts/form-edit-template/form-edit-template.js +++ b/tools/bazar/presentation/javascripts/form-edit-template/form-edit-template.js @@ -31,13 +31,15 @@ import { mapFieldsConf, addAdvancedAttributesSection, adjustDefaultAcls, - adjustJqueryBuilderUI + adjustJqueryBuilderUI, + convertToBytes } from './form-builder-helper.js' import { initListOrFormIdAttribute } from './attributes/list-form-id-attribute.js' import I18nOption from './i18n.js' const $formBuilderTextInput = $('#form-builder-text') window.formBuilder = undefined +window.defaultImage = {} // Use window to make it available outside of module, so extension can adds their own fields window.formBuilderFields = { @@ -120,7 +122,51 @@ function initializeFormbuilder() { } }) }, 0) - } + }, + onOpenFieldEdit() { + // Default image is in base64 in buffer variable => convert it to File in input element + $('input.default-file').each((idx, file_elem) => { + const current_ids = file_elem.attributes.id.value.split('-') + const image_name = current_ids[current_ids.length - 2] + '-' + current_ids[current_ids.length - 1] + if (window.defaultImage[image_name]) { + const image_content = window.defaultImage[image_name].split('|') + if (image_content.length === 2) { + const dataTransfer = new DataTransfer() + dataTransfer.items.add(new File(convertToBytes(image_content[1]), image_content[0])) + file_elem.files = dataTransfer.files + } + } + if (file_elem.parentElement.childElementCount == 1) { + const new_button = document.createElement("i") + new_button.className = "fas fa-remove btn-img-remove" + new_button.onclick = function() { + file_elem.files = new DataTransfer().files + window.defaultImage[image_name] = '' + } + file_elem.parentElement.append(new_button) + } + }) + // When change image, save it to base64 to buffer variable + $('input.default-file').change((event) => { + + const current_ids = event.target.attributes.id.value.split('-') + const image_name = current_ids[current_ids.length - 2] + '-' + current_ids[current_ids.length - 1] + const file = event.target.files[0] + if (typeof imageMaxSize == 'undefined') { + var imageMaxSize = 1024 * 1024; + } + if(file.size > imageMaxSize) { + alert(_t('IMAGEFIELD_TOO_LARGE_IMAGE', { imageMaxSize })) + event.target.value = ""; + return false + } + const reader = new FileReader() + reader.readAsDataURL(file) + reader.onload = function () { + window.defaultImage[image_name] = file.name + '|' + reader.result + } + }) + }, }) const defaultFieldsName = mapFieldsConf((conf) => conf.defaultIdentifier) @@ -153,6 +199,14 @@ function initializeFormbuilder() { // Update the text field converting form builder content into wiki syntax if ($('#form-builder-container').is(':visible')) { const formData = formBuilder.actions.getData() + // save base64 default image from buffer variable + Object.keys(window.defaultImage).forEach((image_name) => { + if (window.defaultImage[image_name] && window.defaultImage[image_name] != '') { + const image_names = image_name.split('-') + const field_idx = Number(image_names[image_names.length - 1]) - 1 + formData[field_idx].default_image = window.defaultImage[image_name] + } + }) const wikiText = formatJsonDataIntoWikiText(formData) if (wikiText) $formBuilderTextInput.val(wikiText) } @@ -251,6 +305,13 @@ function getFieldsIds() { function initializeBuilderFromTextInput() { const jsonData = parseWikiTextIntoJsonData($formBuilderTextInput.val()) try { + window.defaultImage = {} + // extract base64 default image to buffer variable + jsonData.forEach((field, index) => { + if (field.type === 'image') { + window.defaultImage['fld-' + (index + 1)] = field.default_image.trim() + } + }) formBuilder.actions.setData(JSON.stringify(jsonData)) } catch (error) { console.error(error) diff --git a/tools/bazar/presentation/styles/form-edit-template.css b/tools/bazar/presentation/styles/form-edit-template.css index af63c03df..21774a8d7 100644 --- a/tools/bazar/presentation/styles/form-edit-template.css +++ b/tools/bazar/presentation/styles/form-edit-template.css @@ -235,4 +235,13 @@ xmp { overflow: auto; } .form-group.autocomplete_other-wrap { display: none; } - \ No newline at end of file + +.btn-img-remove { + display: block; + position: relative; + top: -26px; + width: 20px; + margin-left: auto; + margin-right: 0; + cursor: pointer; +} \ No newline at end of file diff --git a/tools/bazar/services/BazarListService.php b/tools/bazar/services/BazarListService.php index 6152c50b1..dd0921ee9 100644 --- a/tools/bazar/services/BazarListService.php +++ b/tools/bazar/services/BazarListService.php @@ -2,6 +2,7 @@ namespace YesWiki\Bazar\Service; +use Attach; use YesWiki\Bazar\Controller\EntryController; use YesWiki\Wiki; use YesWiki\Bazar\Field\BazarField; @@ -41,6 +42,37 @@ public function getForms($options): array return $this->formManager->getAll(); } } + + private function replaceDefaultImage($options, $forms, $entries): array { + if (! class_exists('attach')) { + include ('tools/attach/libs/attach.lib.php'); + } + $attach = new attach($this->wiki); + $basePath = $attach->GetUploadPath(); + $basePath = $basePath . (substr($basePath, - 1) != "/" ? "/" : ""); + + foreach($options['idtypeannonce'] as $idtypeannonce) { + $template = $forms[(int)$idtypeannonce]['template']; + $image_names = array_map(function($item) {return $item[1];}, + array_filter($template, + function($item) { return $item[0] == 'image'; } + ) + ); + foreach($image_names as $image_name) { + $default_image_filename = "defaultimage{$idtypeannonce}_{$image_name}.jpg"; + if (file_exists($basePath.$default_image_filename)) { + $image_key = 'image'.$image_name; + foreach($entries as $key=>$entry) { + if (array_key_exists($image_key, $entry) && ($entry[$image_key] == null)) { + $entry[$image_key] = $default_image_filename; + } + $entries[$key] = $entry; + } + } + } + } + return $entries; + } public function getEntries($options, $forms = null): array { @@ -71,6 +103,7 @@ public function getEntries($options, $forms = null): array true // use Guard ); } + $entries = $this->replaceDefaultImage($options, $forms, $entries); // filter entries on datefilter parameter if (!empty($options['datefilter'])) { diff --git a/tools/bazar/services/FormManager.php b/tools/bazar/services/FormManager.php index c99be7563..d94025d34 100644 --- a/tools/bazar/services/FormManager.php +++ b/tools/bazar/services/FormManager.php @@ -2,6 +2,7 @@ namespace YesWiki\Bazar\Service; +use Attach; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use YesWiki\Bazar\Field\BazarField; use YesWiki\Bazar\Field\EnumField; @@ -17,11 +18,11 @@ class FormManager protected $securityController; protected $fieldFactory; protected $params; - protected $cachedForms; protected $cacheValidatedForAll; protected $isAvailableOnlyOneEntryOption; protected $isAvailableOnlyOneEntryMessage; + protected $attach; public function __construct( Wiki $wiki, @@ -31,6 +32,9 @@ public function __construct( ParameterBagInterface $params, SecurityController $securityController ) { + if (!class_exists('attach')) { + include('tools/attach/libs/attach.lib.php'); + } $this->wiki = $wiki; $this->dbService = $dbService; $this->entryManager = $entryManager; @@ -42,6 +46,89 @@ public function __construct( $this->securityController = $securityController; $this->isAvailableOnlyOneEntryOption = null; $this->isAvailableOnlyOneEntryMessage = null; + $this->attach = new attach($this->wiki); + } + + protected function getBasePath() + { + $basePath = $this->attach->GetUploadPath(); + return $basePath . (substr($basePath, -1) != "/" ? "/" : ""); + } + + protected function cleanCacheDefaultImage($prefix) + { + $cache_path = $this->attach->GetCachePath(); + $cache_path = $cache_path . (substr($cache_path, -1) != "/" ? "/" : ""); + $scan_cache_files = scandir($cache_path); + foreach ($scan_cache_files as $scan_cache_file) { + if (str_starts_with($scan_cache_file, $prefix)) { + unlink($cache_path . $scan_cache_file); + } + } + } + + protected function convertWithSpecialParameters($template, $id_nature) + { + $template = _convert($template, YW_CHARSET, true); + $template_list = $this->parseTemplate($template); + $modify = false; + for ($temp_index = 0; $temp_index < count($template_list); $temp_index++) { + if ($template_list[$temp_index][0] == 'image') { + $modify = true; + $basePath = $this->getBasePath(); + $image_comp = $template_list[$temp_index]; + $default_image_prefix = "defaultimage{$id_nature}_{$image_comp[1]}"; + $this->cleanCacheDefaultImage($default_image_prefix); + $default_image_filename = $basePath . $default_image_prefix . ".jpg"; + $default_image = explode('|', $image_comp[8]); + if (count($default_image) == 2) { + $image_comp[8] = $default_image[0]; + $imgext = explode('image/', explode(';', $default_image[1])[0])[1]; + $tmpFile = tempnam('cache', 'dfltimg'); + $tempFile = $tmpFile . '.' . $imgext; + rename($tmpFile, $tempFile); + try { + $ifp = fopen($tempFile, "wb"); + fwrite($ifp, base64_decode(explode(',', $default_image[1])[1])); + fclose($ifp); + $this->attach->redimensionner_image($tempFile, $default_image_filename, $image_comp[5], $image_comp[6], "crop"); + } finally { + unlink($tempFile); + } + } else { + $image_comp[8] = ''; + if (file_exists($default_image_filename)) { + unlink($default_image_filename); + } + } + $template_list[$temp_index] = $image_comp; + } + } + if ($modify) { + $template = $this->encodeTemplate($template_list); + } + return $this->dbService->escape($template); + } + + protected function prepare_with_special_parameters($form) + { + $basePath = $this->getBasePath(); + $template_list = $this->parseTemplate($form['bn_template']); + $modify = false; + for ($temp_index = 0; $temp_index < count($template_list); $temp_index++) { + if ($template_list[$temp_index][0] == 'image') { + $modify = true; + $image_comp = $template_list[$temp_index]; + $default_image_filename = $basePath . "defaultimage{$form['bn_id_nature']}_{$image_comp[1]}.jpg"; + if (file_exists($default_image_filename)) { + $image_comp[8] = $image_comp[8] . '|data:image/jpg;base64,' . base64_encode(file_get_contents($default_image_filename)); + } else { + $image_comp[8] = ''; + } + $template_list[$temp_index] = $image_comp; + } + } + return [$template_list, $modify]; } public function getOne($formId): ?array @@ -68,10 +155,12 @@ public function getFromRawData($form) foreach ($form as $key => $value) { $form[$key] = _convert($value, 'ISO-8859-15'); } - - $form['template'] = $this->parseTemplate($form['bn_template']); + list($template_list, $modify) = $this->prepare_with_special_parameters($form); + $form['template'] = $template_list; $form['prepared'] = $this->prepareData($form); - + if ($modify == true) { + $form['bn_template'] = $this->encodeTemplate($template_list); + } return $form; } @@ -142,11 +231,14 @@ public function update($data) throw new \Exception(_t('WIKI_IN_HIBERNATION')); } + $template = $this->convertWithSpecialParameters($data['bn_template'], $data['bn_id_nature']); + // reset cache $this->cacheValidatedForAll = false; + return $this->dbService->query('UPDATE' . $this->dbService->prefixTable('nature') . 'SET ' . '`bn_label_nature`="' . $this->dbService->escape(_convert($data['bn_label_nature'], YW_CHARSET, true)) . '" ,' - . '`bn_template`="' . $this->dbService->escape(_convert($data['bn_template'], YW_CHARSET, true)) . '" ,' + . '`bn_template`="' . $template . '" ,' . '`bn_description`="' . $this->dbService->escape(_convert($data['bn_description'], YW_CHARSET, true)) . '" ,' . '`bn_sem_context`="' . $this->dbService->escape(_convert($data['bn_sem_context'], YW_CHARSET, true)) . '" ,' . '`bn_sem_type`="' . $this->dbService->escape(_convert($data['bn_sem_type'], YW_CHARSET, true)) . '" ,' @@ -178,7 +270,7 @@ public function delete($id) // tests of if $formId is int if (strval(intval($id)) != strval($id)) { - return null ; + return null; } $this->clear($id); @@ -195,23 +287,23 @@ public function clear($id) } $this->dbService->query( 'DELETE FROM' . $this->dbService->prefixTable('acls') . - 'WHERE page_tag IN (SELECT tag FROM ' . $this->dbService->prefixTable('pages') . - 'WHERE tag IN (SELECT resource FROM ' . $this->dbService->prefixTable('triples') . - 'WHERE property="http://outils-reseaux.org/_vocabulary/type" AND value="fiche_bazar") AND body LIKE \'%"id_typeannonce":"' . $this->dbService->escape($id) . '"%\' );' + 'WHERE page_tag IN (SELECT tag FROM ' . $this->dbService->prefixTable('pages') . + 'WHERE tag IN (SELECT resource FROM ' . $this->dbService->prefixTable('triples') . + 'WHERE property="http://outils-reseaux.org/_vocabulary/type" AND value="fiche_bazar") AND body LIKE \'%"id_typeannonce":"' . $this->dbService->escape($id) . '"%\' );' ); // TODO use PageManager $this->dbService->query( 'DELETE FROM' . $this->dbService->prefixTable('pages') . - 'WHERE tag IN (SELECT resource FROM ' . $this->dbService->prefixTable('triples') . - 'WHERE property="http://outils-reseaux.org/_vocabulary/type" AND value="fiche_bazar") AND body LIKE \'%"id_typeannonce":"' . $this->dbService->escape($id) . '"%\';' + 'WHERE tag IN (SELECT resource FROM ' . $this->dbService->prefixTable('triples') . + 'WHERE property="http://outils-reseaux.org/_vocabulary/type" AND value="fiche_bazar") AND body LIKE \'%"id_typeannonce":"' . $this->dbService->escape($id) . '"%\';' ); // TODO use TripleStore $this->dbService->query( 'DELETE FROM' . $this->dbService->prefixTable('triples') . - 'WHERE resource NOT IN (SELECT tag FROM ' . $this->dbService->prefixTable('pages') . - 'WHERE 1) AND property="http://outils-reseaux.org/_vocabulary/type" AND value="fiche_bazar";' + 'WHERE resource NOT IN (SELECT tag FROM ' . $this->dbService->prefixTable('pages') . + 'WHERE 1) AND property="http://outils-reseaux.org/_vocabulary/type" AND value="fiche_bazar";' ); } @@ -275,6 +367,27 @@ public function parseTemplate($raw) return $tableau_template; } + public function encodeTemplate($template_list) + { + $new_template_list = []; + for ($temp_index = 0; $temp_index < count($template_list); $temp_index++) { + $new_line = ''; + foreach ($template_list[$temp_index] as $value) { + if ($value == '') { + $new_line .= ' '; + } else if ($value == '*') { + $new_line .= ' * '; + } else { + $new_line .= $value; + } + $new_line .= '***'; + } + $new_template_list[] = $new_line; + } + $template = implode("\r\n", array_map('trim', $new_template_list)); + return $template; + } + public function prepareData($form) { $i = 0; @@ -290,7 +403,7 @@ public function prepareData($form) } elseif (function_exists($field[0])) { $functionName = $field[0]; $field[0] = 'old'; // field name - $field['functionName'] = $functionName ; + $field['functionName'] = $functionName; $classField = $this->fieldFactory->create($field); if ($classField) { $prepared[$i] = $classField; @@ -319,7 +432,7 @@ public function scanAllFacettable($entries, $groups = ['all'], $onlyLists = fals $facetteasked = (isset($groups[0]) && $groups[0] == 'all') || in_array($key, $groups); if (!empty($value) and is_array($fields[$entry['id_typeannonce']]) && $facetteasked) { - if (in_array($key, ['id_typeannonce','owner'])) { + if (in_array($key, ['id_typeannonce', 'owner'])) { $fieldPropName = $key; $field = null; } else { @@ -368,7 +481,7 @@ public function scanAllFacettable($entries, $groups = ['all'], $onlyLists = fals array_filter( array_keys($facetteValue['id_typeannonce']), function ($key) { - return !in_array($key, ['type','source']); + return !in_array($key, ['type', 'source']); } ) ); @@ -438,7 +551,7 @@ public function findFieldFromNameOrPropertyName(?string $name, ?string $formId): } foreach ($form['prepared'] as $field) { - if (in_array($name, [$field->getName(),$field->getPropertyName()])) { + if (in_array($name, [$field->getName(), $field->getPropertyName()])) { return $field; } }