79 lines
2.1 KiB
PHP
79 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Article extends Model
|
|
{
|
|
protected $table = 'T_WEB_Articoli';
|
|
|
|
/*
|
|
public function authors()
|
|
{
|
|
return $this->hasMany(Author::class);
|
|
}
|
|
*/
|
|
|
|
public function getAuthorsAttribute()
|
|
{
|
|
$authorId = $this->getRawOriginal('ListaAutori');
|
|
$ids = explode(",", $authorId);
|
|
$autori = [];
|
|
foreach ($ids as $id) {
|
|
|
|
$autore = Author::where('IdAutore', $id)->orderBy('DataOra', 'desc')->first();
|
|
if ($autore) {
|
|
//$autori[] = ($autore->Nome != '' ? trim($autore->Nome) . " " : '') . trim($autore->Cognome);
|
|
$autori[] = trim($autore->Nome) . "," . trim($autore->Cognome);
|
|
}
|
|
}
|
|
|
|
return $autori;
|
|
}
|
|
|
|
public function getStockAttribute()
|
|
{
|
|
$qtas = Stock::where('Codice', $this->IdArticolo)->orderBy('DataOra', 'desc');
|
|
if ($qtas->count() > 0) {
|
|
$qta = $qtas->first();
|
|
$disponibilita = $qta->QtaDisponibile;
|
|
} else {
|
|
$disponibilita = 0;
|
|
}
|
|
return $disponibilita;
|
|
}
|
|
public function getStatoprodottoAttribute()
|
|
{
|
|
$status = Statusproduct::where('IdStatoProdotto', $this->IdStatoProdotto)->orderBy('DataOra', 'desc')->first();
|
|
return $status->Descrizione;
|
|
}
|
|
|
|
public function getEditoreAttribute()
|
|
{
|
|
if ($this->IdMarchioEditoriale > 0) {
|
|
$editore = Publisher::where('IdMarchioEditoriale', $this->IdMarchioEditoriale)->orderBy('DataOra', 'desc')->first();
|
|
return $editore->Descrizione;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public function getArgomentoAttribute()
|
|
{
|
|
$argomenti = Category::where('IdArgomento', $this->ListaArgomenti)->orderBy('DataOra', 'desc');
|
|
if ($argomenti->count() > 0) {
|
|
$argomento = $argomenti->first();
|
|
$descrizione = $argomento->Descrizione;
|
|
} else {
|
|
$descrizione = "Nessuna categoria";
|
|
}
|
|
return $descrizione;
|
|
}
|
|
|
|
public function nimaia()
|
|
{
|
|
return $this->hasOne('App\Artnim', 'id_gm', 'IdArticolo');
|
|
}
|
|
}
|