From 9a8592cb6829933f78b50509ea644039eac48211 Mon Sep 17 00:00:00 2001 From: fredtempez Date: Mon, 5 Apr 2021 15:32:04 +0200 Subject: [PATCH] Search fonction initialisation --- module/search/ressource/defaultdata.php | 3 +- module/search/search.php | 52 ++++++++++++++++++++----- module/search/view/index/index.php | 4 +- 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/module/search/ressource/defaultdata.php b/module/search/ressource/defaultdata.php index 378c347c..bd10fb70 100755 --- a/module/search/ressource/defaultdata.php +++ b/module/search/ressource/defaultdata.php @@ -6,6 +6,7 @@ class init extends search { 'placeHolder' => 'Un ou plusieurs mots-clés séparés par un espace ou par +', 'submitText' => 'Rechercher', 'keywordColor' => 'rgba(229, 229, 1, 1)', - 'versionData' => '2.0' + 'versionData' => '2.0', + 'style' => '' ]; } \ No newline at end of file diff --git a/module/search/search.php b/module/search/search.php index 9050a8a9..17602377 100755 --- a/module/search/search.php +++ b/module/search/search.php @@ -51,35 +51,65 @@ class search extends common { * Appelée par les fonctions index et config */ private function update() { - // Création des valeurs de réglage par défaut - if ( !is_array($this->getData(['module', $this->getUrl(0), 'config']) ) ) { - require_once('module/search/ressource/defaultdata.php'); - $this->setData(['module', $this->getUrl(0), 'config', init::$defaultData]); - } - // Version 2.0 + + // Version 2.0 if (version_compare($this->getData(['module', $this->getUrl(0), 'config', 'versionData']), '2.0', '<') ) { - // Distinguer la config des autres données + $class = get_called_class(); + $moduleId = $this->getUrl(0); + // Données de l'instance $data = $this->getData(['module', $this->getUrl(0)]); $this->setData(['module', $this->getUrl(0), 'config', [ 'submitText' => $this->getData(['module', $this->getUrl(0), 'submitText']), 'placeHolder' => $this->getData(['module', $this->getUrl(0), 'placeHolder']), 'resultHideContent' => $this->getData(['module', $this->getUrl(0), 'resultHideContent']), 'previewLength' => $this->getData(['module', $this->getUrl(0), 'previewLength']), - 'keywordColor' => $this->getData(['module', $this->getUrl(0), 'keywordColor']) + 'keywordColor' => $this->getData(['module', $this->getUrl(0), 'keywordColor']), + 'style' => self::DATA_DIR . 'modules/' . $class . '/' . $moduleId . '.css', + 'versionData' => '2.0' ]]); $this->deleteData(['module', $this->getUrl(0), 'submitText']); $this->deleteData(['module', $this->getUrl(0), 'placeHolder']); $this->deleteData(['module', $this->getUrl(0), 'resultHideContent']); $this->deleteData(['module', $this->getUrl(0), 'previewLength']); $this->deleteData(['module', $this->getUrl(0), 'keywordColor']); - $this->setData(['module', $this->getUrl(0), 'config', 'versionData','2.0']); } } + /** + * Initialisation du module + * Appelée par les fonctions index et config + */ + private function init(){ + // Création des valeurs de réglage par défaut + if ( !is_array($this->getData(['module', $this->getUrl(0), 'config']) ) ) { + require_once('module/search/ressource/defaultdata.php'); + + $class = get_called_class(); + $moduleId = $this->getUrl(0); + // Sauver les données par défaut + init::$defaultData['style'] = self::DATA_DIR . 'modules/' . $class . '/' . $moduleId . '.css'; + $this->setData(['module', $this->getUrl(0), 'config', init::$defaultData]); + + $style = '.searchItem {background:' . $this->getData(['module', $this->getUrl(0), 'config', 'keywordColor']). ';}'; + + // Dossier de l'instance + if (!is_dir(self::DATA_DIR . 'modules/' . $class)) { + mkdir (self::DATA_DIR . 'modules/' . $class, 0777, true); + } + $success = file_put_contents(self::DATA_DIR . 'modules/' . $class . '/' . $moduleId . '.css' , $style ); + + + } + } + + // Configuration vide public function config() { + // Initialisation d'un nouveau module + $this->init(); + // Mise à jour des données de module $this->update(); @@ -128,6 +158,10 @@ class search extends common { } public function index() { + + // Initialisation d'un nouveau module + $this->init(); + // Mise à jour des données de module $this->update(); diff --git a/module/search/view/index/index.php b/module/search/view/index/index.php index 06434a7e..1b809245 100755 --- a/module/search/view/index/index.php +++ b/module/search/view/index/index.php @@ -4,13 +4,13 @@
isset($_COOKIE['ZWII_I18N_SITE'] ) ? $this->getData(['module', $this->getUrl(0), 'placeHolder']):'Un ou plusieurs mots clef séparés par un espace', + 'placeholder' => isset($_COOKIE['ZWII_I18N_SITE'] ) ? $this->getData(['module', $this->getUrl(0), 'config', 'placeHolder']):'Un ou plusieurs mots clef séparés par un espace', 'value' => $module::$motclef ]); ?>
$this->getData(['module', $this->getUrl(0), 'submitText']) + 'value' => $this->getData(['module', $this->getUrl(0), 'config', 'submitText']) ]); ?>