92 lines
1.9 KiB
PHP
92 lines
1.9 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Models\BBS;
|
||
|
|
||
|
use Illuminate\Database\Eloquent\Builder;
|
||
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
||
|
use App\Casts\CompressedString;
|
||
|
|
||
|
/*
|
||
|
* Frames belong to a CUG, and if no cug present, they are assigned to CUG 2, the "null CUG" to which all users
|
||
|
* have access. In our implementation, we are using CUG 0 for this purpose.
|
||
|
*
|
||
|
* Users can see a frame if:
|
||
|
* + The User Access is "Y"
|
||
|
* + If the frame is assigned to a CUG, then only if the user is a member of that CUG can they access
|
||
|
* + If the User Access is "N", then only the IP owner can access the frame.
|
||
|
*
|
||
|
* Frame types:
|
||
|
* + I, i or space = information frame
|
||
|
* + A, a, R or r = response frame
|
||
|
*/
|
||
|
|
||
|
class Frame extends Model
|
||
|
{
|
||
|
protected $casts = [
|
||
|
'content' => CompressedString::class,
|
||
|
];
|
||
|
|
||
|
public $cache_content = '';
|
||
|
|
||
|
public function cug()
|
||
|
{
|
||
|
return $this->belongsTo(CUG::class);
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
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');
|
||
|
});
|
||
|
}
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* For cockroachDB, content is a "resource stream"
|
||
|
*
|
||
|
* @return bool|string
|
||
|
*/
|
||
|
public function xgetContentAttribute()
|
||
|
{
|
||
|
// 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;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Return the Page Number
|
||
|
*
|
||
|
* @return string
|
||
|
*/
|
||
|
public function getPageAttribute()
|
||
|
{
|
||
|
return $this->frame.$this->index;
|
||
|
}
|
||
|
|
||
|
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()
|
||
|
{
|
||
|
return $this->type ?: 'i';
|
||
|
}
|
||
|
}
|