Allineamento add liste
This commit is contained in:
parent
88e5623a9e
commit
877379134b
|
@ -26,14 +26,16 @@ include_once __DIR__.'/../../core.php';
|
|||
|
||||
switch (filter('op')) {
|
||||
case 'add':
|
||||
$lista = post('name');
|
||||
$name = post('name');
|
||||
$lista_new = Lista::find((new Lista())->getByName($name)->id_record);
|
||||
|
||||
if ((new Lista())->getByName($lista)->id_record) {
|
||||
if (!empty($lista_new) && $lista_new->id != $id_record){
|
||||
flash()->error(tr('Esiste già una lista con questo nome.'));
|
||||
} else {
|
||||
$dbo->query('INSERT INTO `em_lists` (`created_at`) VALUES (NOW())');
|
||||
$id_record = $dbo->lastInsertedID();
|
||||
$dbo->query('INSERT INTO `em_lists_lang` (`name`, `id_record`, `id_lang`) VALUES ('.prepare($lista).', '.prepare($id_record).', '.prepare(setting('Lingua')).' )');
|
||||
$lista = Lista::build($name);
|
||||
$id_record = $lista->id;
|
||||
$lista->name = $name;
|
||||
$lista->save();
|
||||
|
||||
flash()->info(tr('Nuova lista aggiunta.'));
|
||||
}
|
||||
|
@ -49,16 +51,18 @@ switch (filter('op')) {
|
|||
$query = html_entity_decode($query);
|
||||
}
|
||||
|
||||
$dbo->update('em_lists', [
|
||||
'query' => $query
|
||||
], ['id' => $id_record]);
|
||||
$lista_new = Lista::find((new Lista())->getByName($name)->id_record);
|
||||
|
||||
$dbo->update('em_lists_lang', [
|
||||
'name' => $name,
|
||||
'description' => $description
|
||||
], ['id_record' => $id_record, 'id_lang' => setting('Lingua')]);
|
||||
if (!empty($lista_new) && $lista_new->id != $id_record){
|
||||
flash()->error(tr('Esiste già una lista con questo nome.'));
|
||||
} else {
|
||||
$lista->name = $name;
|
||||
$lista->description = $description;
|
||||
$lista->query = $query;
|
||||
$lista->save();
|
||||
|
||||
flash()->info(tr('Informazioni salvate correttamente.'));
|
||||
flash()->info(tr('Informazioni salvate correttamente.'));
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
|
|
|
@ -23,4 +23,6 @@ include_once __DIR__.'/../../core.php';
|
|||
|
||||
if (isset($id_record)) {
|
||||
$record = $dbo->fetchOne('SELECT * FROM `em_lists` LEFT JOIN `em_lists_lang` ON (`em_lists`.`id` = `em_lists_lang`.`id_record` AND `em_lists_lang`.`id_lang` = '.prepare(setting('Lingua')).') WHERE `em_lists`.`id` = '.prepare($id_record));
|
||||
|
||||
$lista = Lista::find($id_record);
|
||||
}
|
||||
|
|
|
@ -35,6 +35,15 @@ class Lista extends Model
|
|||
|
||||
protected $table = 'em_lists';
|
||||
|
||||
|
||||
public static function build($name)
|
||||
{
|
||||
$model = new static();
|
||||
$model->save();
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function save(array $options = [])
|
||||
{
|
||||
$result = parent::save($options);
|
||||
|
@ -135,6 +144,54 @@ class Lista extends Model
|
|||
->first()->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Imposta l'attributo name della lista.
|
||||
*/
|
||||
public function setDescriptionAttribute($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([
|
||||
'description' => $value
|
||||
]);
|
||||
} else {
|
||||
$table->insert([
|
||||
'id_record' => $this->id,
|
||||
'id_lang' => setting('Lingua'),
|
||||
'description' => $value
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Imposta l'attributo description della lista.
|
||||
*/
|
||||
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
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ritorna l'attributo description della lista.
|
||||
*
|
||||
|
|
|
@ -914,7 +914,7 @@ CREATE TABLE IF NOT EXISTS `em_lists_lang` (
|
|||
`id_lang` int NOT NULL,
|
||||
`id_record` int NOT NULL,
|
||||
`name` VARCHAR(255) NOT NULL,
|
||||
`description` VARCHAR(255) NOT NULL
|
||||
`description` VARCHAR(255) NULL
|
||||
);
|
||||
ALTER TABLE `em_lists_lang`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
|
@ -930,7 +930,7 @@ ALTER TABLE `em_lists`
|
|||
|
||||
ALTER TABLE `em_lists` CHANGE `id` `id` INT NOT NULL AUTO_INCREMENT;
|
||||
|
||||
ALTER TABLE `em_lists_lang` ADD CONSTRAINT `em_lists_lang_ibfk_1` FOREIGN KEY (`id_record`) REFERENCES `em_lists_lang`(`id`) ON DELETE CASCADE ON UPDATE RESTRICT;
|
||||
ALTER TABLE `em_lists_lang` ADD CONSTRAINT `em_lists_lang_ibfk_1` FOREIGN KEY (`id_record`) REFERENCES `em_lists`(`id`) ON DELETE CASCADE ON UPDATE RESTRICT;
|
||||
|
||||
-- Allineamento vista Liste newsletter
|
||||
UPDATE `zz_modules` SET `options` = "
|
||||
|
|
Loading…
Reference in New Issue