Printing data on numpad key press, first version. Settings page for mapping key to actions.

This commit is contained in:
kplaczek
2018-05-06 21:03:42 +02:00
parent 283c5b905e
commit e5f44b92e4
12 changed files with 535 additions and 61 deletions

View File

@@ -0,0 +1,93 @@
<?php
/**
* Created by PhpStorm.
* User: k
* Date: 10.02.2017
* Time: 20:10
*/
namespace App\Http\Controllers;
set_time_limit(-1);
use App\Paper\Airly;
use App\Paper\Paper;
use Illuminate\Http\Request;
class AirlyController extends Controller
{
private $paper = null;
public function __construct()
{
$this->paper = new Paper();
}
/**
* get:/airly_all
* @return \Illuminate\Http\RedirectResponse
*/
public function airly_all()
{
$airly = new Airly();
$this->paper->sendImagePrint($airly->icon);
$this->paper->sendHeaderPrint('Jakość powietrza:' . PHP_EOL . date('H:i d-m-Y'));
$airly->setStations(config('paper.airly.stations'));
foreach ($airly->getStations() as $stationId) {
$stationInfo = $airly->getStationInfo($stationId);
$this->paper->sendHeaderPrint($stationInfo['address']['locality'] . ' ' . $stationInfo['address']['route']);
$dataText = $airly->getInformationText($stationId);
$this->paper->sendPrint('', $dataText);
}
return back();
}
public function airly_rzeczypospolitej()
{
$airly = new Airly();
$this->paper->sendImagePrint($airly->icon);
$this->paper->sendHeaderPrint('Jakość powietrza:' . PHP_EOL . date('H:i d-m-Y'));
$airly->setStations([config('paper.airly.rzeczypospolitej')]);
foreach ($airly->getStations() as $stationId) {
$stationInfo = $airly->getStationInfo($stationId);
$this->paper->sendHeaderPrint($stationInfo['address']['locality'] . ' ' . $stationInfo['address']['route']);
$dataText = $airly->getInformationText($stationId);
$this->paper->sendPrint('', $dataText);
}
return back();
}
public function airly_grunwaldzka()
{
$airly = new Airly();
$this->paper->sendImagePrint($airly->icon);
$this->paper->sendHeaderPrint('Jakość powietrza:' . PHP_EOL . date('H:i d-m-Y'));
$airly->setStations([config('paper.airly.grunwaldzka')]);
foreach ($airly->getStations() as $stationId) {
$stationInfo = $airly->getStationInfo($stationId);
$this->paper->sendHeaderPrint($stationInfo['address']['locality'] . ' ' . $stationInfo['address']['route']);
$dataText = $airly->getInformationText($stationId);
$this->paper->sendPrint('', $dataText);
}
return back();
}
public function airly_sowinskiego()
{
$airly = new Airly();
$this->paper->sendImagePrint($airly->icon);
$this->paper->sendHeaderPrint('Jakość powietrza:' . PHP_EOL . date('H:i d-m-Y'));
$airly->setStations([config('paper.airly.sowinskiego')]);
foreach ($airly->getStations() as $stationId) {
$stationInfo = $airly->getStationInfo($stationId);
$this->paper->sendHeaderPrint($stationInfo['address']['locality'] . ' ' . $stationInfo['address']['route']);
$dataText = $airly->getInformationText($stationId);
$this->paper->sendPrint('', $dataText);
}
return back();
}
}

View File

