issue #1 reset form resets selected icon to empty

This commit is contained in:
kplaczek
2018-04-04 19:44:11 +02:00
commit bcc445f75a
196 changed files with 49208 additions and 0 deletions

78
app/Paper/Airly.php Normal file
View File

@@ -0,0 +1,78 @@
<?php
namespace App\Paper;
class Airly
{
private $apiKey = '8b6d77b2950e4e018b0684912bf7b9ed';
private $stations = ['2210', '2256', '2180'];
private $airlyApi = 'https://airapi.airly.eu/v1';
public function getStations()
{
return $this->stations;
}
function getStationInfo($stationId)
{
return json_decode(file_get_contents(sprintf('%s/sensors/%d?apikey=%s', $this->airlyApi, $stationId, $this->apiKey)), 1);
}
function getStationMeasurements($stationId)
{
return json_decode(file_get_contents(sprintf('%s/sensor/measurements?sensorId=%d&apikey=%s', $this->airlyApi, $stationId, $this->apiKey)), 1);
}
public function getPollutionLevelToText($pollutionLevel)
{
return ["Wspaniałe powietrze! Idealny dzień na aktywność na świeżym powietrzu",
"Dobre powietrze. Możesz bez obaw wyjść na zewnątrz i cieszyć się dniem",
"Bywało lepiej… To nie jest najlepszy dzień na aktywność poza domem",
"Zła jakość powietrza! Lepiej zostań dzisiaj w domu",
"Zła jakość powietrza! Lepiej zostań dzisiaj w domu",
"Bardzo zła jakość powietrza! Zostań dziś w domu"][$pollutionLevel - 1];
}
public function getInformationText($stationId)
{
$stationMeasurements = $this->getStationMeasurements($stationId);
if ($stationMeasurements['currentMeasurements'] === []) {
$dataText = 'Brak aktualnych danych ze stacji';
} else {
$dataText = "Aktualne warunki:" . PHP_EOL;
if (isset($stationMeasurements['currentMeasurements']['temperature'])) {
$dataText .= "Temperatura: " . round((int)$stationMeasurements['currentMeasurements']['temperature'], 0) . "°C" . PHP_EOL;
}
if (isset($stationMeasurements['currentMeasurements']['pressure'])) {
$dataText .= "Ciśnienie: " . round(((float)$stationMeasurements['currentMeasurements']['pressure'] / 100), 2) . "hPa" . PHP_EOL;
}
if (isset($stationMeasurements['currentMeasurements']['humidity'])) {
$dataText .= "Wilgotność: " . round((int)$stationMeasurements['currentMeasurements']['humidity'], 2) . "%" . PHP_EOL . PHP_EOL;
}
if (isset($stationMeasurements['currentMeasurements']['pm1'])) {
$dataText .= "PMI 1: " . (int)$stationMeasurements['currentMeasurements']['pm1'] . "ppm" . PHP_EOL;
}
if (isset($stationMeasurements['currentMeasurements']['pm25'])) {
$dataText .= "PMI 2.5: " . (int)$stationMeasurements['currentMeasurements']['pm25'] . "ppm / " . round((int)$stationMeasurements['currentMeasurements']['pm25'] / 0.25, 0) . '%' . PHP_EOL;
}
if (isset($stationMeasurements['currentMeasurements']['pm10'])) {
$dataText .= "PMI 10: " . (int)$stationMeasurements['currentMeasurements']['pm10'] . "ppm / " . round((int)$stationMeasurements['currentMeasurements']['pm10'] / 0.50, 0) . '%' . PHP_EOL;
}
if (isset($stationMeasurements['currentMeasurements']['airQualityIndex'])) {
$dataText .= "Ogólna jakość powietrza: " . (int)$stationMeasurements['currentMeasurements']['airQualityIndex'] . '/100' . PHP_EOL;
}
if (isset($stationMeasurements['currentMeasurements']['pollutionLevel'])) {
$dataText .= "Stopień zanieczyszczeń: " . (int)$stationMeasurements['currentMeasurements']['pollutionLevel'] . '/6' . PHP_EOL;
$dataText .= $this->getPollutionLevelToText((int)$stationMeasurements['currentMeasurements']['pollutionLevel']);
}
}
return $dataText;
}
}

