Skip to content
Snippets Groups Projects
Commit f83ef439 authored by Tilman Vatteroth's avatar Tilman Vatteroth :robot:
Browse files

Zeilenendungen geändert

parent 38c7e138
No related branches found
No related tags found
No related merge requests found
<?php
namespace App\Controller\Component;
use Cake\Controller\Component;
use Cake\Filesystem\File;
class ConfigurationComponent extends Component {
private $session = NULL;
private $folder = null;
public function initialize(array $config) {
$this->session = $this->request->session();
}
public function getConfiguration($session_key, $config_name = '', $config_type = 'panel') {
if (!is_string($session_key)
|| !is_string($config_name)
|| !is_string($config_type)
|| empty($session_key)) {
return FALSE;
}
// load data from session or reload data to session?
/* if ($this->session->check($session_key)) {
// return configuration
return $this->session->read($session_key);
} else {*/
// reload configuration
return $this->getReloadedConfiguration($session_key, $config_name, $config_type);
// }
}
public function getReloadedConfiguration($session_key, $config_name = '', $config_type = 'panel') {
if (!is_string($session_key)
|| !is_string($config_name)
|| !is_string($config_type)
|| (strpos($config_type, ".."))
|| empty($config_name)
|| empty($session_key)) {
return FALSE;
}
// get filename for configuration
$file = new File(ROOT.'/config/'.$config_type.'/'.$config_name.'.json');
// can we get our configuration?
if ($file->exists() && $file->readable()
&& !(($file_content = $file->read()) === false)) {
// decode, save and return configuration
$result = json_decode($file_content,true);
$this->session->write($session_key, $result);
return $result;
} else {
// ERROR!
return FALSE;
}
}
}
iuguaesdfgüobuhasdfvgöuohdtafhhklöujager <?php
namespace App\Controller\Component;
use Cake\Controller\Component;
use Cake\Filesystem\File;
class ConfigurationComponent extends Component {
private $session = NULL;
private $folder = null;
public function initialize(array $config) {
$this->session = $this->request->session();
}
public function getConfiguration($session_key, $config_name = '', $config_type = 'panel') {
if (!is_string($session_key)
|| !is_string($config_name)
|| !is_string($config_type)
|| empty($session_key)) {
return FALSE;
}
// load data from session or reload data to session?
/* if ($this->session->check($session_key)) {
// return configuration
return $this->session->read($session_key);
} else {*/
// reload configuration
return $this->getReloadedConfiguration($session_key, $config_name, $config_type);
// }
}
public function getReloadedConfiguration($session_key, $config_name = '', $config_type = 'panel') {
if (!is_string($session_key)
|| !is_string($config_name)
|| !is_string($config_type)
|| (strpos($config_type, ".."))
|| empty($config_name)
|| empty($session_key)) {
return FALSE;
}
// get filename for configuration
$file = new File(ROOT.'/config/'.$config_type.'/'.$config_name.'.json');
// can we get our configuration?
if ($file->exists() && $file->readable()
&& !(($file_content = $file->read()) === false)) {
// decode, save and return configuration
$result = json_decode($file_content,true);
$this->session->write($session_key, $result);
return $result;
} else {
// ERROR!
return FALSE;
}
}
}
<?php
namespace App\Controller\Component;
use Cake\Controller\Component;
class DeparturesComponent extends Component {
const VERSION = "0.1";
const VRRF_VERSION = "0.07";
public function grabData($options) {
$alldata = array();
$rawdata = array();
foreach ($options['stops'] as $n => $stop) {
$stopsplit = explode(":",$stop);
// errors?
if ($stopsplit == $stop)
echo "<div error><h1>NAME ERROR!</h1>$stop<br/>Not a propper stop name. Usage: city:stop[;city:stop]*</div>";
// get departures
$plain = file_get_contents("http://vrrf.finalrewind.org/$stopsplit[0]/$stopsplit[1].json?frontend=json");
$data = json_decode($plain, true);
// version
$alldata["version"] = $this::VERSION;
$alldata["vrrf_version"] = $data['version'];
$alldata["used_vrrf_version"] = $this::VRRF_VERSION;
// api_errors
$alldata["errors"]["$stopsplit[0] - $stopsplit[1]"] = $data['error'];
// data
$rawdata["$stopsplit[0] - $stopsplit[1]"] = $data['raw'];
}
$reftime = date("dHi");
$alldata['lines'] = array();
foreach ($rawdata as $stop => $data) {
// process
foreach ($data as $i => $entry) {
// filter
if (isset($options['filter']['bl'])) {
if (isset($options['filter']['bl']['line']) ) {
if (in_array($entry['line'], $options['filter']['bl']['line'])) {
continue;
}
}
if (isset($options['filter']['bl']['type']) ) {
if (in_array($entry['type'], $options['filter']['bl']['type'])) {
continue;
}
}
if (isset($options['filter']['bl']['platform']) ) {
if (in_array($entry['platform'], $options['filter']['bl']['platform'])) {
continue;
}
}
}
if (isset($options['filter']['wl'])) {
if (isset($options['filter']['wl']['line']) ) {
if (!in_array($entry['line'], $options['filter']['wl']['line'])) {
continue;
}
}
if (isset($options['filter']['wl']['type']) ) {
if (!in_array($entry['type'], $options['filter']['wl']['type'])) {
continue;
}
}
if (isset($options['filter']['wl']['platform']) ) {
if (!in_array($entry['platform'], $options['filter']['wl']['platform'])) {
continue;
}
}
}
// !filter
$scheddate = explode(".",$entry['sched_date']);
$schedtime = explode(":",$entry['sched_time']);
$deptime = $scheddate[0].$schedtime[0].$schedtime[1];
//echo intval($deptime)." + ".intval($entry['delay'])." - ".intval($reftime)." = ".(intval($deptime) + intval($entry['delay']) - intval($reftime))."<br/>";
if (intval($deptime) + intval($entry['delay']) - intval($reftime) > 0) {
$buf = array('date' => $entry['sched_date'], 'time' => $entry['sched_time'], 'delay' => $entry['delay'], 'cancel' => $entry['is_cancelled'], 'name' => $stop, 'info' => $entry['info']);
foreach ($alldata['lines'] as $key => $value) {
if (($entry['key'] == $value['key']) && ($entry['lineref']['identifier'] == $value['identifier']) && ($entry['line'] == $value['line'])) {
$ibuf = sizeof($alldata['lines'][$key]['stops']);
while ($buf != null) {
if ($ibuf < 1 || strcmp($buf['time'], $alldata['lines'][$key]['stops'][$ibuf - 1]['time']) > 0) {
$alldata['lines'][$key]['stops'][$ibuf] = $buf;
$buf = null;
} else {
$alldata['lines'][$key]['stops'][$ibuf] = $alldata['lines'][$key]['stops'][$ibuf - 1];
$ibuf--;
}
}
break;
}
}
if ($buf != null) {
$dbuf = array('line' => $entry['line'], 'destination' => $entry['destination'], 'type' => $entry['type'], 'key' => $entry['key'], 'identifier' => $entry['lineref']['identifier'], 'stops' => array($buf));
$alldata['lines'][] = $dbuf;
}
}
}
}
// sort
usort($alldata['lines'], function($a, $b) {
// atime
$scheddate = explode(".",$a['stops'][0]['date']);
$schedtime = explode(":",$a['stops'][0]['time']);
$atime = $scheddate[2].$scheddate[1].$scheddate[0].$schedtime[0].$schedtime[1];
// btime
$scheddate = explode(".",$b['stops'][0]['date']);
$schedtime = explode(":",$b['stops'][0]['time']);
$btime = $scheddate[2].$scheddate[1].$scheddate[0].$schedtime[0].$schedtime[1];
// compare
return intval($atime) - intval($btime);
});
// clean
$lines_count = count($alldata['lines']);
if ($lines_count > $options['max']) {
$max = min($lines_count, $options['max']);
for ($i = $max; $i < $lines_count; $i++) {
unset($alldata['lines'][$i]);
}
foreach ($alldata['lines'] as $id => $line) {
unset($alldata['lines'][$id]['key']);
unset($alldata['lines'][$id]['identifier']);
}
return $alldata;
}
}
}
\ No newline at end of file
<?php
namespace App\Controller\Component;
use Cake\Controller\Component;
class DeparturesComponent extends Component {
const VERSION = "0.1";
const VRRF_VERSION = "0.07";
public function grabData($options) {
$alldata = array();
$rawdata = array();
foreach ($options['stops'] as $n => $stop) {
$stopsplit = explode(":",$stop);
// errors?
if ($stopsplit == $stop)
echo "<div error><h1>NAME ERROR!</h1>$stop<br/>Not a propper stop name. Usage: city:stop[;city:stop]*</div>";
// get departures
$plain = file_get_contents("http://vrrf.finalrewind.org/$stopsplit[0]/$stopsplit[1].json?frontend=json");
$data = json_decode($plain, true);
// version
$alldata["version"] = $this::VERSION;
$alldata["vrrf_version"] = $data['version'];
$alldata["used_vrrf_version"] = $this::VRRF_VERSION;
// api_errors
$alldata["errors"]["$stopsplit[0] - $stopsplit[1]"] = $data['error'];
// data
$rawdata["$stopsplit[0] - $stopsplit[1]"] = $data['raw'];
}
$reftime = date("dHi");
$alldata['lines'] = array();
foreach ($rawdata as $stop => $data) {
// process
foreach ($data as $i => $entry) {
// filter
if (isset($options['filter']['bl'])) {
if (isset($options['filter']['bl']['line']) ) {
if (in_array($entry['line'], $options['filter']['bl']['line'])) {
continue;
}
}
if (isset($options['filter']['bl']['type']) ) {
if (in_array($entry['type'], $options['filter']['bl']['type'])) {
continue;
}
}
if (isset($options['filter']['bl']['platform']) ) {
if (in_array($entry['platform'], $options['filter']['bl']['platform'])) {
continue;
}
}
}
if (isset($options['filter']['wl'])) {
if (isset($options['filter']['wl']['line']) ) {
if (!in_array($entry['line'], $options['filter']['wl']['line'])) {
continue;
}
}
if (isset($options['filter']['wl']['type']) ) {
if (!in_array($entry['type'], $options['filter']['wl']['type'])) {
continue;
}
}
if (isset($options['filter']['wl']['platform']) ) {
if (!in_array($entry['platform'], $options['filter']['wl']['platform'])) {
continue;
}
}
}
// !filter
$scheddate = explode(".",$entry['sched_date']);
$schedtime = explode(":",$entry['sched_time']);
$deptime = $scheddate[0].$schedtime[0].$schedtime[1];
//echo intval($deptime)." + ".intval($entry['delay'])." - ".intval($reftime)." = ".(intval($deptime) + intval($entry['delay']) - intval($reftime))."<br/>";
if (intval($deptime) + intval($entry['delay']) - intval($reftime) > 0) {
$buf = array('date' => $entry['sched_date'], 'time' => $entry['sched_time'], 'delay' => $entry['delay'], 'cancel' => $entry['is_cancelled'], 'name' => $stop, 'info' => $entry['info']);
foreach ($alldata['lines'] as $key => $value) {
if (($entry['key'] == $value['key']) && ($entry['lineref']['identifier'] == $value['identifier']) && ($entry['line'] == $value['line'])) {
$ibuf = sizeof($alldata['lines'][$key]['stops']);
while ($buf != null) {
if ($ibuf < 1 || strcmp($buf['time'], $alldata['lines'][$key]['stops'][$ibuf - 1]['time']) > 0) {
$alldata['lines'][$key]['stops'][$ibuf] = $buf;
$buf = null;
} else {
$alldata['lines'][$key]['stops'][$ibuf] = $alldata['lines'][$key]['stops'][$ibuf - 1];
$ibuf--;
}
}
break;
}
}
if ($buf != null) {
$dbuf = array('line' => $entry['line'], 'destination' => $entry['destination'], 'type' => $entry['type'], 'key' => $entry['key'], 'identifier' => $entry['lineref']['identifier'], 'stops' => array($buf));
$alldata['lines'][] = $dbuf;
}
}
}
}
// sort
usort($alldata['lines'], function($a, $b) {
// atime
$scheddate = explode(".",$a['stops'][0]['date']);
$schedtime = explode(":",$a['stops'][0]['time']);
$atime = $scheddate[2].$scheddate[1].$scheddate[0].$schedtime[0].$schedtime[1];
// btime
$scheddate = explode(".",$b['stops'][0]['date']);
$schedtime = explode(":",$b['stops'][0]['time']);
$btime = $scheddate[2].$scheddate[1].$scheddate[0].$schedtime[0].$schedtime[1];
// compare
return intval($atime) - intval($btime);
});
// clean
$lines_count = count($alldata['lines']);
if ($lines_count > $options['max']) {
$max = min($lines_count, $options['max']);
for ($i = $max; $i < $lines_count; $i++) {
unset($alldata['lines'][$i]);
}
foreach ($alldata['lines'] as $id => $line) {
unset($alldata['lines'][$id]['key']);
unset($alldata['lines'][$id]['identifier']);
}
return $alldata;
}
}
}
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment