Allineamento add template email

This commit is contained in:
Pek5892 2024-03-07 14:52:41 +01:00
parent 877379134b
commit 675d1f11da
4 changed files with 124 additions and 44 deletions

View File

@ -17,43 +17,40 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use Modules\Emails\Template;
include_once __DIR__.'/../../core.php';
switch (post('op')) {
case 'add':
$dbo->insert('em_templates', [
'id_module' => post('module'),
'id_account' => post('smtp'),
]);
$id_record = $dbo->lastInsertedID();
$dbo->insert('em_templates_lang', [
'name' => post('name'),
'subject' => post('subject'),
'id_lang' => setting('Lingua'),
'id_record' => $id_record
]);
$id_module = post('module');
$id_account = post('smtp');
$name = post('name');
$subject = post('subject');
$template = Template::build($id_module, $id_account);
$id_record = $template->id;
$template->name = $name;
$template->subject = $subject;
$template->save();
flash()->info(tr('Aggiunto nuovo template per le email!'));
break;
case 'update':
$dbo->update('em_templates', [
'id_account' => post('smtp'),
'icon' => post('icon'),
'tipo_reply_to' => post('tipo_reply_to'),
'reply_to' => post('reply_to'),
'cc' => post('cc'),
'bcc' => post('bcc'),
'read_notify' => post('read_notify'),
'note_aggiuntive' => post('note_aggiuntive')
], ['id' => $id_record]);
$dbo->update('em_templates_lang', [
'name' => post('name'),
'subject' => post('subject'),
'body' => post('body')
], ['id_record' => $id_record, 'id_lang' => (setting('Lingua'))]);
$template->name = post('name');
$template->id_account = post('smtp');
$template->icon = post('icon');
$template->tipo_reply_to = post('tipo_reply_to');
$template->reply_to = post('reply_to');
$template->cc = post('cc');
$template->bcc = post('bcc');
$template->read_notify = post('read_notify');
$template->note_aggiuntive = post('note_aggiuntive');
$template->subject = post('subject');
$template->body = post('body');
$template->save();
$dbo->sync('em_print_template', ['id_template' => $id_record], ['id_print' => (array) post('prints')]);
$dbo->sync('em_mansioni_template', ['id_template' => $id_record], ['idmansione' => (array) post('idmansioni')]);

View File

@ -18,12 +18,15 @@
*/
use Modules\Newsletter\Newsletter;
use Modules\Emails\Template;
include_once __DIR__.'/../../core.php';
if (isset($id_record)) {
$record = $dbo->fetchOne('SELECT * FROM em_templates LEFT JOIN `em_templates_lang` ON (`em_templates`.`id` = `em_templates_lang`.`id_record` AND `em_templates_lang`.`id_lang` = '.prepare(setting('Lingua')).') WHERE `em_templates`.`id`='.prepare($id_record).' AND `deleted_at` IS NULL');
$template = Template::find($id_record);
// Controllo se ci sono newletter collegate a questo template
$newsletters = Newsletter::where('id_template', $id_record)->get();
}

View File

@ -44,6 +44,16 @@ class Template extends Model
return (array) $variables;
}
public static function build($id_module, $id_account)
{
$model = new static();
$model->id_module = $id_module;
$model->id_account = $id_account;
$model->save();
return $model;
}
/* Relazioni Eloquent */
public function module()
@ -75,6 +85,29 @@ class Template extends Model
->first()->name;
}
/**
* Imposta l'attributo name 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 subject del template.
*
@ -89,6 +122,30 @@ class Template extends Model
->first()->subject;
}
/**
* Imposta l'attributo subject del template.
*/
public function setSubjectAttribute($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([
'subject' => $value
]);
} else {
$table->insert([
'id_record' => $this->id,
'id_lang' => setting('Lingua'),
'subject' => $value
]);
}
}
/**
* Ritorna l'attributo body del template.
*
@ -102,6 +159,29 @@ class Template extends Model
->where('id_lang', '=', setting('Lingua'))
->first()->body;
}
/**
* Imposta l'attributo body del template.
*/
public function setBodyAttribute($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([
'body' => $value
]);
} else {
$table->insert([
'id_record' => $this->id,
'id_lang' => setting('Lingua'),
'body' => $value
]);
}
}
/**
* Ritorna l'id del template a partire dal nome.

View File

@ -145,7 +145,7 @@ class Lista extends Model
}
/**
* Imposta l'attributo name della lista.
* Imposta l'attributo description della lista.
*/
public function setDescriptionAttribute($value)
{
@ -169,7 +169,22 @@ class Lista extends Model
}
/**
* Imposta l'attributo description della lista.
* Ritorna l'attributo description della lista.
*
* @return string
*/
public function getDescriptionAttribute()
{
return database()->table($this->table.'_lang')
->select('description')
->where('id_record', '=', $this->id)
->where('id_lang', '=', setting('Lingua'))
->first()->description;
}
/**
* Imposta l'attributo name della lista.
*/
public function setNameAttribute($value)
{
@ -192,21 +207,6 @@ class Lista extends Model
}
}
/**
* Ritorna l'attributo description della lista.
*
* @return string
*/
public function getDescriptionAttribute()
{
return database()->table($this->table.'_lang')
->select('description')
->where('id_record', '=', $this->id)
->where('id_lang', '=', setting('Lingua'))
->first()->description;
}
/**
* Ritorna l'id della lista a partire dal nome.
*