snipe-it/app/Models/SavedReport.php

71 lines
1.6 KiB
PHP
Raw Normal View History

2023-08-23 16:32:19 -07:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class SavedReport extends Model
{
use HasFactory;
2023-08-24 11:32:37 -07:00
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'options' => 'array',
];
2023-08-28 16:26:31 -07:00
protected $fillable = [
'user_id',
'name',
'options',
];
2023-11-30 16:57:21 -08:00
public function checkmarkValue($property): string
{
// Assuming we're using the null object pattern,
// return the default value if the object is not saved yet.
if (is_null($this->id)) {
return '1';
}
// Return the property's value if it exists
// and return the default value if not.
return $this->options[$property] ?? '0';
}
2023-11-30 16:57:21 -08:00
public function selectValue($property)
{
return $this->options[$property] ?? null;
}
public function selectValues($property)
{
if (!isset($this->options[$property])) {
return null;
}
if ($this->options[$property] === [null]) {
return null;
}
return $this->options[$property];
}
public function textValue($property): string
{
// Assuming we're using the null object pattern,
// return the default value if the object is not saved yet.
if (is_null($this->id)) {
return '';
}
// Return the property's value if it exists
// and return the default value if not.
return $this->options[$property] ?? '';
}
2023-08-23 16:32:19 -07:00
}