73 lines
1.7 KiB
PHP
73 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
|
|
|
class School extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $guarded = [];
|
|
|
|
public function directors(): HasMany
|
|
{
|
|
return $this->hasMany(User::class);
|
|
}
|
|
|
|
public function users(): HasMany
|
|
{
|
|
return $this->hasMany(User::class);
|
|
}
|
|
|
|
public function emailDomains(): HasMany
|
|
{
|
|
return $this->hasMany(SchoolEmailDomain::class);
|
|
}
|
|
|
|
public function doublerRequests()
|
|
{
|
|
return $this->hasManyThrough(DoublerRequest::class, Student::class);
|
|
}
|
|
|
|
/** TODO: Remove this and concepts of profile picture */
|
|
/** @codeCoverageIgnore */
|
|
public function initialLetterImageURL($bg_color = '4f46e5', $text_color = 'fff'): string
|
|
{
|
|
$img = "https://ui-avatars.com/api/?background=$bg_color&color=$text_color&name=";
|
|
$img .= substr($this->name, 0, 1);
|
|
|
|
return $img;
|
|
}
|
|
|
|
public function students(): HasMany
|
|
{
|
|
return $this->hasMany(Student::class)->orderBy('last_name')->orderBy('first_name');
|
|
}
|
|
|
|
public function entries(): HasManyThrough
|
|
{
|
|
return $this->hasManyThrough(
|
|
Entry::class,
|
|
Student::class,
|
|
'school_id',
|
|
'student_id',
|
|
'id',
|
|
'id');
|
|
}
|
|
|
|
public function nominations(): HasManyThrough
|
|
{
|
|
return $this->hasManyThrough(
|
|
NominationEnsembleEntry::class,
|
|
Student::class,
|
|
'school_id',
|
|
'student_id',
|
|
'id',
|
|
'id');
|
|
}
|
|
}
|