@@ -2,25 +2,127 @@
namespace App\Http\Controllers;
use App\Paper\CinemaMultikino;
use DiDom\Query;
use Illuminate\Http\Request;
use DiDom\Document;
use App\Paper\Paper;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class Keyboard extends Controller
{
private $paper;
public function __construct()
public function press(Request $request, $key)
{
$this->paper = new Paper();
}
public function press($key)
{
$this->paper->sendPrint($key);
$keyboardData = DB::table('keyboard')->where('key', $key)->first();
if (isset($keyboardData) && isset($keyboardData->action)) {
$keyboardAction = explode('_', $keyboardData->action);
switch ($keyboardAction[0]) {
case 'settings':
$settings = new Settings();
$settings->printMappedKeys();
break;
case 'airly':
$airly = new AirlyController();
switch ($keyboardAction[1]) {
case 'all':
$airly->airly_all();
break;
case 'rzeczypospolitej':
$airly->airly_rzeczypospolitej();
break;
case 'grunwaldzka':
$airly->airly_grunwaldzka();
break;
case 'sowinskiego':
$airly->airly_sowinskiego();
break;
}
break;
case 'note':
switch ($keyboardAction[1]) {
case 'last':
$main = new Main();
$main->noteLast();
break;
case $keyboardAction[1] > 0:
echo 'test';
$main = new Main();
$main->printNote((int)$keyboardAction[1]);
break;
}
break;
case 'repertoire':
switch ($keyboardAction[1]) {
case 'all':
switch ($keyboardAction[2]) {
case 'today':
$repertoire = new Repertoire();
$repertoire->today_repertoire($request);
break;
case 'tomorrow':
$repertoire = new Repertoire();
$repertoire->tomorrow_repertoire($request);
break;
}
break;
case 'helios':
switch ($keyboardAction[2]) {
case 'today':
$repertoire = new Repertoire();
$repertoire->today_helios($request);
break;
case 'tomorrow':
$repertoire = new Repertoire();
$repertoire->tomorrow_helios($request);
break;
}
break;
case 'multikino':
switch ($keyboardAction[2]) {
case 'today':
$repertoire = new Repertoire();
$repertoire->today_multikino($request);
break;
case 'tomorrow':
$repertoire = new Repertoire();
$repertoire->tomorrow_multikino($request);
break;
}
break;
case 'cinemacity':
switch ($keyboardAction[2]) {
case 'today':
$repertoire = new Repertoire();
$repertoire->today_cinemacity($request);
break;
case 'tomorrow':
$repertoire = new Repertoire();
$repertoire->tomorrow_cinemacity($request);
break;
}
break;
case 'gdynskiecentrumfilmowe':
switch ($keyboardAction[2]) {
case 'today':
$repertoire = new Repertoire();
$repertoire->today_gdynskiecentrumfilmowe($request);
break;
case 'tomorrow':
$repertoire = new Repertoire();
$repertoire->tomorrow_gdynskiecentrumfilmowe($request);
break;
}
break;
}
break;
}
}
}
}

View File

