Created frames table with migration
This commit is contained in:
parent
4504818e25
commit
3651a6508a
@ -56,7 +56,7 @@ class Frame
|
||||
if (! $this->hasFlag('ip')) {
|
||||
// Set the page header: CUG/Site Name | Page # | Cost
|
||||
$this->output .= $this->render_header($this->header).
|
||||
$this->render_page($this->frame->frame_id,$this->frame->subframe_id).
|
||||
$this->render_page($this->frame->frame,$this->frame->index).
|
||||
$this->render_cost($this->frame->cost);
|
||||
}
|
||||
|
||||
@ -93,14 +93,14 @@ class Frame
|
||||
for ($x=0;$x<$this->frame_width;$x++)
|
||||
{
|
||||
$posn = $y*40+$x;
|
||||
$byte = ord(isset($this->frame->frame_content{$posn}) ? $this->frame->frame_content{$posn} : ' ')%128;
|
||||
$byte = ord(isset($this->frame->content{$posn}) ? $this->frame->content{$posn} : ' ')%128;
|
||||
// dump(sprintf('Y: %s,X: %s, POSN: %s, BYTE: %s',$y,$x,$posn,$byte));
|
||||
|
||||
// Check for start-of-field
|
||||
if ($byte == ord(ESC)) { // Esc designates start of field (Esc-K is end of edit)
|
||||
$infield = TRUE;
|
||||
$fieldlength = 0;
|
||||
$fieldtype = ord(substr($this->frame->frame_content,$posn+1,1))%128;
|
||||
$fieldtype = ord(substr($this->frame->content,$posn+1,1))%128;
|
||||
$byte = ord(' '); // Replace ESC with space.
|
||||
|
||||
} else {
|
||||
@ -132,7 +132,7 @@ class Frame
|
||||
// Replace field with Date
|
||||
if ($field == '%date') {
|
||||
if ($fieldlength == 1)
|
||||
$datetime = strtoupper(date('D d M Y H:i:s'));
|
||||
$datetime = date('D d M H:ia');
|
||||
|
||||
if ($fieldlength <= strlen($datetime))
|
||||
$byte = ord($datetime{$fieldlength-1});
|
||||
@ -168,7 +168,7 @@ class Frame
|
||||
}
|
||||
|
||||
// truncate end of lines
|
||||
if (isset($pageflags['tru']) && substr($this->frame->frame_content,$y*40+$x,40-$x) === str_repeat(' ',40-$x)) {
|
||||
if (isset($pageflags['tru']) && substr($this->frame->content,$posn,40-$x) === str_repeat(' ',40-$x)) {
|
||||
$this->output .= CR . LF;
|
||||
break;
|
||||
}
|
||||
@ -183,7 +183,7 @@ class Frame
|
||||
*/
|
||||
public function framenum()
|
||||
{
|
||||
return $this->frame->frame_id.$this->frame->subframe_id;
|
||||
return $this->frame->frame.$this->frame->index;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -253,6 +253,17 @@ class Frame
|
||||
return sprintf(WHITE.'% '.$this->pagenum_length.'.0f%s',$num,$frame);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the route for the key press
|
||||
*
|
||||
* @param string $read
|
||||
*/
|
||||
public function route(string $read)
|
||||
{
|
||||
// @todo
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the length of text
|
||||
*
|
||||
@ -270,21 +281,21 @@ class Frame
|
||||
// Simulate a DB load
|
||||
$o = new \App\Models\Frame;
|
||||
|
||||
$o->frame_content = '';
|
||||
$o->content = '';
|
||||
$o->flags = ['ip'];
|
||||
$o->frametype = 'a';
|
||||
$o->frame_id = 999;
|
||||
$o->subframe_id = 'a';
|
||||
$o->type = 'a';
|
||||
$o->frame = 999;
|
||||
$o->index = 'a';
|
||||
|
||||
// Header
|
||||
$o->frame_content .= substr(R_RED.'T'.R_BLUE.'E'.R_GREEN.'S'.R_YELLOW.'T-12345678901234567890',0,20).
|
||||
$o->content .= substr(R_RED.'T'.R_BLUE.'E'.R_GREEN.'S'.R_YELLOW.'T-12345678901234567890',0,20).
|
||||
R_WHITE.'999999999a'.R_RED.sprintf('%07.0f',999).'u';
|
||||
|
||||
$o->frame_content .= str_repeat('+-',18).' '.R_RED.'01';
|
||||
$o->frame_content .= 'Date: '.ESC.str_repeat('d',25).str_repeat('+-',4);
|
||||
$o->frame_content .= 'Name: '.ESC.str_repeat('u',5).str_repeat('+-',14);
|
||||
$o->frame_content .= 'Address: '.ESC.str_repeat('a',20).''.str_repeat('+-',5);
|
||||
$o->frame_content .= ' : '.ESC.str_repeat('a',20).''.str_repeat('+-',5);
|
||||
$o->content .= str_repeat('+-',18).' '.R_RED.'01';
|
||||
$o->content .= 'Date: '.ESC.str_repeat('d',25).str_repeat('+-',4);
|
||||
$o->content .= 'Name: '.ESC.str_repeat('u',5).str_repeat('+-',14);
|
||||
$o->content .= 'Address: '.ESC.str_repeat('a',20).''.str_repeat('+-',5);
|
||||
$o->content .= ' : '.ESC.str_repeat('a',20).''.str_repeat('+-',5);
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
61
app/Console/Commands/FrameDelete.php
Normal file
61
app/Console/Commands/FrameDelete.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Frame;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class FrameDelete extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'frame:delete {frame} {index}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Delete frames from the database.';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if (! is_numeric($this->argument('frame')))
|
||||
throw new \Exception('Frame is not numeric: '.$this->argument('frame'));
|
||||
|
||||
if (strlen($this->argument('index')) != 1 OR ! preg_match('/^[a-z]$/',$this->argument('index')))
|
||||
throw new \Exception('Subframe failed validation');
|
||||
|
||||
try {
|
||||
$o = Frame::where('frame',$this->argument('frame'))
|
||||
->where('index',$this->argument('index'))
|
||||
->firstOrFail();
|
||||
|
||||
} catch (ModelNotFoundException $e) {
|
||||
$this->error('Page not found to delete: '.$this->argument('frame').$this->argument('index'));
|
||||
die(1);
|
||||
}
|
||||
|
||||
$o->delete();
|
||||
$this->info('Page deleted: '.$this->argument('frame').$this->argument('index'));
|
||||
}
|
||||
}
|
84
app/Console/Commands/FrameImport.php
Normal file
84
app/Console/Commands/FrameImport.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Frame;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
|
||||
class FrameImport extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'frame:import {frame} {index} {file} '.
|
||||
'{--cost=0 : Frame Cost }'.
|
||||
'{--mode=1 : Frame Emulation Mode }'.
|
||||
'{--replace : Replace existing frame}'.
|
||||
'{--type=i : Frame Type}'.
|
||||
'{--trim : Trim off header (first 40 chars)}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Import frames into the database. The frames should be in binary format.';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if (! is_numeric($this->argument('frame')))
|
||||
throw new \Exception('Frame is not numeric: '.$this->argument('frame'));
|
||||
|
||||
if (strlen($this->argument('index')) != 1 OR ! preg_match('/^[a-z]$/',$this->argument('index')))
|
||||
throw new \Exception('Subframe failed validation');
|
||||
|
||||
if (! file_exists($this->argument('file')))
|
||||
throw new \Exception('File not found: '.$this->argument('file'));
|
||||
|
||||
$o = new Frame;
|
||||
if ($this->option('replace')) {
|
||||
try {
|
||||
$o = $o->where('frame',$this->argument('frame'))
|
||||
->where('index',$this->argument('index'))
|
||||
->firstOrFail();
|
||||
|
||||
} catch (ModelNotFoundException $e) {
|
||||
$this->error('Page not found to replace: '.$this->argument('frame').$this->argument('index'));
|
||||
die(1);
|
||||
}
|
||||
|
||||
} else {
|
||||
$o->frame = $this->argument('frame');
|
||||
$o->index = $this->argument('index');
|
||||
}
|
||||
|
||||
$o->content = ($this->option('trim'))
|
||||
? substr(file_get_contents($this->argument('file')),40)
|
||||
: file_get_contents($this->argument('file'));
|
||||
|
||||
$o->cost = $this->option('cost');
|
||||
$o->mode_id = $this->option('mode');
|
||||
$o->type = $this->option('type');
|
||||
|
||||
$o->save();
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -13,25 +13,14 @@ class Frame extends Model
|
||||
* @param string $frame
|
||||
* @return mixed
|
||||
*/
|
||||
public function fetch(int $page,string $frame): \App\Classes\Frame
|
||||
public function fetch(int $frame,string $index): \App\Classes\Frame
|
||||
{
|
||||
if ($page == '999' and $frame == 'a')
|
||||
if ($frame == '999' and $index == 'a')
|
||||
{
|
||||
return new \App\Classes\Frame(\App\Classes\Frame::testFrame());
|
||||
}
|
||||
|
||||
return new \App\Classes\Frame($this->where('frame_id',$page)->where('subframe_id',$frame)->firstOrFail());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the frame cost
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getCostAttribute()
|
||||
{
|
||||
// @todo NOT in DB
|
||||
return rand(0,999);
|
||||
return new \App\Classes\Frame($this->where('frame',$frame)->where('index',$index)->firstOrFail());
|
||||
}
|
||||
|
||||
public function hasFlag(string $flag)
|
||||
@ -45,7 +34,6 @@ class Frame extends Model
|
||||
*/
|
||||
public function type()
|
||||
{
|
||||
// @todo in DB
|
||||
return isset($this->frametype) ? $this->frametype : 'i';
|
||||
return $this->type ?: 'i';
|
||||
}
|
||||
}
|
53
app/Traits/HasCompositePrimaryKey.php
Normal file
53
app/Traits/HasCompositePrimaryKey.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use \Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
/**
|
||||
* Trait HasCompositePrimaryKey
|
||||
* Enables primary keys to be an array.
|
||||
*
|
||||
* @package App\Traits
|
||||
*/
|
||||
trait HasCompositePrimaryKey {
|
||||
/**
|
||||
* Set the keys for a save update query.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
protected function setKeysForSaveQuery(Builder $query)
|
||||
{
|
||||
$keys = $this->getKeyName();
|
||||
|
||||
if (! is_array($keys)){
|
||||
return parent::setKeysForSaveQuery($query);
|
||||
}
|
||||
|
||||
foreach ($keys as $keyName){
|
||||
$query->where($keyName, '=', $this->getKeyForSaveQuery($keyName));
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the primary key value for a save query.
|
||||
*
|
||||
* @param mixed $keyName
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getKeyForSaveQuery($keyName = null)
|
||||
{
|
||||
if (is_null($keyName)){
|
||||
$keyName = $this->getKeyName();
|
||||
}
|
||||
|
||||
if (isset($this->original[$keyName])) {
|
||||
return $this->original[$keyName];
|
||||
}
|
||||
|
||||
return $this->getAttribute($keyName);
|
||||
}
|
||||
}
|
@ -40,7 +40,7 @@
|
||||
"App\\": "app/"
|
||||
},
|
||||
"files": [
|
||||
"bootstrap/constants.php"
|
||||
"config/constants.php"
|
||||
],
|
||||
"classmap": [
|
||||
"database/seeds",
|
||||
|
79
database/migrations/2018_12_03_104758_init_database.php
Normal file
79
database/migrations/2018_12_03_104758_init_database.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class InitDatabase extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$this->down();
|
||||
|
||||
Schema::create('modes', function (Blueprint $table) {
|
||||
$table->timestamps();
|
||||
$table->integer('id')->autoIncrement();
|
||||
$table->string('name',16);
|
||||
$table->string('note',255);
|
||||
|
||||
$table->unique(['name']);
|
||||
});
|
||||
|
||||
Schema::create('cugs', function (Blueprint $table) {
|
||||
$table->timestamps();
|
||||
$table->integer('id');
|
||||
$table->string('name',16);
|
||||
$table->string('note',255);
|
||||
$table->integer('parent_id')->nullable();
|
||||
|
||||
$table->primary('id');
|
||||
$table->foreign('parent_id')->references('id')->on('cugs');
|
||||
$table->unique(['name']);
|
||||
});
|
||||
|
||||
Schema::create('frames', function (Blueprint $table) {
|
||||
$table->timestamps();
|
||||
$table->integer('id')->autoIncrement();
|
||||
$table->integer('frame');
|
||||
$table->char('index',1);
|
||||
$table->integer('mode_id');
|
||||
$table->char('type',2);
|
||||
$table->smallInteger('cost')->default(0);
|
||||
$table->integer('cug_id')->default(0);
|
||||
$table->boolean('public')->default(FALSE);
|
||||
$table->binary('content');
|
||||
$table->string('note',255)->nullable();
|
||||
|
||||
//$table->unique(['frame','index','mode_id']); // Not needed since we have timewarp
|
||||
|
||||
$table->foreign('mode_id')->references('id')->on('modes');
|
||||
$table->foreign('cug_id')->references('id')->on('cugs');
|
||||
});
|
||||
|
||||
Schema::create('routes', function (Blueprint $table) {
|
||||
$table->integer('id')->autoIncrement();
|
||||
$table->char('key',1);
|
||||
$table->integer('route');
|
||||
|
||||
$table->foreign('route')->references('id')->on('frames');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('routes');
|
||||
Schema::dropIfExists('frames');
|
||||
Schema::dropIfExists('cugs');
|
||||
Schema::dropIfExists('modes');
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ class DatabaseSeeder extends Seeder
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
// $this->call(UsersTableSeeder::class);
|
||||
$this->call(SeedMode::class);
|
||||
$this->call(SeedCUG::class);
|
||||
}
|
||||
}
|
||||
}
|
21
database/seeds/SeedCUG.php
Normal file
21
database/seeds/SeedCUG.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class SeedCUG extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
DB::table('cugs')->insert([
|
||||
'created_at' => now(),
|
||||
'id' => 0,
|
||||
'name' => 'Public Frames',
|
||||
'note' => 'All frames belong to this CUG if not any other.',
|
||||
]);
|
||||
}
|
||||
}
|
20
database/seeds/SeedMode.php
Normal file
20
database/seeds/SeedMode.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class SeedMode extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
DB::table('modes')->insert([
|
||||
'created_at' => now(),
|
||||
'name' => 'ViewData',
|
||||
'note' => 'Original ViewData/VideoTex 40x25 char mode.',
|
||||
]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user