Printing data on numpad key press, first version. Settings page for mapping key to actions.
This commit is contained in:
93
app/Http/Controllers/AirlyController.php
Normal file
93
app/Http/Controllers/AirlyController.php
Normal 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();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
119
app/Http/Controllers/Settings.php
Normal file
119
app/Http/Controllers/Settings.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,7 +24,7 @@ class Airly
|
||||
return $this->stations;
|
||||
}
|
||||
|
||||
public function setStations($stations){
|
||||
public function setStations(array $stations){
|
||||
$this->stations = $stations;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,9 +26,6 @@ class CinemaCinemaCity implements Cinema
|
||||
if (is_null($this->cinemaId) || is_null($this->day))
|
||||
throw new \Exception('Day or cinemaid not set.');
|
||||
|
||||
// if (!is_array($this->cinemaId)) {
|
||||
// $this->cinemaId = (array)$this->cinemaId;
|
||||
// }
|
||||
$url = 'https://www.cinema-city.pl/pgm-list-byfeat?si=' . $this->cinemaId . '&sort=cin&bd=' . $this->day;
|
||||
|
||||
return file_get_contents($url);
|
||||
@@ -41,9 +38,6 @@ class CinemaCinemaCity implements Cinema
|
||||
$document = json_decode($document);
|
||||
|
||||
|
||||
// $cinemaData = [];
|
||||
// $text = "Repertuar Cinema-City\n";
|
||||
// $text .= str_replace('/', '-', $this->day) . "\n\n";
|
||||
$movies = [];
|
||||
|
||||
$date = date('d/m/Y', strtotime($this->day));
|
||||
@@ -55,9 +49,6 @@ class CinemaCinemaCity implements Cinema
|
||||
foreach ($movieData->BD as $projections) {
|
||||
if ($projections->date == $date) {
|
||||
foreach ($projections->P as $projection) {
|
||||
|
||||
// var_dump($projection);
|
||||
// die();
|
||||
$movie['hours'][] = $projection->time;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user