@@ -34,6 +34,7 @@ class Main extends Controller
* post::/printImage
* @param Request $request
* @return \Illuminate\Http\RedirectResponse
* @throws \Exception
*/
public function imagePrint(Request $request)
{
@@ -138,28 +139,6 @@ class Main extends Controller
]);
}
/**
* get:/airly
* @param Request $request
* @return \Illuminate\Http\RedirectResponse
*/
public function airly(Request $request)
{
$airly = new Airly();
$this->paper->sendImagePrint($airly->icon);
$this->paper->sendHeaderPrint('Jakość powietrza:' . PHP_EOL . date('H:i d-m-Y'));
$airly->setStations(config('paper.airly.stations'));
foreach ($airly->getStations() as $stationId) {
$stationInfo = $airly->getStationInfo($stationId);
$this->paper->sendHeaderPrint($stationInfo['address']['locality'] . ' ' . $stationInfo['address']['route']);
$dataText = $airly->getInformationText($stationId);
$this->paper->sendPrint('', $dataText);
}
return back();
}
/**
* post::/print/{id}
* @param Request $request
@@ -168,15 +147,24 @@ class Main extends Controller
*/
public function printText(Request $request, $id)
{
$note = DB::table('note')->where('id', $id)->first();
$this->paper->sendPrint($note->topic, $note->text, $note->icon);
$note = $this->printNote($id);
$request->session()->flash('print_status', 'Wydrukowano notatkę: ' . $note->topic . '!');
return back();
}
public function printNote($noteId){
$note = DB::table('note')->where('id', $noteId)->first();
$this->paper->sendPrint($note->topic, $note->text, $note->icon);
return $note;
}
public function noteLast(){
$note = DB::table('note')->orderBy('id', 'desc')->first();
$this->printNote($note->id);
}
private function templateReplace($input)
{
return str_replace(['[d]', '[m]', '[y]', '[h]', '[i]', '[s]'],
[date('d'), date('m'), date('Y'), date('H'), date('i'), date('s')],
$input);

View File

@@ -0,0 +1,119 @@
<?php
/**
* Created by PhpStorm.
* User: k
* Date: 10.02.2017
* Time: 20:10
*/
namespace App\Http\Controllers;
set_time_limit(-1);
use App\Paper\Paper;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
class Settings extends Controller
{
private $paper = null;
public function __construct()
{
$this->paper = new Paper();
}
/**
* get:/
* @param Request $request
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function mainView(Request $request)
{
$keyboard = DB::select('SELECT * FROM keyboard');
return view('settings', [
'keyboard' => $keyboard,
'actions' => $this->getActions()
]);
}
public function getMappedKeys()
{
$keys = DB::table('keyboard')->get();
$text = '';
$actions = $this->getActions('');
foreach ($keys as $key) {
$text .= '[' . $key->key . '] ' . $actions[$key->action] . "\n";
}
return $text;
}
public function printMappedKeys()
{
$this->paper->sendPrint('Zmapowane klawisze', $this->getMappedKeys());
}
public function save(Request $request)
{
foreach ($request->input('key') as $keyid => $keyValue) {
DB::table('keyboard')
->where('id', $keyid)
->update([
'action' => $keyValue,
]);
}
return redirect()->route('settingsList');
}
private function getActions($noActionText = 'Bez akcji')
{
$actions = [];
$actions[''] = $noActionText;
$actions['separator0'] = 'separator';
$actions['settings_list'] = 'Lista zmapowanych klawiszy';
$actions['separator1'] = 'separator';
$actions['repertoire_all_today'] = 'Repertuar wszystkie kina dzisiaj';
$actions['repertoire_all_tomorrow'] = 'Repertuar wszystkie kina jutro';
$actions['repertoire_helios_today'] = 'Repertuar Helios dzisiaj';
$actions['repertoire_helios_tomorrow'] = 'Repertuar Helios jutro';
$actions['repertoire_multikino_today'] = 'Repertuar Multikino dzisiaj';
$actions['repertoire_multikino_tomorrow'] = 'Repertuar Multikino jutro';
$actions['repertoire_cinemacity_today'] = 'Repertuar Cinema-City dzisiaj';
$actions['repertoire_cinemacity_tomorrow'] = 'Repertuar Cinema-City jutro';
$actions['repertoire_gdynskiecentrumfilmowe_today'] = 'Repertuar Gdyńskie Centrum filmowe dzisiaj';
$actions['repertoire_gdynskiecentrumfilmowe_tomorrow'] = 'Repertuar Gdyńskie Centrum filmowe jutro';
$actions['separator2'] = 'separator';
$actions['airly_all'] = 'Airly wszystkie stacje';
$actions['airly_rzeczypospolitej'] = 'Airly (Rzeczypospolitej)';
$actions['airly_grunwaldzka'] = 'Airly (Grunwaldzka)';
$actions['airly_sowinskiego'] = 'Airly (Sowińskiego)';
// $actions['separator3'] = 'separator';
// $actions['spacex_next_flight'] = 'Najbliższy lot SpaceX';
// $actions['spacex_prev_flight'] = 'Poprzedni lot SpaceX';
// $actions['spacex_all_next_summary'] = 'Wszystkie zaplanowane loty SpaceX (skrót)';
$actions['separator4'] = 'separator';
$actions['note_last'] = 'Ostatnia zapisana notatka';
$actions['separator5'] = 'separator';
$notes = DB::select('SELECT * FROM note WHERE type = "note" ORDER BY updated_at DESC');
foreach ($notes as $note) {
$actions['note_' . $note->id] = 'Notatka: ' . $note->topic;
}
return $actions;
}
}