2018-12-01 21:50:34 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2018-12-05 10:50:38 +00:00
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
2018-12-01 21:50:34 +00:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
class Frame extends Model
|
|
|
|
{
|
2018-12-29 12:24:41 +00:00
|
|
|
public $cache_content = '';
|
|
|
|
|
2018-12-10 11:59:02 +00:00
|
|
|
public function cug()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(CUG::class);
|
|
|
|
}
|
|
|
|
|
2018-12-11 12:31:44 +00:00
|
|
|
public function route()
|
|
|
|
{
|
|
|
|
return $this->hasOne(FrameMeta::class);
|
|
|
|
}
|
|
|
|
|
2018-12-05 10:50:38 +00:00
|
|
|
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()
|
|
|
|
{
|
2018-12-29 12:24:41 +00:00
|
|
|
// For stream resources, we need to cache this result.
|
|
|
|
if (! $this->cache_content) {
|
|
|
|
$this->cache_content = is_resource($this->attributes['content'])
|
|
|
|
? stream_get_contents($this->attributes['content'])
|
|
|
|
: $this->attributes['content'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->cache_content;
|
2018-12-25 01:48:57 +00:00
|
|
|
}
|
|
|
|
|
2018-12-05 10:50:38 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
}
|
|
|
|
}
|