Added page authorisation and cug processing

This commit is contained in:
Deon George
2018-12-10 22:59:02 +11:00
parent 86e29a3cee
commit 4d65bb05a1
15 changed files with 792 additions and 107 deletions

View File

@@ -2,8 +2,12 @@
namespace App\Classes;
use App\Models\Mode;
use Illuminate\Support\Facades\Log;
use App\User;
use App\Models\CUG;
/**
* Handles all aspects of frame
*
@@ -100,12 +104,15 @@ abstract class Frame
/**
* Return a list of alternative versions of this frame.
*
* @todo: Need to adjust to not include access=0 frames unless owner
*/
public function alts()
public function alts(Mode $o)
{
return \App\Models\Frame::where('frame',$this->frame())
->where('index',$this->index())
->where('id','<>',$this->frame->id)
->where('mode_id',$o->id)
->limit(9);
}
@@ -133,6 +140,34 @@ abstract class Frame
return $this->frame->frame;
}
/**
* Get the CUG for a frame
*
* Frame CUG are derived from their frame number.
* EG: Frame 642 is a member of 642, or 64, or 6, or 0, whichever matches first.
*
* @return CUG
*/
public function getCUG()
{
$co = NULL;
$frame = $this->frame->frame;
while (! $co)
{
$co = CUG::find($frame);
if (! $co) {
$frame = substr($frame,0,strlen($frame)-1);
if (! $frame)
$frame = 0;
}
}
return $co;
}
/**
* Return the current field configuration
*/
@@ -197,6 +232,21 @@ abstract class Frame
return chr(ord($this->frame->index)+1);
}
public function isAccessible():bool
{
return $this->frame->access ? TRUE : FALSE;
}
/**
* Determine if the frame is a particular CUG
* @param int $cug
* @return bool
*/
public function isCUG(int $cug): bool
{
return ($this->getCUG()->id == $cug);
}
/**
* Determine if a field is editable
*
@@ -208,6 +258,22 @@ abstract class Frame
return array_get(array_get($this->fieldoptions,$field),'edit',FALSE);
}
/**
* Is this frame Public
*
* @return bool
*/
public function isFramePublic(): bool
{
return $this->frame->closed ? FALSE : TRUE;
}
// @todo To implement
public function isOwner(User $o):bool
{
return FALSE;
}
/**
* Return the Page Number
*/
@@ -312,6 +378,8 @@ abstract class Frame
$o->type = 'a';
$o->frame = 999;
$o->index = 'a';
$o->access = 1;
$o->closed = 0;
// Header
$sid = R_RED.'T'.R_BLUE.'E'.R_GREEN.'S'.R_YELLOW.'T';