View File

@@ -0,0 +1,80 @@
<?php
namespace App\Paper;
use App\Paper\Interfaces\Cinema;
class CinemaMultikino implements Cinema
{
function fetchRepertorire($day, $cinemaId = null)
{
$moviePath = 'https://multikino.pl/data/filmswithshowings/' . $cinemaId;
$movieContent = file_get_contents($moviePath);
print_r($movieContent);
$movieJson = json_decode($movieContent, 0);
return $movieJson;
}
function parseRepertoire($day, $cinemaId = null)
{
$movieJson = $this->fetchRepertorire($day, $cinemaId);
echo $day;
// print_r($movieJson);
$filmy = [];
foreach ($movieJson->films as $movie) {
$film = [];
$film['id'] = $movie->id;
$film['title'] = $movie->title;
$film['times'] = [];
$film['date'] = $day;
$film['runningtime'] = $movie->info_runningtime;
$film['genres'] = [];
$film['synopsis_short'] = str_replace(["\r\n", " "], [" "], $movie->synopsis_short);
if ($movie->original_s_count > 0 && $movie->show_showings) {
foreach ($movie->showings as $shoving) {
if ($shoving->date_time == $day) {
foreach ($shoving->times as $time) {
$film['times'][] = $time->time . " " . $time->screen_type;
}
}
}
}
foreach ($movie->genres->names as $genre) {
$film['genres'][] = $genre->name;
}
if (count($film['times'])) {
$filmy[] = $film;
}
}
// print_r($filmy);
die();
return $filmy;
}
function convertToPrint($day, $cinemaId = null)
{
$filmy = $this->parseRepertoire($day, $cinemaId);
$text = '';
$text .= "Repertuar Multikino Gdańsk\n";
$text .= $day . "\n\n";
foreach ($filmy as $movie) {
$text .= $movie['title']. "\n";
$text .= '('.$movie['runningtime']. ")\n";
$text .= implode(', ', $movie['genres']) . "\n\n";
$text .= $movie['synopsis_short'] . "\n\n";
$text .= implode(', ', $movie['times']) . "\n";
$text .= "--------------------------------\n\n";
}
return $text;
}
}

21
app/Paper/HtmlToPos.php Normal file
View File

