hasMany(Frame::class); } public function frameId(int $id) { return $this->frameLoad(Frame::findOrFail($id)); } /** * Return a frame class for the Model * * @param Model $o * @return FrameClass * @throws \Exception */ private function frameLoad(Model $o): FrameClass { switch (strtolower($this->name)) { case 'ansi': return new AnsiFrame($o); case 'videotex': return new VideotexFrame($o); default: 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 * * @param int $frame * @param string $index * @param Server $so * @return FrameClass * @throws \Exception */ public function framePage(int $frame,string $index='a',Server $so): FrameClass { return ($frame == '999' and $index == 'a') // Return our internal test frame. ? $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); } } /** * Return our server instance */ public function server() { switch (strtolower($this->name)) { case 'ansi': return new AnsiServer($this); case 'videotex': return new VideotexServer($this); default: throw new \Exception('Unknown server type: '.$this->name); } } }