Internal rework pending editframe

This commit is contained in:
Deon George
2019-07-12 10:42:01 +07:00
parent 4f79a1a997
commit 264747e2f3
14 changed files with 611 additions and 428 deletions

View File

@@ -20,6 +20,11 @@ class Mode extends Model
return $this->hasMany(Frame::class);
}
public function frameId(int $id)
{
return $this->frameLoad(Frame::findOrFail($id));
}
/**
* Return a frame class for the Model
*
@@ -27,7 +32,7 @@ class Mode extends Model
* @return FrameClass
* @throws \Exception
*/
public function frame(Model $o): FrameClass
private function frameLoad(Model $o): FrameClass
{
switch (strtolower($this->name)) {
case 'ansi':
@@ -35,10 +40,28 @@ class Mode extends Model
case 'videotex':
return new VideotexFrame($o);
default:
throw new \Exception('Unknown Frame type: '.$mo->name);
throw new \Exception('Unknown Frame type: '.$this->name);
}
}
public function frameNew(Server $so,int $frame,string $index='a'): FrameClass
{
$o = new Frame;
$o->frame = $frame;
$o->index = $index;
$o->mode_id = $this->id;
// Make sure parent frame exists
// @todo make sure not trying to edit test frames
if ($o->index != 'a' AND ! FrameModel::where('frame',$fo->frame())->where('index',$fo->index_prev())->exists())
{
$so->sendBaseline($so->co,ERR_ROUTE);
return new Frame;
}
return $this->frameLoad($o);
}
/**
* Fetch a specific frame from the DB
*
@@ -48,17 +71,28 @@ class Mode extends Model
* @return FrameClass
* @throws \Exception
*/
public function frameLoad(int $frame,string $index,Server $so): FrameClass
public function framePage(int $frame,string $index='a',Server $so): FrameClass
{
return $this->frame(
return ($frame == '999' and $index == 'a')
// Return our internal test frame.
($frame == '999' and $index == 'a')
? $so->testFrame()
: $this->frames()
->where('frame','=',$frame)
->where('index','=',$index)
->firstOrFail()
);
? $this->frameTest($so)
: $this->frameLoad($this->frames()
->where('frame','=',$frame)
->where('index','=',$index)
->firstOrFail()
);
}
public function frameTest(Server $so): FrameClass
{
switch (strtolower($this->name)) {
case 'ansi':
return AnsiFrame::testFrame($so);
case 'videotex':
return VideotexFrame::testFrame($so);
default:
throw new \Exception('Unknown Frame type: '.$this->name);
}
}
/**