mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-03 09:17:37 +01:00
Allineamento add attributi
This commit is contained in:
parent
659ea9f97a
commit
2d3465ce4f
@ -24,30 +24,35 @@ use Modules\AttributiCombinazioni\ValoreAttributo;
|
||||
|
||||
switch (filter('op')) {
|
||||
case 'add':
|
||||
$nome = post('nome');
|
||||
$esistente = (new Attributo())->getByName(post('nome'));
|
||||
$descrizione = post('nome');
|
||||
$title = post('titolo');
|
||||
$attributo_new = (new Attributo())->getByName($descrizione)->id_record;
|
||||
|
||||
if (!$esistente) {
|
||||
if ($stato_new) {
|
||||
flash()->error(tr('Questo nome è già stato utilizzato per un altro attributo.'));
|
||||
} else {
|
||||
$attributo = Attributo::build();
|
||||
$id_record= $dbo->lastInsertedID();
|
||||
$attributo->name = $descrizione;
|
||||
$attributo->title = $title;
|
||||
$attributo->save();
|
||||
|
||||
$id_record = $attributo->id;
|
||||
|
||||
$database->query('INSERT INTO `mg_attributi_lang` (`id_record`, `id_lang`, `name`, `title`) VALUES ('.$id_record.', '.setting('Lingua').', \''.post('nome').'\', \''.post('titolo').'\')');
|
||||
|
||||
flash()->info(tr('Nuovo attributo creato correttamente!'));
|
||||
} else {
|
||||
flash()->error(tr('Attributo esistente con lo stesso nome!'));
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'update':
|
||||
$title = post('titolo');
|
||||
$attributo_new = (new Attributo())->getByName($descrizione)->id_record;
|
||||
|
||||
$attributo->save();
|
||||
|
||||
flash()->info(tr('Attributo aggiornato correttamente!'));
|
||||
if (!empty($attributo_new) && $attributo_new != $id_record){
|
||||
flash()->error(tr('Questo nome è già stato utilizzato per un altro attributo.'));
|
||||
} else {
|
||||
$attributo->title = $title;
|
||||
$attributo->save();
|
||||
|
||||
flash()->info(tr('Attributo aggiornato correttamente!'));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
|
@ -13,6 +13,14 @@ class Attributo extends Model
|
||||
|
||||
protected $table = 'mg_attributi';
|
||||
|
||||
public static function build()
|
||||
{
|
||||
$model = new static();
|
||||
$model->save();
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
/* Relazioni Eloquent */
|
||||
public function valori()
|
||||
{
|
||||
@ -34,6 +42,30 @@ class Attributo extends Model
|
||||
->first()->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Imposta l'attributo name dell'attributo.
|
||||
*/
|
||||
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 title dell'attributo.
|
||||
*
|
||||
@ -48,6 +80,30 @@ class Attributo extends Model
|
||||
->first()->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Imposta l'attributo title dell'attributo.
|
||||
*/
|
||||
public function setTitleAttribute($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([
|
||||
'title' => $value
|
||||
]);
|
||||
} else {
|
||||
$table->insert([
|
||||
'id_record' => $this->id,
|
||||
'id_lang' => setting('Lingua'),
|
||||
'title' => $value
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ritorna l'id dell'attributo a partire dal nome.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user