prepare intranet for first Dokploy deployment
This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
/*
|
||||
Name: connector_feiertage.php
|
||||
Beschreibung: Ermittlung von Feiertagen
|
||||
*/
|
||||
|
||||
class lib_Feiertage_Connector
|
||||
{
|
||||
const BASE_URL = 'https://feiertage-api.de/api/';
|
||||
const HOLIDAY_URL = 'https://ferien-api.de/api/v1/holidays/';
|
||||
|
||||
private static $cache = array();
|
||||
private static $itsInstance = null;
|
||||
|
||||
private function __construct(){}
|
||||
|
||||
public static function getInstance()
|
||||
{
|
||||
if(self::$itsInstance == null)
|
||||
self::$itsInstance = new lib_Feiertage_Connector();
|
||||
|
||||
return self::$itsInstance;
|
||||
}
|
||||
|
||||
public function get_feiertagsname($datum)
|
||||
{
|
||||
$feiertagsname = null;
|
||||
$jahr = date('Y',strtotime($datum));
|
||||
$array = $this->get_FeiertageDesJahres($jahr);
|
||||
|
||||
$filter = array_filter($array, function ($wert) use ($datum) {
|
||||
|
||||
return $wert === $datum;
|
||||
});
|
||||
|
||||
if ($filter !== null) {
|
||||
|
||||
$feiertagsname = implode(" ",array_keys($filter));
|
||||
}
|
||||
|
||||
return $feiertagsname;
|
||||
}
|
||||
|
||||
public function get_FeiertageDesJahres($jahr) //Lade Feiertage aus Datei (Alle Bundesländer)
|
||||
{
|
||||
if(isset(self::$cache['c0-'.$jahr]))
|
||||
return self::$cache['c0-'.$jahr];
|
||||
|
||||
$file = "data/feiertage_$jahr.json";
|
||||
|
||||
if (!file_exists($file)) { //Ggf. Datei von externer API speichern
|
||||
|
||||
$extResult = $this->_file_get_contents_t_curl(lib_Feiertage_Connector::BASE_URL.'?jahr='.$jahr.'&nur_daten=1');
|
||||
file_put_contents($file, $extResult);
|
||||
}
|
||||
|
||||
self::$cache['c0-'.$jahr] = json_decode(file_get_contents($file), true);
|
||||
return self::$cache['c0-'.$jahr];
|
||||
}
|
||||
|
||||
public function getFeiertageVonLand($jahr,$land)
|
||||
{
|
||||
if(isset(self::$cache['c0-'.$jahr.$land]))
|
||||
return self::$cache['c0-'.$jahr.$land];
|
||||
|
||||
$file = "data/feiertage_" . $jahr . "_" . $land . ".json";
|
||||
|
||||
if (!file_exists($file)) { //Ggf. Datei von externer API speichern
|
||||
|
||||
$extResult = $this->_file_get_contents_t_curl(lib_Feiertage_Connector::BASE_URL.'?jahr='.$jahr.'&nur_land='.$land);
|
||||
$array = json_decode($extResult, true);
|
||||
//Feste Feiertage hinzufügen
|
||||
$array = array_merge($array, ["Heiligabend" => ["datum" => "$jahr-12-24","hinweis" => ""]]);
|
||||
$array = array_merge($array, ["Silvester" => ["datum" => "$jahr-12-31","hinweis" => ""]]);
|
||||
|
||||
$array_json = json_encode($array);
|
||||
file_put_contents($file, $array_json);
|
||||
//file_put_contents($file, $extResult);
|
||||
}
|
||||
|
||||
self::$cache['c0-'.$jahr.$land] = json_decode(file_get_contents($file), true);
|
||||
return self::$cache['c0-'.$jahr.$land];
|
||||
}
|
||||
|
||||
public function isFeiertagInBerlin($datum)
|
||||
{
|
||||
$feiertage_land = $this->getFeiertageVonLand(date('Y',strtotime($datum)),'BE');
|
||||
|
||||
foreach($feiertage_land as $feiertagsname => $feiertagsdatum)
|
||||
if($feiertagsdatum['datum'] == date('Y-m-d',strtotime($datum)))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function get_BerlinerFerientageDesJahres($jahr) //Lade Ferientage aus Datei
|
||||
{
|
||||
if(isset(self::$cache['c1-'.$jahr]))
|
||||
return self::$cache['c1-'.$jahr];
|
||||
|
||||
$file = "data/ferientage_berlin_$jahr.json";
|
||||
|
||||
if (!file_exists($file)) { //Ggf. Datei von externer API speichern
|
||||
|
||||
$result = $this->_file_get_contents_t_curl(lib_Feiertage_Connector::HOLIDAY_URL.'BE/'.$jahr);
|
||||
file_put_contents($file, $result);
|
||||
}
|
||||
|
||||
self::$cache['c1-'.$jahr] = json_decode(file_get_contents($file), true);
|
||||
return self::$cache['c1-'.$jahr];
|
||||
}
|
||||
|
||||
private function _file_get_contents_t_curl($url) {
|
||||
|
||||
$ctx = stream_context_create(['http' => ['timeout' => 5]]);
|
||||
$file = @file_get_contents($url, false, $ctx);
|
||||
if(!empty($file))
|
||||
return $file;
|
||||
else
|
||||
{
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
|
||||
$data = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
if(empty($data))
|
||||
throw new Exception('Verbindung zu feiertage-api.de war nicht moeglich.');
|
||||
else
|
||||
return $data;
|
||||
}
|
||||
|
||||
throw new Exception('Verbindung zu feiertage-api.de war nicht moeglich.');
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/*
|
||||
Name: connector_kalendertage.php
|
||||
Beschreibung: Ermittlung von Kalendertagen
|
||||
|
||||
*/
|
||||
|
||||
class lib_Kalendertage_Connector
|
||||
{
|
||||
private static $cache = array();
|
||||
private static $itsInstance = null;
|
||||
|
||||
private function __construct(){}
|
||||
|
||||
public static function getInstance()
|
||||
{
|
||||
if(self::$itsInstance == null)
|
||||
self::$itsInstance = new lib_Kalendertage_Connector();
|
||||
|
||||
return self::$itsInstance;
|
||||
}
|
||||
|
||||
public function get_KalenderMonatsname($datum) // Deutsche Monatsnamen
|
||||
{
|
||||
$monate = array(1 => "Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember");
|
||||
|
||||
$timestamp = strtotime($datum);
|
||||
$monatIndex = date("n", $timestamp);
|
||||
return $monate[$monatIndex];
|
||||
}
|
||||
|
||||
public function get_KalenderWochentag($datum) // Deutsche Wochentage
|
||||
{
|
||||
$wochentage = array("Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag");
|
||||
|
||||
$timestamp = strtotime($datum);
|
||||
$wochentagIndex = date("w", $timestamp);
|
||||
return $wochentage[$wochentagIndex];
|
||||
}
|
||||
|
||||
public function get_KalenderStart($datum) //-> Montag der Woche, der den ersten Kalendertag enthält
|
||||
{
|
||||
$t_datum = strtotime($datum);
|
||||
|
||||
$t_firstMonday_Of_thisMonth = strtotime("first monday of this month", $t_datum);
|
||||
$t_lastMonday_Of_lastMonth = strtotime("last monday of last month", $t_datum);
|
||||
|
||||
if ((int)date("d", $t_firstMonday_Of_thisMonth) === 1) {
|
||||
|
||||
return date("Y-m-d", $t_firstMonday_Of_thisMonth);
|
||||
} else {
|
||||
|
||||
return date('Y-m-d', $t_lastMonday_Of_lastMonth);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user