Skip to content

Instantly share code, notes, and snippets.

@arsfeld
Created July 1, 2015 17:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arsfeld/eed276cd33bf61b857db to your computer and use it in GitHub Desktop.
Save arsfeld/eed276cd33bf61b857db to your computer and use it in GitHub Desktop.
Laravel 5.1 command to list FileMaker layouts or show information about one specific layout
<?php namespace App\Console\Commands;
use Illuminate\Console\Command;
use Soliant\SimpleFM\Adapter;
class FMShow extends Command {
/**
* The console command signature.
*
* @var string
*/
protected $signature = 'fm:show {tables?*} {--limit=20}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Show data for a table in FileMaker or list layout names';
/**
* @var Adapter
*/
protected $fm;
public function __construct(Adapter $fm)
{
parent::__construct();
$this->fm = $fm;
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$fm = $this->fm;
$tables = $this->argument('tables');
if ($tables) {
foreach ($tables as $table) {
$this->comment("Getting info for $table");
$command = ['-findall' => NULL];
if ($this->option('limit')) {
$command['-max'] = $this->option('limit');
}
$fm->setCommandarray($command);
$fm->setLayoutname(strtoupper($table));
$data = $fm->execute();
$rows = $data["rows"];
if (count($rows) > 0) {
foreach ($rows as &$row) {
foreach ($row as $k => &$v) {
if (starts_with($k, 'c_') || str_contains($k, '---')) {
unset($row[$k]);
}
$v = str_replace("\n", "⏎ ", trim($v));
}
}
$headers = array_keys($rows[0]);
$this->table($headers, $rows);
}
}
} else {
$this->comment("Getting layout names");
$fm->setCommandarray(['-layoutnames'=>NULL]);
$data = $fm->execute();
foreach (array_fetch($data['rows'], 'LAYOUT_NAME') as $column) {
$this->info(" • " . $column);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment