Miglioramento variabili di filtraggio

@fpsoftware
This commit is contained in:
Thomas Zilio 2018-09-03 09:29:54 +02:00
parent c35ea2c836
commit 8cc2783187
3 changed files with 39 additions and 11 deletions

View File

@ -402,29 +402,37 @@ class App
*
* @return string
*/
public static function replacePlaceholder($query, $custom = null)
public static function replacePlaceholder($query)
{
$id_module = filter('id_module');
$id_parent = filter('id_parent');
$user = Auth::user();
// Sostituzione degli identificatori
$id = empty($custom) ? $user['idanagrafica'] : $custom;
$query = str_replace(['|idagente|', '|idtecnico|', '|idanagrafica|'], prepare($id), $query);
$segment = !empty($_SESSION['module_'.$id_module]['id_segment']);
// Sostituzione delle date
$query = str_replace(['|period_start|', '|period_end|'], [$_SESSION['period_start'], $_SESSION['period_end']], $query);
// Elenco delle sostituzioni
$replace = [
// Identificatori
'|id_anagrafica|' => prepare($user['idanagrafica']),
'|id_utente|' => prepare($user['id']),
'|id_parent|' => prepare($id_parent),
// Sostituzione dei segmenti
$query = str_replace('|segment|', !empty($_SESSION['module_'.$id_module]['id_segment']) ? ' AND id_segment = '.prepare($_SESSION['module_'.$id_module]['id_segment']) : '', $query);
// Date
'|period_start|' => $_SESSION['period_start'],
'|period_end|' => $_SESSION['period_end'],
// Segmenti
'|segment|' => !empty($segment) ? ' AND id_segment = '.prepare($segment) : '',
];
// Sostituzione dei formati
$patterns = formatter()->getSQLPatterns();
$replace = [];
foreach ($patterns as $key => $value) {
$replace['|'.$key.'_format|'] = "'".$value."'";
}
// Sostituzione effettiva
$query = replace($query, $replace);
return $query;

View File

@ -52,12 +52,12 @@ class Plugin extends Model
public function getOptionsAttribute($value)
{
return App::replacePlaceholder($value, filter('id_parent'));
return App::replacePlaceholder($value);
}
public function getOptions2Attribute($value)
{
return App::replacePlaceholder($value, filter('id_parent'));
return App::replacePlaceholder($value);
}
/* Metodi personalizzati */

View File

@ -265,3 +265,23 @@ UPDATE `zz_widgets` SET `query` = REPLACE(`query`, 'co_contratti_promemoria', 'c
-- Fix nome in zz_files
ALTER TABLE `zz_files` CHANGE `nome` `name` varchar(255) NOT NULL;
UPDATE `zz_files` SET `id_module` = NULL WHERE `id_plugin` IS NOT NULL;
-- Adeguamento variabili di filtraggio
UPDATE `zz_modules` SET `options` = REPLACE(`options`, '|idanagrafica|', '|id_anagrafica|'), `options2` = REPLACE(`options2`, '|idanagrafica|', '|id_anagrafica|');
UPDATE `zz_plugins` SET `options` = REPLACE(`options`, '|idanagrafica|', '|id_anagrafica|'), `options2` = REPLACE(`options2`, '|idanagrafica|', '|id_anagrafica|');
UPDATE `zz_widgets` SET `query` = REPLACE(`query`, '|idanagrafica|', '|id_anagrafica|');
UPDATE `zz_group_module` SET `clause` = REPLACE(`clause`, '|idanagrafica|', '|id_anagrafica|');
UPDATE `zz_modules` SET `options` = REPLACE(`options`, '|idtecnico|', '|id_anagrafica|'), `options2` = REPLACE(`options2`, '|idtecnico|', '|id_anagrafica|');
UPDATE `zz_plugins` SET `options` = REPLACE(`options`, '|idtecnico|', '|id_anagrafica|'), `options2` = REPLACE(`options2`, '|idtecnico|', '|id_anagrafica|');
UPDATE `zz_widgets` SET `query` = REPLACE(`query`, '|idtecnico|', '|id_anagrafica|');
UPDATE `zz_group_module` SET `clause` = REPLACE(`clause`, '|idtecnico|', '|id_anagrafica|');
UPDATE `zz_modules` SET `options` = REPLACE(`options`, '|idagente|', '|id_anagrafica|'), `options2` = REPLACE(`options2`, '|idagente|', '|id_anagrafica|');
UPDATE `zz_plugins` SET `options` = REPLACE(`options`, '|idagente|', '|id_anagrafica|'), `options2` = REPLACE(`options2`, '|idagente|', '|id_anagrafica|');
UPDATE `zz_widgets` SET `query` = REPLACE(`query`, '|idagente|', '|id_anagrafica|');
UPDATE `zz_group_module` SET `clause` = REPLACE(`clause`, '|idagente|', '|id_anagrafica|');
-- Adeguamento variabili di filtraggio per i plugin Sedi e Referenti in Anagrafiche
UPDATE `zz_plugins` SET `script` = '', `options` = ' { "main_query": [ { "type": "table", "fields": "Nome, Indirizzo, Città, CAP, Provincia, Referente", "query": "SELECT an_sedi.id, an_sedi.nomesede AS Nome, an_sedi.indirizzo AS Indirizzo, an_sedi.citta AS Città, an_sedi.cap AS CAP, an_sedi.provincia AS Provincia, an_referenti.nome AS Referente FROM an_sedi LEFT OUTER JOIN an_referenti ON idsede = an_sedi.id WHERE 1=1 AND an_sedi.idanagrafica=|id_parent| HAVING 2=2 ORDER BY an_sedi.id DESC"} ]}', `directory` = 'sedi', `version` = '2.3', `compatibility` = '2.*' WHERE `name` = 'Sedi';
UPDATE `zz_plugins` SET `script` = '', `options` = ' { "main_query": [ { "type": "table", "fields": "Nominativo, Mansione, Telefono, Indirizzo email, Sede", "query": "SELECT an_referenti.id, an_referenti.nome AS Nominativo, mansione AS Mansione, an_referenti.telefono AS Telefono, an_referenti.email AS ''Indirizzo email'', an_sedi.nomesede AS Sede FROM an_referenti LEFT OUTER JOIN an_sedi ON idsede = an_sedi.id WHERE 1=1 AND an_referenti.idanagrafica=|id_parent| HAVING 2=2 ORDER BY an_referenti.id DESC"} ]}', `directory` = 'referenti', `version` = '2.3', `compatibility` = '2.*' WHERE `name` = 'Referenti';