This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
vbbs/app/Models/Frame.php

63 lines
1.1 KiB
PHP
Raw Normal View History

2018-12-01 21:50:34 +00:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
2018-12-01 21:50:34 +00:00
use Illuminate\Database\Eloquent\Model;
class Frame extends Model
{
public function cug()
{
return $this->belongsTo(CUG::class);
}
2018-12-11 12:31:44 +00:00
public function route()
{
return $this->hasOne(FrameMeta::class);
}
protected static function boot() {
parent::boot();
static::addGlobalScope('order', function (Builder $builder) {
$builder->orderBy('created_at','DESC');
});
}
2018-12-25 01:48:57 +00:00
/**
* For cockroachDB, content is a "resource stream"
*
* @return bool|string
*/
public function getContentAttribute()
{
return is_resource($this->attributes['content'])
? stream_get_contents($this->attributes['content'])
: $this->attributes['content'];
}
/**
* Return the Page Number
*
* @return string
*/
public function getPageAttribute()
{
return $this->frame.$this->index;
}
2018-12-01 21:50:34 +00:00
public function hasFlag(string $flag)
{
// @todo When flags is in the DB update this.
return isset($this->flags) ? in_array($flag,$this->flags,FALSE) : FALSE;
}
/**
* Frame Types
*/
public function type()
{
2018-12-03 12:59:22 +00:00
return $this->type ?: 'i';
2018-12-01 21:50:34 +00:00
}
}