Aggiunta tabella zz_views_lang

This commit is contained in:
Pek5892 2024-03-11 11:21:05 +01:00
parent cf68c56b3a
commit a5994a5eb4
12 changed files with 85 additions and 20 deletions

View File

@ -411,12 +411,12 @@ elseif (post('op') == 'send-email') {
$visible = filter('visible'); $visible = filter('visible');
$id_riga = filter('id_vista'); $id_riga = filter('id_vista');
$dbo->query('UPDATE `zz_views` SET `visible` = '.prepare($visible).' WHERE id = '.prepare($id_riga)); $dbo->query('UPDATE `zz_views` SET `visible` = '.prepare($visible).' WHERE `id` = '.prepare($id_riga));
} elseif (filter('op') == 'ordina_colonne') { } elseif (filter('op') == 'ordina_colonne') {
$order = explode(',', post('order', true)); $order = explode(',', post('order', true));
foreach ($order as $i => $id_riga) { foreach ($order as $i => $id_riga) {
$dbo->query('UPDATE `zz_views` SET `order` = '.prepare($i).' WHERE id='.prepare($id_riga)); $dbo->query('UPDATE `zz_views` SET `order` = '.prepare($i).' WHERE `id`='.prepare($id_riga));
} }
} elseif (filter('op') == 'visualizza_righe_riferimenti') { } elseif (filter('op') == 'visualizza_righe_riferimenti') {
include_once base_dir().'/include/riferimenti/riferimenti.php'; include_once base_dir().'/include/riferimenti/riferimenti.php';

View File

@ -27,7 +27,7 @@ echo '
<p>'.tr('Trascina le colonne per ordinare la struttura della tabella principale, seleziona e deseleziona le colonne per renderle visibili o meno').'.</p> <p>'.tr('Trascina le colonne per ordinare la struttura della tabella principale, seleziona e deseleziona le colonne per renderle visibili o meno').'.</p>
<div class="sortable">'; <div class="sortable">';
$fields = $dbo->fetchArray('SELECT *, (SELECT GROUP_CONCAT(zz_groups.nome) FROM zz_group_view INNER JOIN zz_groups ON zz_group_view.id_gruppo = zz_groups.id WHERE zz_group_view.id_vista = zz_views.id) AS gruppi_con_accesso FROM zz_views WHERE id_module='.prepare($id_module).' ORDER BY `order` ASC'); $fields = $dbo->fetchArray('SELECT *, (SELECT GROUP_CONCAT(`zz_groups`.`nome`) FROM `zz_group_view` INNER JOIN `zz_groups` ON `zz_group_view`.`id_gruppo` = `zz_groups`.`id` WHERE `zz_group_view`.`id_vista` = `zz_views`.`id`) AS gruppi_con_accesso FROM `zz_views` LEFT JOIN `zz_views_lang` ON (`zz_views`.`id` = `zz_views_lang`.`id_record` AND `zz_views_lang`.`id_lang` = '.prepare(setting('Lingua')).') WHERE `id_module`='.prepare($id_module).' ORDER BY `order` ASC');
foreach ($fields as $field) { foreach ($fields as $field) {
echo ' echo '
<div class="panel panel-default clickable col-md-4" data-id="'.$field['id'].'"> <div class="panel panel-default clickable col-md-4" data-id="'.$field['id'].'">

View File

@ -20,7 +20,7 @@
namespace Modules\Aggiornamenti\Controlli; namespace Modules\Aggiornamenti\Controlli;
use Models\Module; use Models\Module;
use Models\View;
class ColonneDuplicateViste extends Controllo class ColonneDuplicateViste extends Controllo
{ {
public function getName() public function getName()
@ -35,8 +35,8 @@ class ColonneDuplicateViste extends Controllo
public function check() public function check()
{ {
$duplicati = database()->fetchArray('SELECT `id_module`, `name` FROM `zz_views` GROUP BY `id_module`, `name` HAVING COUNT(`name`) > 1'); $duplicati = database()->fetchArray('SELECT `id_module`, `name` FROM `zz_views` LEFT JOIN `zz_views_lang` ON (`zz_views`.`id` = `zz_views_lang`.`id_record` AND `zz_views_lang`.`id_lang` = '.prepare(setting('Lingua')).') GROUP BY `id_module`, `name` HAVING COUNT(`name`) > 1');
foreach ($duplicati as $colonna) { foreach ($duplicati as $colonna) {
$modulo = Module::find($colonna['id_module']); $modulo = Module::find($colonna['id_module']);

View File

@ -49,7 +49,6 @@ switch (filter('op')) {
foreach ($queries as $c => $query) { foreach ($queries as $c => $query) {
if (check_query($query)) { if (check_query($query)) {
$array = [ $array = [
'name' => post('name')[$c],
'query' => $query, 'query' => $query,
'visible' => post('visible')[$c], 'visible' => post('visible')[$c],
'search' => post('search')[$c], 'search' => post('search')[$c],
@ -62,15 +61,19 @@ switch (filter('op')) {
'id_module' => $id_record, 'id_module' => $id_record,
]; ];
$name = post('name')[$c];
if (!empty(post('id')[$c]) && !empty($query)) { if (!empty(post('id')[$c]) && !empty($query)) {
$id = post('id')[$c]; $id = post('id')[$c];
$dbo->update('zz_views', $array, ['id' => $id]); $dbo->update('zz_views', $array, ['id' => $id]);
$dbo->update('zz_views_lang', [
'name' => $name
], ['id_record' => $id, 'id_lang' => setting('Lingua')]);
} elseif (!empty($query)) { } elseif (!empty($query)) {
$array['order'] = orderValue('zz_views', 'id_module', $id_record); $array['order'] = orderValue('zz_views', 'id_module', $id_record);
$dbo->insert('zz_views', $array); $dbo->insert('zz_views', $array);
$id = $dbo->lastInsertedID(); $id = $dbo->lastInsertedID();
} }
@ -171,7 +174,7 @@ switch (filter('op')) {
$order = explode(',', post('order', true)); $order = explode(',', post('order', true));
foreach ($order as $i => $id_riga) { foreach ($order as $i => $id_riga) {
$dbo->query('UPDATE `zz_views` SET `order` = '.prepare($i).' WHERE id='.prepare($id_riga)); $dbo->query('UPDATE `zz_views` SET `order` = '.prepare($i).' WHERE `id`='.prepare($id_riga));
} }
break; break;
@ -180,7 +183,7 @@ switch (filter('op')) {
$visible = filter('visible'); $visible = filter('visible');
$id_riga = filter('id_vista'); $id_riga = filter('id_vista');
$dbo->query('UPDATE `zz_views` SET `visible` = '.prepare($visible).' WHERE id = '.prepare($id_riga)); $dbo->query('UPDATE `zz_views` SET `visible` = '.prepare($visible).' WHERE `id` = '.prepare($id_riga));
break; break;
} }

View File

@ -101,8 +101,8 @@ if (!empty($options) && $options != 'custom' && $options != 'menu') {
echo ' echo '
<div class="nav-tabs-custom"> <div class="nav-tabs-custom">
<ul class="nav nav-tabs nav-justified"> <ul class="nav nav-tabs nav-justified">
<li class="active"><a data-toggle="tab" href="#fields">'.tr('Campi').' <span class="badge">'.$dbo->fetchNum('SELECT * FROM zz_views WHERE id_module='.prepare($record['id']).' ORDER BY `order` ASC').'</a></li> <li class="active"><a data-toggle="tab" href="#fields">'.tr('Campi').' <span class="badge">'.$dbo->fetchNum('SELECT * FROM `zz_views` LEFT JOIN `zz_views_lang` ON (`zz_views`.`id` = `zz_views_lang`.`id_record` AND `zz_views_lang`.`id_lang` = '.prepare(setting('Lingua')).') WHERE `id_module`='.prepare($record['id']).' ORDER BY `order` ASC').'</a></li>
<li><a data-toggle="tab" href="#filters">'.tr('Filtri').' <span class="badge">'.$dbo->fetchNum('SELECT * FROM zz_group_module WHERE idmodule='.prepare($record['id']).' ORDER BY `id` ASC').'</span></a></li> <li><a data-toggle="tab" href="#filters">'.tr('Filtri').' <span class="badge">'.$dbo->fetchNum('SELECT * FROM `zz_group_module` WHERE `idmodule`='.prepare($record['id']).' ORDER BY `id` ASC').'</span></a></li>
</ul> </ul>
<div class="tab-content"> <div class="tab-content">

View File

@ -28,7 +28,7 @@ echo '
<div class="data">'; <div class="data">';
$key = 0; $key = 0;
$fields = $dbo->fetchArray('SELECT * FROM `zz_views` WHERE `id_module`='.prepare($record->id).' ORDER BY `order` ASC, `updated_at` DESC '); $fields = $dbo->fetchArray('SELECT * FROM `zz_views` LEFT JOIN `zz_views_lang` ON (`zz_views`.`id` = `zz_views_lang`.`id_record` AND `zz_views_lang`.`id_lang` = '.prepare(setting('Lingua')).') WHERE `id_module`='.prepare($record->id).' ORDER BY `order` ASC, `updated_at` DESC ');
foreach ($fields as $key => $field) { foreach ($fields as $key => $field) {
$editable = !($field['default'] && $enable_readonly); $editable = !($field['default'] && $enable_readonly);

View File

@ -19,7 +19,10 @@
include_once __DIR__.'/../../core.php'; include_once __DIR__.'/../../core.php';
use Models\Module; use Models\Module;
use Models\View;
if (isset($id_record)) { if (isset($id_record)) {
$record = Module::find($id_record); $record = Module::find($id_record);
$vista = View::find($id_record);
} }

View File

@ -115,8 +115,8 @@ class Module extends Model
{ {
$user = \Auth::user(); $user = \Auth::user();
$views = database()->fetchArray('SELECT * FROM `zz_views` WHERE `id_module` = :module_id AND $views = database()->fetchArray('SELECT * FROM `zz_views` LEFT JOIN `zz_views_lang` ON (`zz_views`.`id` = `zz_views_lang`.`id_record` AND `zz_views_lang`.`id_lang` = '.prepare(setting('Lingua')).') WHERE `id_module` = :module_id AND
`id` IN ( `zz_views`.`id` IN (
SELECT `id_vista` FROM `zz_group_view` WHERE `id_gruppo` = ( SELECT `id_vista` FROM `zz_group_view` WHERE `id_gruppo` = (
SELECT `idgruppo` FROM `zz_users` WHERE `id` = :user_id SELECT `idgruppo` FROM `zz_users` WHERE `id` = :user_id
)) ))

View File

@ -45,4 +45,42 @@ class View extends Model
{ {
return $this->belongsTo(Module::class, 'id_module'); return $this->belongsTo(Module::class, 'id_module');
} }
/**
* Ritorna l'attributo name dell'articolo.
*
* @return string
*/
public function getNameAttribute()
{
return database()->table($this->table.'_lang')
->select('name')
->where('id_record', '=', $this->id)
->where('id_lang', '=', setting('Lingua'))
->first()->name;
}
/**
* Imposta l'attributo name dell'articolo.
*/
public function setNameAttribute($value)
{
$table = database()->table($this->table.'_lang');
$translated = $table
->where('id_record', '=', $this->id)
->where('id_lang', '=', setting('Lingua'));
if ($translated->count() > 0) {
$translated->update([
'name' => $value
]);
} else {
$table->insert([
'id_record' => $this->id,
'id_lang' => setting('Lingua'),
'name' => $value
]);
}
}
} }

View File

@ -501,8 +501,8 @@ class Query
$user = \Auth::user(); $user = \Auth::user();
$views = $database->fetchArray('SELECT * FROM `zz_views` WHERE `id_module`='.prepare($element['id']).' AND $views = $database->fetchArray('SELECT *, `zz_views`.`id` FROM `zz_views` LEFT JOIN `zz_views_lang` ON (`zz_views`.`id` = `zz_views_lang`.`id_record` AND `zz_views_lang`.`id_lang` = '.prepare(setting('Lingua')).') WHERE `id_module`='.prepare($element['id']).' AND
`id` IN ( `zz_views`.`id` IN (
SELECT `id_vista` FROM `zz_group_view` WHERE `id_gruppo`=( SELECT `id_vista` FROM `zz_group_view` WHERE `id_gruppo`=(
SELECT `idgruppo` FROM `zz_users` WHERE `id`='.prepare($user['id']).' SELECT `idgruppo` FROM `zz_users` WHERE `id`='.prepare($user['id']).'
)) ))

View File

@ -2059,4 +2059,24 @@ HAVING
2=2 2=2
ORDER BY `zz_segments_lang`.`name`, ORDER BY `zz_segments_lang`.`name`,
`zz_segments`.`id_module`" WHERE `zz_modules`.`id` = (SELECT `id_record` FROM `zz_modules_lang` WHERE `name` = 'Segmenti'); `zz_segments`.`id_module`" WHERE `zz_modules`.`id` = (SELECT `id_record` FROM `zz_modules_lang` WHERE `name` = 'Segmenti');
UPDATE `zz_views` INNER JOIN `zz_modules` ON `zz_views`.`id_module` = `zz_modules`.`id` LEFT JOIN `zz_modules_lang` ON (`zz_modules_lang`.`id_record` = `zz_modules`.`id` AND `zz_modules_lang`.`id_lang` = (SELECT `valore` FROM `zz_settings` WHERE `nome` = "Lingua")) SET `zz_views`.`query` = '`zz_segments_lang`.`name`' WHERE `zz_modules_lang`.`name` = 'Segmenti' AND `zz_views`.`name` = 'Nome'; UPDATE `zz_views` INNER JOIN `zz_modules` ON `zz_views`.`id_module` = `zz_modules`.`id` LEFT JOIN `zz_modules_lang` ON (`zz_modules_lang`.`id_record` = `zz_modules`.`id` AND `zz_modules_lang`.`id_lang` = (SELECT `valore` FROM `zz_settings` WHERE `nome` = "Lingua")) SET `zz_views`.`query` = '`zz_segments_lang`.`name`' WHERE `zz_modules_lang`.`name` = 'Segmenti' AND `zz_views`.`name` = 'Nome';
-- Aggiunta tabella zz_views_lang
CREATE TABLE IF NOT EXISTS `zz_views_lang` (
`id` int NOT NULL,
`id_lang` int NOT NULL,
`id_record` int NOT NULL,
`name` VARCHAR(255) NOT NULL
);
ALTER TABLE `zz_views_lang`
ADD PRIMARY KEY (`id`);
ALTER TABLE `zz_views_lang`
MODIFY `id` int NOT NULL AUTO_INCREMENT;
INSERT INTO `zz_views_lang` (`id`, `id_lang`, `id_record`, `name`) SELECT NULL, (SELECT `id` FROM `zz_langs` WHERE `iso_code` = 'it'), `id`, `name` FROM `zz_views`;
ALTER TABLE `zz_views`
DROP `name`;
ALTER TABLE `zz_views_lang` ADD CONSTRAINT `zz_views_lang_ibfk_1` FOREIGN KEY (`id_record`) REFERENCES `zz_views`(`id`) ON DELETE CASCADE ON UPDATE RESTRICT;

View File

@ -181,7 +181,7 @@ return [
'zz_plugins_lang', 'zz_plugins_lang',
'zz_prints', 'zz_prints',
'zz_segments', 'zz_segments',
'zz_segments_lang' 'zz_segments_lang',
'zz_semaphores', 'zz_semaphores',
'zz_settings', 'zz_settings',
'zz_tasks', 'zz_tasks',
@ -190,6 +190,7 @@ return [
'zz_users', 'zz_users',
'zz_user_sedi', 'zz_user_sedi',
'zz_views', 'zz_views',
'zz_views_lang',
'zz_widgets', 'zz_widgets',
'zz_widgets_lang', 'zz_widgets_lang',
]; ];