73 lines
1.6 KiB
PHP
Executable File
73 lines
1.6 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class TipoRelazionePersonaUnita extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'tipi_relazione_persona_unita';
|
|
|
|
protected $fillable = [
|
|
'codice',
|
|
'descrizione',
|
|
'richiede_quota',
|
|
'vota_assemblea',
|
|
'riceve_convocazioni',
|
|
'ordine_visualizzazione',
|
|
'attivo'
|
|
];
|
|
|
|
protected $casts = [
|
|
'richiede_quota' => 'boolean',
|
|
'vota_assemblea' => 'boolean',
|
|
'riceve_convocazioni' => 'boolean',
|
|
'attivo' => 'boolean',
|
|
'ordine_visualizzazione' => 'integer'
|
|
];
|
|
|
|
/**
|
|
* Relazioni che usano questo tipo
|
|
*/
|
|
public function relazioni(): HasMany
|
|
{
|
|
return $this->hasMany(PersonaUnitaRelazione::class, 'tipo_relazione', 'codice');
|
|
}
|
|
|
|
/**
|
|
* SCOPE: Tipi attivi
|
|
*/
|
|
public function scopeAttivi($query)
|
|
{
|
|
return $query->where('attivo', true);
|
|
}
|
|
|
|
/**
|
|
* SCOPE: Ordinati per visualizzazione
|
|
*/
|
|
public function scopeOrdinati($query)
|
|
{
|
|
return $query->orderBy('ordine_visualizzazione')->orderBy('descrizione');
|
|
}
|
|
|
|
/**
|
|
* SCOPE: Che possono votare
|
|
*/
|
|
public function scopeVotanti($query)
|
|
{
|
|
return $query->where('vota_assemblea', true);
|
|
}
|
|
|
|
/**
|
|
* SCOPE: Che richiedono quota di proprietà
|
|
*/
|
|
public function scopeConQuota($query)
|
|
{
|
|
return $query->where('richiede_quota', true);
|
|
}
|
|
}
|