openstamanager/modules/attributi_combinazioni/actions.php

93 lines
2.9 KiB
PHP
Raw Normal View History

<?php
2024-02-29 17:42:08 +01:00
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
* Copyright (C) DevCode s.r.l.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
include_once __DIR__.'/../../core.php';
use Modules\AttributiCombinazioni\Attributo;
use Modules\AttributiCombinazioni\ValoreAttributo;
switch (filter('op')) {
case 'add':
2024-03-07 15:38:03 +01:00
$descrizione = post('nome');
$title = post('titolo');
2024-03-20 11:13:28 +01:00
$attributo_new = (new Attributo())->getByField('name', $descrizione);
2024-03-07 15:38:03 +01:00
if ($stato_new) {
flash()->error(tr('Questo nome è già stato utilizzato per un altro attributo.'));
} else {
$attributo = Attributo::build();
2024-03-07 15:38:03 +01:00
$id_record= $dbo->lastInsertedID();
2024-03-20 11:13:28 +01:00
$attributo->setTranslation('name', $descrizione);
$attributo->setTranslation('title', $title);
$attributo->save();
flash()->info(tr('Nuovo attributo creato correttamente!'));
}
break;
case 'update':
2024-03-07 15:38:03 +01:00
$title = post('titolo');
2024-03-20 11:13:28 +01:00
$attributo_new = (new Attributo())->getByField('name', $descrizione);
2024-02-29 17:42:08 +01:00
2024-03-07 15:38:03 +01:00
if (!empty($attributo_new) && $attributo_new != $id_record){
flash()->error(tr('Questo nome è già stato utilizzato per un altro attributo.'));
} else {
2024-03-20 11:13:28 +01:00
$attributo->setTranslation('title', $title);
2024-03-07 15:38:03 +01:00
$attributo->save();
2024-03-07 15:38:03 +01:00
flash()->info(tr('Attributo aggiornato correttamente!'));
}
break;
case 'delete':
$attributo->delete();
flash()->info(tr('Attributo rimosso correttamente!'));
break;
case 'gestione-valore':
$id_valore = filter('id_valore');
$nome = post('nome');
if (!empty($id_valore)) {
$valore = ValoreAttributo::find($id_valore);
$valore->nome = $nome;
$valore->save();
} else {
$valore = ValoreAttributo::build($attributo, $nome);
}
flash()->info(tr('Valore aggiornato correttamente!'));
break;
case 'rimuovi-valore':
$id_valore = filter('id_valore');
if (!empty($id_valore)) {
$valore = ValoreAttributo::find($id_valore);
$valore->delete();
}
flash()->info(tr('Valore rimosso correttamente!'));
break;
}