@@ -0,0 +1,21 @@
<?php
namespace App\Paper;
class HtmlToPos
{
private function handleNewLine($text)
{
return str_replace(['<br>', '<br/>', '<br />'], "\n", $text);
}
public function convert($html = '')
{
$posText = $this->handleNewLine($html);
return $posText;
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace App\Paper\Interfaces;
/**
* Created by PhpStorm.
* User: k
* Date: 28.05.2017
* Time: 20:14
*/
interface Cinema
{
function fetchRepertorire($day, $cinemaId = null);
function parseRepertoire($day, $cinemaId = null);
function convertToPrint($day, $cinemaId = null);
}

104
app/Paper/Paper.php Normal file
View File

@@ -0,0 +1,104 @@
<?php
namespace App\Paper;
use Illuminate\Support\Facades\DB;
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
use Mike42\Escpos\Printer;
use Mike42\Escpos\EscposImage;
use Mockery\Exception;
class Paper
{
private $imageDirectory = 'large/';
private $imageDirectorySmall = 'small/';
private $printer;
private $connector;
public function __construct()
{
try {
$this->connector = new FilePrintConnector("/dev/usb/lp0");
$this->printer = new Printer($this->connector);
} catch (Exception $e) {
die($e->getMessage());
}
}
public function sendHeaderPrint($title)
{
if (strlen($title)) {
$this->printer->setDoubleStrike(true);
$this->printer->setJustification(Printer::JUSTIFY_CENTER);
$this->printer->setEmphasis(true);
$this->printer->text($title . "\n\n");
$this->printer->setEmphasis(false);
$this->printer->setJustification(Printer::JUSTIFY_LEFT);
$this->printer->setDoubleStrike(false);
}
}
public function sendImagePrint($image, $imageLocal = true)
{
if ($image) {
if ($imageLocal) {
$img = EscposImage::load($this->imageDirectory . basename($image) . '.png');
} else { //image not local so then remote image
$extension = strtolower(pathinfo($image, PATHINFO_EXTENSION));
$tmpFile = storage_path() . '/image_packt.' . $extension;
file_put_contents($tmpFile, file_get_contents($image));
$img = EscposImage::load($tmpFile);
}
$this->printer->setJustification(Printer::JUSTIFY_CENTER);
$this->printer->bitImageColumnFormat($img);
$this->printer->feed(2);
$this->printer->setJustification(Printer::JUSTIFY_LEFT);
}
}
public function sendPrint($title, $text = '', $image = false, $imageLocal = true)
{
$this->sendImagePrint($image, $imageLocal);
$this->sendHeaderPrint($title);
$htmlToPos = new HtmlToPos();
$this->printer->text($htmlToPos->convert($text));
$this->printer->feed(4);
}
/**
*
* pobieranie ikon z bazy w kolejności ilości użyć, ikon z dysku a następnie
* usunięcie pozdbioru ikon z bazy ze wszystkich ikon a następnie dodanie
* ich na początek listy ikon
*
* @return array
*/
public function getIcons()
{
// $icons = array_diff(scandir($this->imageDirectorySmall), ['.', '..']);
$icons = ["address-card-o", "anchor", "archive-3", "at", "balance-scale", "ban", "bar-chart-o", "barcode", "battery-empty", "battery-full", "battery-half", "battery-quarter", "battery-three-quarters", "bed", "beer", "bell-o", "bell-slash-o", "bicycle", "birthday-cake", "bolt", "bomb", "book", "bug", "building-o", "bullhorn", "bus", "camera", "car", "chain", "chat-2", "check", "cloud", "code", "coffee", "cog", "cutlery", "dashboard", "database", "diamond", "dollar", "dribbble", "envelope-o", "envira", "exclamation-triangle", "female", "file-text-o", "film", "fingerprint", "fire-extinguisher", "fire", "flag-o", "flask", "floppy-o", "folder-o", "folder-open-o", "frown-o", "gamepad", "gift", "git", "glass", "graduation-cap", "grav", "group", "hand-o-left", "heart-o", "home", "lemon-o", "lightbulb-o", "list-alt", "location-arrow", "lock", "male", "map-1", "map-marker", "microchip", "money", "moon-o", "music", "paper-plane", "paperclip", "paw", "pencil", "phone", "pie-chart", "piggy-bank", "plane", "question-circle-o", "rocket", "search", "ship", "shopping-cart", "smile-o", "snowflake-o", "steam", "subway", "success", "support", "thermometer-2", "thumbs-o-down", "thumbs-o-up", "ticket", "times", "trash-o", "tree", "trophy", "truck", "umbrella", "usd", "warning", "wifi", "wpexplorer", "wrench", "youtube-play"];
$iconsDatabase = [];
$iconsDb = DB::select('SELECT icon FROM note WHERE icon is not null group by icon ORDER BY count(icon) DESC ');
foreach ($iconsDb as $icon) {
$iconsDatabase[] = pathinfo(basename($icon->icon), PATHINFO_FILENAME);
}
return (array_merge($iconsDatabase, array_diff($icons, $iconsDatabase)));
}
public function __destruct()
{
$this->printer->close();
}
}