diff --git a/modules/viste/fields.php b/modules/viste/fields.php
index 0f64eacdd..e10f1f5aa 100755
--- a/modules/viste/fields.php
+++ b/modules/viste/fields.php
@@ -28,7 +28,7 @@ echo '
';
$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) {
$editable = !($field['default'] && $enable_readonly);
diff --git a/modules/viste/init.php b/modules/viste/init.php
index 6162ecec9..7451b0229 100755
--- a/modules/viste/init.php
+++ b/modules/viste/init.php
@@ -19,7 +19,10 @@
include_once __DIR__.'/../../core.php';
use Models\Module;
+use Models\View;
if (isset($id_record)) {
$record = Module::find($id_record);
+
+ $vista = View::find($id_record);
}
diff --git a/src/Models/Module.php b/src/Models/Module.php
index d6cb8c333..c8c63922d 100755
--- a/src/Models/Module.php
+++ b/src/Models/Module.php
@@ -115,8 +115,8 @@ class Module extends Model
{
$user = \Auth::user();
- $views = database()->fetchArray('SELECT * FROM `zz_views` WHERE `id_module` = :module_id AND
- `id` IN (
+ $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
+ `zz_views`.`id` IN (
SELECT `id_vista` FROM `zz_group_view` WHERE `id_gruppo` = (
SELECT `idgruppo` FROM `zz_users` WHERE `id` = :user_id
))
diff --git a/src/Models/View.php b/src/Models/View.php
index 597474906..239825e69 100755
--- a/src/Models/View.php
+++ b/src/Models/View.php
@@ -45,4 +45,42 @@ class View extends Model
{
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
+ ]);
+ }
+ }
}
diff --git a/src/Util/Query.php b/src/Util/Query.php
index 72c6e3973..7ab97dd5b 100755
--- a/src/Util/Query.php
+++ b/src/Util/Query.php
@@ -501,8 +501,8 @@ class Query
$user = \Auth::user();
- $views = $database->fetchArray('SELECT * FROM `zz_views` WHERE `id_module`='.prepare($element['id']).' AND
- `id` IN (
+ $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
+ `zz_views`.`id` IN (
SELECT `id_vista` FROM `zz_group_view` WHERE `id_gruppo`=(
SELECT `idgruppo` FROM `zz_users` WHERE `id`='.prepare($user['id']).'
))
diff --git a/update/2_5.sql b/update/2_5.sql
index 99a5eb743..2c3eb9fd0 100644
--- a/update/2_5.sql
+++ b/update/2_5.sql
@@ -2059,4 +2059,24 @@ HAVING
2=2
ORDER BY `zz_segments_lang`.`name`,
`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';
\ No newline at end of file
+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;
diff --git a/update/tables.php b/update/tables.php
index d38f536a7..4ea2868ce 100755
--- a/update/tables.php
+++ b/update/tables.php
@@ -181,7 +181,7 @@ return [
'zz_plugins_lang',
'zz_prints',
'zz_segments',
- 'zz_segments_lang'
+ 'zz_segments_lang',
'zz_semaphores',
'zz_settings',
'zz_tasks',
@@ -190,6 +190,7 @@ return [
'zz_users',
'zz_user_sedi',
'zz_views',
+ 'zz_views_lang',
'zz_widgets',
'zz_widgets_lang',
];