first commit
This commit is contained in:
196
app/Core/Helper/LanguageService.php
Normal file
196
app/Core/Helper/LanguageService.php
Normal file
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
|
||||
namespace App\Core\Helper;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class LanguageService
|
||||
{
|
||||
private static $currentLanguage = null;
|
||||
private static $languageSupportList = null;
|
||||
private static $languageSupportCacheName = "langSupportCache";
|
||||
|
||||
public static function getDefaultLang()
|
||||
{
|
||||
return config("languageSupport.defaultLanguage");
|
||||
}
|
||||
|
||||
public static function getCurrentLang ( )
|
||||
{
|
||||
$language = self::$currentLanguage;
|
||||
$language = $language ? $language : self::getDefaultLang();
|
||||
return $language;
|
||||
}
|
||||
|
||||
public static function isValidLanguage ( $language )
|
||||
{
|
||||
$validLanguages = self::getValidLanguages();
|
||||
return in_array($language,$validLanguages);
|
||||
}
|
||||
|
||||
public static function getCurrentLangPack($language = null)
|
||||
{
|
||||
$language = $language ? $language : self::getCurrentLang();
|
||||
return config("language-pack-".$language);
|
||||
}
|
||||
|
||||
|
||||
public static function setCurrentLanguage($language)
|
||||
{
|
||||
$language = strtolower($language);
|
||||
self::$currentLanguage = self::isValidLanguage($language) ? $language : config("languageSupport.defaultLanguage");
|
||||
return self::$currentLanguage;
|
||||
}
|
||||
|
||||
public static function getValidLanguages ( $except = null )
|
||||
{
|
||||
return collect(config("languageSupport.availableLanguages"))->flip()->except($except)->flip()->toArray();
|
||||
}
|
||||
|
||||
public static function getAllLangPackages()
|
||||
{
|
||||
$langPackages = [];
|
||||
$validSystemLanguages = self::getValidLanguages();
|
||||
foreach ($validSystemLanguages as $perLanguage)
|
||||
{
|
||||
$langPackages[$perLanguage] = self::getCurrentLangPack($perLanguage);
|
||||
}
|
||||
return $langPackages;
|
||||
}
|
||||
|
||||
public static function convertAllLanguageSettingsAndCache()
|
||||
{
|
||||
$cacheParam = [];
|
||||
$wordIndexCounter = 0;
|
||||
$allLangPackages = self::getAllLangPackages();
|
||||
$systemDefaultLang = self::getDefaultLang();
|
||||
|
||||
foreach ($allLangPackages[$systemDefaultLang] as $perLangKey => $perLangWord)
|
||||
{
|
||||
$cacheParam[$wordIndexCounter]["md5"] = self::convertToMd5ForMultiLanguage($perLangWord);
|
||||
|
||||
foreach ($allLangPackages as $perLangPackKey => $perLangPack)
|
||||
{
|
||||
$cacheParam[$wordIndexCounter][$perLangPackKey] = $perLangPack[$wordIndexCounter];
|
||||
}
|
||||
$wordIndexCounter++;
|
||||
}
|
||||
|
||||
$cacheParam = collect($cacheParam)->keyBy("md5")->toArray();
|
||||
Cache::put(self::$languageSupportCacheName,$cacheParam,120);
|
||||
return $cacheParam;
|
||||
}
|
||||
|
||||
public static function getLanguageSupportList()
|
||||
{
|
||||
$cachedData = self::$languageSupportList;
|
||||
if ( !$cachedData)
|
||||
{
|
||||
$cachedData = Cache::get(self::$languageSupportCacheName);
|
||||
self::$languageSupportList = $cachedData;
|
||||
}
|
||||
$cachedData = $cachedData ? $cachedData : self::convertAllLanguageSettingsAndCache();
|
||||
return $cachedData;
|
||||
}
|
||||
|
||||
|
||||
private static function makeSlugForMultiLanguage( $word )
|
||||
{
|
||||
$word = lowerCase($word);
|
||||
preg_match_all("#[\pL\d+]+#iu",$word,$results);
|
||||
$results = $results[0];
|
||||
$converted = implode("",$results);
|
||||
return $converted;
|
||||
}
|
||||
|
||||
public static function convertToMd5ForMultiLanguage($word)
|
||||
{
|
||||
/*Clear The Parameters*/
|
||||
$word = preg_replace('/\{\#\d+\}/',"",$word);
|
||||
/**/
|
||||
/*Clear From Html*/
|
||||
$word = strip_tags($word);
|
||||
/**/
|
||||
$word = self::makeSlugForMultiLanguage($word);
|
||||
return md5($word);
|
||||
}
|
||||
|
||||
|
||||
public static function findWordForLanguage($word,$lang,array $parameters = [])
|
||||
{
|
||||
$md5Key = self::convertToMd5ForMultiLanguage($word);
|
||||
$langSupportList = self::getLanguageSupportList();
|
||||
$converted = fillOnUndefined($langSupportList,$md5Key.".".$lang);
|
||||
$converted = $converted ? $converted : fillOnUndefined($langSupportList,$md5Key.".".self::getDefaultLang());
|
||||
$converted = $converted ? $converted : $word;
|
||||
|
||||
/*Inject Parameters*/
|
||||
$parameters = reIndexArrayKeys($parameters,1);
|
||||
foreach ($parameters as $perParameterKey => $perParameter)
|
||||
{
|
||||
$converted = preg_replace('/\{\#'.$perParameterKey.'\}/',$perParameter,$converted);
|
||||
}
|
||||
/**/
|
||||
|
||||
return $converted;
|
||||
}
|
||||
|
||||
public static function lang ( $word,array $parameters = [],$lang = null )
|
||||
{
|
||||
$lang = $lang ? : self::$currentLanguage;
|
||||
return self::findWordForLanguage($word,$lang,$parameters);
|
||||
}
|
||||
|
||||
public static function langArrayStack ( array $langParamStack )
|
||||
{
|
||||
$result = [];
|
||||
$validCases = ["lower","title","upper"];
|
||||
|
||||
foreach ($langParamStack as $perLangParam)
|
||||
{
|
||||
$word = castToString(fillOnUndefined($perLangParam,"word"));
|
||||
$parameters = fillOnUndefined($perLangParam,"parameters",[]);
|
||||
$lang = castToString(fillOnUndefined($perLangParam,"lang"));
|
||||
$case = lowerCase(castToString(fillOnUndefined($perLangParam,"case")));
|
||||
$case = in_array($case,$validCases) ? $case : null;
|
||||
$caseFunction = $case ? camel_case("lang".$case."case") : "lang";
|
||||
$result[] = self::$caseFunction($word,$parameters,$lang);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function langArray ( array $words, $lang = null )
|
||||
{
|
||||
$result = [];
|
||||
foreach ($words as $perWord)
|
||||
{
|
||||
$result[] = self::lang($perWord, [], $lang);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function langLowerCase($word,array $parameters = [],$lang = null)
|
||||
{
|
||||
$lang = $lang ? : self::getCurrentLang();
|
||||
$translated = self::lang($word, $parameters,$lang);
|
||||
return $lang == "tr" ? lowerCase($translated) : mb_strtolower($translated);
|
||||
}
|
||||
|
||||
public static function langTitleCase($word,array $parameters = [],$lang = null)
|
||||
{
|
||||
$lang = $lang ? : self::getCurrentLang();
|
||||
$translated = self::lang($word, $parameters,$lang);
|
||||
return $lang == "tr" ? uCase($translated) : mb_convert_case($translated,MB_CASE_TITLE);
|
||||
}
|
||||
|
||||
public static function langUpperCase($word,array $parameters = [],$lang = null)
|
||||
{
|
||||
$lang = $lang ? : self::getCurrentLang();
|
||||
$translated = self::lang($word, $parameters,$lang);
|
||||
return $lang == "tr" ? upperCase($translated) : mb_strtoupper($translated);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
570
app/Core/Helper/PhpHelper.php
Normal file
570
app/Core/Helper/PhpHelper.php
Normal file
@@ -0,0 +1,570 @@
|
||||
<?php
|
||||
|
||||
namespace App\Core\Helper;
|
||||
|
||||
use DateTime;
|
||||
use Illuminate\Support\Facades\App;
|
||||
|
||||
|
||||
class PhpHelper {
|
||||
|
||||
private static $days = [
|
||||
'Pazartesi',
|
||||
'Salı',
|
||||
'Çarşamba',
|
||||
'Perşembe',
|
||||
'Cuma',
|
||||
'Cumartesi',
|
||||
'Pazar',
|
||||
];
|
||||
private static $months = [
|
||||
'Ocak',
|
||||
'Şubat',
|
||||
'Mart',
|
||||
'Nisan',
|
||||
'Mayıs',
|
||||
'Haziran',
|
||||
'Temmuz',
|
||||
'Ağustos',
|
||||
'Eylül',
|
||||
'Ekim',
|
||||
'Kasım',
|
||||
'Aralık',
|
||||
];
|
||||
private static $encryptionKey = 'd0a7e7997b6d5fcd55f4b5c32611b87cd923e88837b63bf2941ef819dc8ca282';
|
||||
|
||||
public static function json_decode($input) {
|
||||
return json_decode($input);
|
||||
}
|
||||
|
||||
public static function json_encode($input) {
|
||||
return json_encode($input);
|
||||
}
|
||||
|
||||
public static function pre($input) {
|
||||
echo '<pre>';
|
||||
print_r($input);
|
||||
echo '</pre>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the difference between two dates
|
||||
* (30 years, 9 months, 25 days, 21 hours, 33 minutes, 3 seconds).
|
||||
*
|
||||
* @param string $start starting date
|
||||
* @param string $end=false ending date
|
||||
*
|
||||
* @return string formatted date difference
|
||||
*/
|
||||
public static function dateDiff($start, $end = false) {$return = [];
|
||||
|
||||
try {
|
||||
$start = new DateTime($start);
|
||||
$end = new DateTime($end);
|
||||
$form = $start->diff($end);
|
||||
} catch (Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
$display = ['y' => 'Yıl', 'm' => 'Ay', 'd' => 'Gün', 'h' => 'Saat', 'i' => 'Dakika', 's' => 'Saniye'];
|
||||
|
||||
foreach ($display as $key => $value) {
|
||||
if ($form->$key > 0) {
|
||||
$return[] = $form->$key . ' ' . $value;
|
||||
}
|
||||
}
|
||||
|
||||
return implode($return, ', ');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the day count between two dates
|
||||
* (3 days).
|
||||
*
|
||||
* @param string $start starting date
|
||||
* @param string $end=false ending date
|
||||
*
|
||||
* @return string day count
|
||||
*/
|
||||
public static function dayCount($end, $start) {
|
||||
$return = [];
|
||||
|
||||
try {
|
||||
$start = new DateTime($start);
|
||||
$end = new DateTime($end);
|
||||
$form = $start->diff($end);
|
||||
} catch (Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
return $form->days;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the day and month name
|
||||
* (16 July).
|
||||
*
|
||||
* @param string $date date
|
||||
*
|
||||
* @return string formatted date
|
||||
*/
|
||||
public static function dayNumberAndMonthWord($date) {
|
||||
return date('d', strtotime($date)) . ' ' . self::$months[date('m', strtotime($date)) - 1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the month name
|
||||
* (July).
|
||||
*
|
||||
* @param string $date date
|
||||
*
|
||||
* @return string formatted date
|
||||
*/
|
||||
public static function monthName($date) {
|
||||
return self::$months[date('m', strtotime($date)) - 1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the day name
|
||||
* (Sunday).
|
||||
*
|
||||
* @param string $date date
|
||||
*
|
||||
* @return string formatted date
|
||||
*/
|
||||
public static function dayName($date) {
|
||||
return self::$days[date('N', strtotime($date)) - 1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the day number
|
||||
* 01.
|
||||
*
|
||||
* @param string $date date
|
||||
*
|
||||
* @return string formatted date
|
||||
*/
|
||||
public static function dayNumber($date) {
|
||||
return date('d', strtotime($date));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the human readable day
|
||||
* 01.
|
||||
*
|
||||
* @param string $date date
|
||||
*
|
||||
* @return string formatted date
|
||||
*/
|
||||
public static function humanReadableDateWithDay($date) {
|
||||
return date('d', strtotime($date)) . ' ' . self::$months[date('m', strtotime($date)) - 1] . ' ' . date('Y', strtotime($date)) . ', ' . self::dayName($date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the human readable day
|
||||
* 01.
|
||||
*
|
||||
* @param string $date date
|
||||
*
|
||||
* @return string formatted date
|
||||
*/
|
||||
public static function humanReadableDate($date) {
|
||||
return date('d-m-Y H:i:s', strtotime($date));
|
||||
}
|
||||
|
||||
public static function humanReadableDateWithoutClock($date) {
|
||||
return date('d-m-Y', strtotime($date));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $date date
|
||||
*
|
||||
* @return string formatted date
|
||||
*/
|
||||
public static function sqlDate($date) {
|
||||
$date = date('Y-m-d', strtotime($date));
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
public static function getMonth() {
|
||||
return self::$months;
|
||||
}
|
||||
|
||||
public static function isValidDate($date) {
|
||||
if (!is_string($date)) {
|
||||
return false;
|
||||
}
|
||||
$day = substr($date, 0, 2);
|
||||
$mont = substr($date, 3, 2);
|
||||
$year = substr($date, 6, 4);
|
||||
return checkdate($mont, $day, $year);
|
||||
}
|
||||
|
||||
public static function fillNullIfEmpty(&$variable) {
|
||||
if (!isset($variable)) {
|
||||
$variable = null;
|
||||
}
|
||||
return $variable;
|
||||
}
|
||||
|
||||
public static function getWeekDays() {
|
||||
$days = self::$days;
|
||||
$result = array();
|
||||
$counter = 1;
|
||||
foreach ($days as $x) {
|
||||
$result[$counter] = $x;
|
||||
$counter++;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function parseXmlToArray($xmlSource) {
|
||||
try {
|
||||
$xmlOut = simplexml_load_string($xmlSource, 'SimpleXMLElement', LIBXML_NOCDATA);
|
||||
|
||||
$arrayOut = json_decode(json_encode($xmlOut), true);
|
||||
} catch (\Exception $e) {
|
||||
$arrayOut = false;
|
||||
}
|
||||
return $arrayOut;
|
||||
}
|
||||
|
||||
public static function encryptCodeNumber($string, $key) {
|
||||
$key = is_null($key) ? self::$encryptionKey : $key;
|
||||
|
||||
$result = '';
|
||||
for ($i = 0; $i < mb_strlen($string, "UTF-8"); $i++) {
|
||||
$char = mb_substr($string, $i, 1, "UTF-8");
|
||||
$keychar = mb_substr($key, ($i % mb_strlen($key, "UTF-8")) - 1, 1, "UTF-8");
|
||||
$char = chr(ord($char) + ord($keychar));
|
||||
$result.=$char;
|
||||
}
|
||||
$result = base64_encode($result);
|
||||
$result = str_replace("=", "", $result);
|
||||
return urlencode($result);
|
||||
}
|
||||
|
||||
public static function decryptCodeNumber($string, $key) {
|
||||
$key = is_null($key) ? self::$encryptionKey : $key;
|
||||
|
||||
$string = urldecode($string);
|
||||
$eqcount = strlen($string) % 4;
|
||||
if ($eqcount == 2)
|
||||
$string . "==";
|
||||
else if ($eqcount == 3)
|
||||
$string . "=";
|
||||
$result = '';
|
||||
$string = base64_decode($string);
|
||||
for ($i = 0; $i < mb_strlen($string); $i++) {
|
||||
$char = mb_substr($string, $i, 1);
|
||||
$keychar = mb_substr($key, ($i % mb_strlen($key)) - 1, 1);
|
||||
$char = chr(ord($char) - ord($keychar));
|
||||
$result.=$char;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function generateRandomString($length = 5) {
|
||||
$characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
$charactersLength = strlen($characters);
|
||||
$randomString = '';
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
||||
}
|
||||
return $randomString;
|
||||
}
|
||||
|
||||
|
||||
public static function convertArrayToCsv (array $valueArray )
|
||||
{
|
||||
if ( !$valueArray )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
$csvResult = "";
|
||||
|
||||
$valueArray = singleElementArray($valueArray);
|
||||
|
||||
/*Get The Column Names*/
|
||||
$firstArray = reset($valueArray);
|
||||
|
||||
$csvResult.=implode(",",array_keys($firstArray))."\r\n";
|
||||
|
||||
foreach ($valueArray as $perArray)
|
||||
{
|
||||
$csvResult.=implode(",",$perArray)."\r\n";
|
||||
}
|
||||
return $csvResult;
|
||||
}
|
||||
|
||||
private static function nextExcelColName ( $colName = null )
|
||||
{
|
||||
$primary = range("A","Z");
|
||||
if ( !$colName)
|
||||
{
|
||||
return reset($primary);
|
||||
}
|
||||
|
||||
if(last($primary) == $colName)
|
||||
{
|
||||
return reset($primary);
|
||||
}
|
||||
|
||||
return $primary[array_search($colName,$primary)+1];
|
||||
|
||||
}
|
||||
|
||||
/* If $params[keyNames] is Empty Function Gonna Take All The Keys Of The Array */
|
||||
public static function convertArrayToXls (array $valueArray,array $params = [] )
|
||||
{
|
||||
try
|
||||
{
|
||||
$excel = App::make('excel');
|
||||
$params[ "fileName" ] = isset( $params[ "fileName" ] ) ? $params[ "fileName" ] : "xls_file";
|
||||
$params[ "pagePrefix" ] = isset( $params[ "pagePrefix" ] ) ? $params[ "pagePrefix" ] : "Page";
|
||||
$params[ "onlyTheseKeys" ] = isset( $params[ "onlyTheseKeys" ] ) ? $params[ "onlyTheseKeys" ] : [];
|
||||
$params[ "keyNames" ] = isset( $params[ "keyNames" ] ) ? $params[ "keyNames" ] : [];
|
||||
$result = $excel->create ( $params[ "fileName" ], function ( $excel ) use ( $valueArray, $params )
|
||||
{
|
||||
$excel->sheet ( $params[ "pagePrefix" ], function ( $sheet ) use ( $valueArray, $params)
|
||||
{
|
||||
$rowCounter = 1;
|
||||
$sheet->setOrientation ( 'landscape' );
|
||||
if ($params["keyNames"])
|
||||
{
|
||||
$colCounter = 0;
|
||||
|
||||
foreach ($params["keyNames"] as $perKey)
|
||||
{
|
||||
if ($params["onlyTheseKeys"] && !in_array($perKey,$params["onlyTheseKeys"]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$sheet->setCellValueByColumnAndRow ( $colCounter, $rowCounter, $perKey );
|
||||
$style = array(
|
||||
'alignment' => array(
|
||||
'horizontal' => "center",
|
||||
)
|
||||
);
|
||||
|
||||
$sheet->getDefaultStyle()->applyFromArray($style);
|
||||
$colCounter++;
|
||||
}
|
||||
$rowCounter++;
|
||||
}
|
||||
|
||||
foreach ($valueArray as $perValue)
|
||||
{
|
||||
$colCounter = 0;
|
||||
foreach ($perValue as $perCol)
|
||||
{
|
||||
if ($params["onlyTheseKeys"] && !in_array($perKey,$params["onlyTheseKeys"]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (is_array($perCol))
|
||||
{
|
||||
$perCol = json_encode($perCol);
|
||||
}
|
||||
$sheet->setCellValueByColumnAndRow ( $colCounter, $rowCounter, $perCol );
|
||||
$colCounter++;
|
||||
}
|
||||
$rowCounter++;
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
});
|
||||
return $result;
|
||||
} catch ( Exception $e )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static function singleElementArray ( $arrayElement,array $extraParams = null)
|
||||
{
|
||||
$isMultiArray = true;
|
||||
|
||||
if ( !is_array($arrayElement))
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
foreach ($arrayElement as $perItem)
|
||||
{
|
||||
if (gettype($perItem)!="array")
|
||||
{
|
||||
$isMultiArray = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!$isMultiArray)
|
||||
{
|
||||
$isMultiArray = true;
|
||||
foreach (array_keys ( $arrayElement ) as $perKey)
|
||||
{
|
||||
if (!is_numeric($perKey))
|
||||
{
|
||||
$isMultiArray = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $isMultiArray?$arrayElement:array($arrayElement);
|
||||
|
||||
}
|
||||
|
||||
public static function checkWizardMenu($wizardArray, $menuCode)
|
||||
{
|
||||
return array_filter($wizardArray, function ($key) use ($menuCode) {
|
||||
return $key['menu_code'] == $menuCode ? true : false;
|
||||
}, ARRAY_FILTER_USE_BOTH);
|
||||
}
|
||||
|
||||
|
||||
/*If its an array enter the index of the array to $index variable*/
|
||||
public static function fillOnUndefined($variable,$index = null,$fillWith = null,$arrayDelimiter = ".")
|
||||
{
|
||||
if ( !$arrayDelimiter)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$index = trim($index,$arrayDelimiter);
|
||||
|
||||
if ( !$index && $index !== '0')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$indexes = explode($arrayDelimiter,$index);
|
||||
|
||||
$arrayDeep = $variable;
|
||||
|
||||
foreach ($indexes as $perIndex)
|
||||
{
|
||||
if ( !isset($arrayDeep[$perIndex]))
|
||||
{
|
||||
return $fillWith;
|
||||
}
|
||||
|
||||
$arrayDeep = $arrayDeep[$perIndex];
|
||||
}
|
||||
|
||||
return $arrayDeep;
|
||||
}
|
||||
public static function hexToBinary ( $hex )
|
||||
{
|
||||
if ( strlen($hex)<=0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
$str = "";
|
||||
for($i=0;$i<strlen($hex);$i+=2)
|
||||
$str .= chr(hexdec(substr($hex,$i,2)));
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
public static function pickItemFromArray($index,array $targetArray)
|
||||
{
|
||||
try
|
||||
{
|
||||
$result = [ ];
|
||||
foreach ($targetArray as $perIndex => $perValue)
|
||||
{
|
||||
if (isset($perValue[$index]))
|
||||
{
|
||||
$result[] = $perValue[$index];
|
||||
}
|
||||
|
||||
}
|
||||
return $result;
|
||||
} catch ( Exception $e )
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public static function pickNodeFromArray($index, $value, array $targetArray)
|
||||
{
|
||||
try {
|
||||
$result = [];
|
||||
foreach ($targetArray as $perIndex => $perValue) {
|
||||
if (isset($perValue[$index]) && $perValue[$index] == $value) {
|
||||
$result = $perValue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
} catch (Exception $e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public static function numberSortTurkish($number)
|
||||
{
|
||||
$returnString = '';
|
||||
$numberValue = [
|
||||
'inci' => [1,5,8,20,70,80],
|
||||
'üncü' => [3,4,100],
|
||||
'nci' => [2,7,50],
|
||||
'ıncı' => [0,40,60,90],
|
||||
'ncı' => [6],
|
||||
'uncu' => [9,10,30]
|
||||
];
|
||||
|
||||
if(strlen($number) < 4) {
|
||||
if ($number % 10 == 0) {
|
||||
$numberKey = $number;
|
||||
} else $numberKey = substr($number, -1,1);
|
||||
}
|
||||
|
||||
foreach ($numberValue as $orderKey => $numbers) {
|
||||
if (array_search($numberKey, $numbers) !== false) {
|
||||
$returnString = $orderKey;
|
||||
}
|
||||
}
|
||||
|
||||
return $returnString;
|
||||
|
||||
}
|
||||
|
||||
public static function now ( array $param = [] )
|
||||
{
|
||||
return date("Y-m-d H:i:s");
|
||||
}
|
||||
|
||||
public static function todayDate ( array $param = [] )
|
||||
{
|
||||
return date("Y-m-d");
|
||||
}
|
||||
|
||||
public static function moneyFormatWithTwoDecimals($money)
|
||||
{
|
||||
$money = str_replace(",","",$money);
|
||||
return number_format($money,2,'.','');
|
||||
}
|
||||
|
||||
public static function getXmlResponse ($view,$data)
|
||||
{
|
||||
$responseObj = App::make("Response");
|
||||
return $responseObj::view($view,$data)->header('Content-Type', 'text/xml');
|
||||
}
|
||||
|
||||
public static function preDie($args)
|
||||
{
|
||||
|
||||
echo '<pre>';
|
||||
print_r($args);
|
||||
echo '</pre>';
|
||||
|
||||
die;
|
||||
}
|
||||
}
|
||||
264
app/Core/Helper/compat_l5.php
Normal file
264
app/Core/Helper/compat_l5.php
Normal file
@@ -0,0 +1,264 @@
|
||||
<?php
|
||||
|
||||
if(!function_exists('config_path'))
|
||||
{
|
||||
/**
|
||||
* Return the path to config files
|
||||
* @param null $path
|
||||
* @return string
|
||||
*/
|
||||
function config_path($path=null)
|
||||
{
|
||||
return app()->getConfigurationPath(rtrim($path, ".php"));
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists('public_path'))
|
||||
{
|
||||
|
||||
/**
|
||||
* Return the path to public dir
|
||||
* @param null $path
|
||||
* @return string
|
||||
*/
|
||||
function public_path($path=null)
|
||||
{
|
||||
return rtrim(app()->basePath('public/'.$path), '/');
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists('storage_path'))
|
||||
{
|
||||
|
||||
/**
|
||||
* Return the path to storage dir
|
||||
* @param null $path
|
||||
* @return string
|
||||
*/
|
||||
function storage_path($path=null)
|
||||
{
|
||||
return app()->storagePath($path);
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists('database_path'))
|
||||
{
|
||||
|
||||
/**
|
||||
* Return the path to database dir
|
||||
* @param null $path
|
||||
* @return string
|
||||
*/
|
||||
function database_path($path=null)
|
||||
{
|
||||
return app()->databasePath($path);
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists('resource_path'))
|
||||
{
|
||||
|
||||
/**
|
||||
* Return the path to resource dir
|
||||
* @param null $path
|
||||
* @return string
|
||||
*/
|
||||
function resource_path($path=null)
|
||||
{
|
||||
return app()->resourcePath($path);
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists('lang_path'))
|
||||
{
|
||||
|
||||
/**
|
||||
* Return the path to lang dir
|
||||
* @param null $str
|
||||
* @return string
|
||||
*/
|
||||
function lang_path($path=null)
|
||||
{
|
||||
return app()->getLanguagePath($path);
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists('asset'))
|
||||
{
|
||||
/**
|
||||
* Generate an asset path for the application.
|
||||
*
|
||||
* @param string $path
|
||||
* @param bool $secure
|
||||
* @return string
|
||||
*/
|
||||
function asset($path, $secure = null)
|
||||
{
|
||||
return app('url')->asset($path, $secure);
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists('elixir'))
|
||||
{
|
||||
/**
|
||||
* Get the path to a versioned Elixir file.
|
||||
*
|
||||
* @param string $file
|
||||
* @return string
|
||||
*/
|
||||
function elixir($file)
|
||||
{
|
||||
static $manifest = null;
|
||||
if (is_null($manifest))
|
||||
{
|
||||
$manifest = json_decode(file_get_contents(public_path().'/build/rev-manifest.json'), true);
|
||||
}
|
||||
if (isset($manifest[$file]))
|
||||
{
|
||||
return '/build/'.$manifest[$file];
|
||||
}
|
||||
throw new InvalidArgumentException("File {$file} not defined in asset manifest.");
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists('auth'))
|
||||
{
|
||||
/**
|
||||
* Get the available auth instance.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Auth\Guard
|
||||
*/
|
||||
function auth()
|
||||
{
|
||||
return app('Illuminate\Contracts\Auth\Guard');
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists('bcrypt'))
|
||||
{
|
||||
/**
|
||||
* Hash the given value.
|
||||
*
|
||||
* @param string $value
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
function bcrypt($value, $options = array())
|
||||
{
|
||||
return app('hash')->make($value, $options);
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists('redirect'))
|
||||
{
|
||||
/**
|
||||
* Get an instance of the redirector.
|
||||
*
|
||||
* @param string|null $to
|
||||
* @param int $status
|
||||
* @param array $headers
|
||||
* @param bool $secure
|
||||
* @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
function redirect($to = null, $status = 302, $headers = array(), $secure = null)
|
||||
{
|
||||
if (is_null($to)) return app('redirect');
|
||||
return app('redirect')->to($to, $status, $headers, $secure);
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists('response'))
|
||||
{
|
||||
/**
|
||||
* Return a new response from the application.
|
||||
*
|
||||
* @param string $content
|
||||
* @param int $status
|
||||
* @param array $headers
|
||||
* @return \Symfony\Component\HttpFoundation\Response|\Illuminate\Contracts\Routing\ResponseFactory
|
||||
*/
|
||||
function response($content = '', $status = 200, array $headers = array())
|
||||
{
|
||||
$factory = app('Illuminate\Contracts\Routing\ResponseFactory');
|
||||
if (func_num_args() === 0)
|
||||
{
|
||||
return $factory;
|
||||
}
|
||||
return $factory->make($content, $status, $headers);
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists('secure_asset'))
|
||||
{
|
||||
/**
|
||||
* Generate an asset path for the application.
|
||||
*
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
function secure_asset($path)
|
||||
{
|
||||
return asset($path, true);
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists('secure_url'))
|
||||
{
|
||||
/**
|
||||
* Generate a HTTPS url for the application.
|
||||
*
|
||||
* @param string $path
|
||||
* @param mixed $parameters
|
||||
* @return string
|
||||
*/
|
||||
function secure_url($path, $parameters = array())
|
||||
{
|
||||
return url($path, $parameters, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( ! function_exists('session'))
|
||||
{
|
||||
/**
|
||||
* Get / set the specified session value.
|
||||
*
|
||||
* If an array is passed as the key, we will assume you want to set an array of values.
|
||||
*
|
||||
* @param array|string $key
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
function session($key = null, $default = null)
|
||||
{
|
||||
if (is_null($key)) return app('session');
|
||||
if (is_array($key)) return app('session')->put($key);
|
||||
return app('session')->get($key, $default);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( ! function_exists('cookie'))
|
||||
{
|
||||
/**
|
||||
* Create a new cookie instance.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
* @param int $minutes
|
||||
* @param string $path
|
||||
* @param string $domain
|
||||
* @param bool $secure
|
||||
* @param bool $httpOnly
|
||||
* @return \Symfony\Component\HttpFoundation\Cookie
|
||||
*/
|
||||
function cookie($name = null, $value = null, $minutes = 0, $path = null, $domain = null, $secure = false, $httpOnly = true)
|
||||
{
|
||||
$cookie = app('Illuminate\Contracts\Cookie\Factory');
|
||||
if (is_null($name))
|
||||
{
|
||||
return $cookie;
|
||||
}
|
||||
return $cookie->make($name, $value, $minutes, $path, $domain, $secure, $httpOnly);
|
||||
}
|
||||
}
|
||||
463
app/Core/Helper/helpers.php
Normal file
463
app/Core/Helper/helpers.php
Normal file
@@ -0,0 +1,463 @@
|
||||
<?php
|
||||
|
||||
use App\Core\Helper\LanguageService;
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Laravel\Lumen\Bus\PendingDispatch;
|
||||
use Illuminate\Contracts\Bus\Dispatcher;
|
||||
use Illuminate\Contracts\Debug\ExceptionHandler;
|
||||
use Laravel\Lumen\Http\ResponseFactory;
|
||||
use Symfony\Component\Debug\Exception\FatalThrowableError;
|
||||
use Illuminate\Contracts\Broadcasting\Factory as BroadcastFactory;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
|
||||
function output($param)
|
||||
{
|
||||
|
||||
$statusArr = [1 => "success", -1 => "exception", 0 => "error"];
|
||||
$exceptionClassArr = ["exception" => "\Exception", "error" => "App\Exceptions\ApiErrorException"];
|
||||
$statusCodeArr = [1 => 200, -1 => 500, 0 => 400];
|
||||
$param["status"] = isset($param["status"]) ? $param["status"] : 1;
|
||||
$status = isset($statusArr[$param["status"]]) ? $statusArr[$param["status"]] : "success";
|
||||
$statusCode = isset($statusCodeArr[$param["status"]]) ? $statusCodeArr[$param["status"]] : 200;
|
||||
$message = (isset($param['message']) ? $param['message'] : '');
|
||||
$data = (isset($param['data']) ? $param['data'] : '');
|
||||
$exceptionClass = isset($exceptionClassArr[$status]) ? new $exceptionClassArr[$status]($message) : null;
|
||||
|
||||
return ['status' => $status, 'message' => $message, 'data' => $data, 'statusCode' => $statusCode, "exceptionClass" => $exceptionClass];
|
||||
}
|
||||
|
||||
function apiResponse($status = -1, $message = "", $data = [], $statusCode = null, $errorCode = null)
|
||||
{
|
||||
$genericMessage = "Bilinmeyen Bir Hata Oluştu";
|
||||
$error = $status <= 0 ? true : false;
|
||||
$statusCode = $statusCode ? $statusCode : 200;
|
||||
$errorCode = $errorCode ? $errorCode : null;
|
||||
//$statusCode = $error ? 500 : $statusCode;
|
||||
$message = $status != -1 ? $message : $genericMessage;
|
||||
$message = $message ? $message : null;
|
||||
$data = $data && is_array($data) ? $data : [];
|
||||
|
||||
$responseData = [
|
||||
"status" => $statusCode,
|
||||
"error" => $error,
|
||||
"errorCode" => $errorCode,
|
||||
"message" => $message,
|
||||
"data" => $data
|
||||
];
|
||||
|
||||
/** ServiceLog **/
|
||||
$serviceLogId = app('request')->serviceLogId;
|
||||
$serviceLogRequestTime = app('request')->serviceLogRequestTime;
|
||||
if (!empty($serviceLogId)) {
|
||||
$updateServiceLog = [
|
||||
'response' => json_encode($responseData),
|
||||
'response_time' => microtime(true) - $serviceLogRequestTime,
|
||||
'status' => 1
|
||||
];
|
||||
$serviceLog = App::make("App\Core\Service\ServiceLogService");
|
||||
$serviceLog->update($serviceLogId, $updateServiceLog);
|
||||
}
|
||||
/** ServiceLog **/
|
||||
|
||||
return response()->json($responseData, $statusCode);
|
||||
}
|
||||
|
||||
function fillOnUndefined($variable, $index = null, $fillWith = null, $arrayDelimiter = ".")
|
||||
{
|
||||
if (!$arrayDelimiter) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
if (!$index && $index !== '0' && $index !== 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$indexes = explode($arrayDelimiter, $index);
|
||||
|
||||
$arrayDeep = $variable;
|
||||
|
||||
foreach ($indexes as $perIndex) {
|
||||
if (!isset($arrayDeep[$perIndex])) {
|
||||
return $fillWith;
|
||||
}
|
||||
|
||||
$arrayDeep = $arrayDeep[$perIndex];
|
||||
}
|
||||
|
||||
|
||||
return $arrayDeep;
|
||||
|
||||
}
|
||||
|
||||
function fillOnUndefinedAndEmpty($variable, $index = null, $fillWith = null, $arrayDelimiter = ".")
|
||||
{
|
||||
if (!$arrayDelimiter) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
if (!$index && $index !== '' && $index !== '0' && $index !== 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$indexes = explode($arrayDelimiter, $index);
|
||||
|
||||
$arrayDeep = $variable;
|
||||
|
||||
foreach ($indexes as $perIndex) {
|
||||
if (!isset($arrayDeep[$perIndex]) || empty($arrayDeep[$perIndex])) {
|
||||
return $fillWith;
|
||||
}
|
||||
|
||||
$arrayDeep = $arrayDeep[$perIndex];
|
||||
}
|
||||
|
||||
|
||||
return $arrayDeep;
|
||||
|
||||
}
|
||||
|
||||
function createFolderAndSubFolder($structure, $path = __DIR__, &$createdPaths, $mode = 0777)
|
||||
{
|
||||
|
||||
foreach ($structure as $folder => $subFolder) {
|
||||
if (is_array($subFolder)) {
|
||||
$newPath = "{$path}/{$folder}";
|
||||
//$createdPaths[$newPath] = $newPath;
|
||||
$createdPaths[] = $newPath;
|
||||
|
||||
if (!is_dir($newPath)) mkdir($newPath, $mode);
|
||||
|
||||
createFolderAndSubFolder($subFolder, $newPath, $createdPaths);
|
||||
} else {
|
||||
$newPath = "{$path}/{$subFolder}";
|
||||
//$createdPaths[$newPath] = $newPath;
|
||||
$createdPaths[] = $newPath;
|
||||
if (!is_dir($newPath)) mkdir($newPath, $mode);
|
||||
}
|
||||
}
|
||||
|
||||
return $createdPaths;
|
||||
}
|
||||
|
||||
function smartyModifierFileSize($size)
|
||||
{
|
||||
$size = max(0, (int)$size);
|
||||
$units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
|
||||
$power = $size > 0 ? floor(log($size, 1024)) : 0;
|
||||
$convertSize = number_format($size / pow(1024, $power), 2, '.', ',');
|
||||
$convertType = $units[$power];
|
||||
return [$convertSize, $convertType];
|
||||
}
|
||||
|
||||
function pickItemFromArray($index, array $targetArray)
|
||||
{
|
||||
try {
|
||||
$result = [];
|
||||
foreach ($targetArray as $perIndex => $perValue) {
|
||||
if (isset($perValue[$index])) {
|
||||
$result[] = $perValue[$index];
|
||||
}
|
||||
|
||||
}
|
||||
return $result;
|
||||
} catch (Exception $e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function lang($word, array $parameters = [], $lang = null)
|
||||
{
|
||||
return LanguageService::lang($word, $parameters, $lang);
|
||||
}
|
||||
|
||||
function getSystemLang()
|
||||
{
|
||||
return LanguageService::getCurrentLang();
|
||||
}
|
||||
|
||||
function getSystemLangSession()
|
||||
{
|
||||
return session("sysLang");
|
||||
}
|
||||
|
||||
function setSystemLangSession($language)
|
||||
{
|
||||
$validLanguages = LanguageService::getValidLanguages();
|
||||
if (!in_array($language, $validLanguages)) {
|
||||
throw new Exception("Invalid Language Selected language parameter : " . json_encode($language));
|
||||
}
|
||||
session()->set("sysLang", $language);
|
||||
return $language;
|
||||
}
|
||||
|
||||
function getSystemDefaultLang()
|
||||
{
|
||||
return LanguageService::getDefaultLang();
|
||||
}
|
||||
|
||||
function getLanguageSupportList()
|
||||
{
|
||||
return LanguageService::getLanguageSupportList();
|
||||
}
|
||||
|
||||
function upperCase($word, $charset = "UTF-8")
|
||||
{
|
||||
$word = str_replace("i", "İ", $word);
|
||||
return mb_strtoupper($word, $charset);
|
||||
}
|
||||
|
||||
function lowerCase($word, $charset = "UTF-8")
|
||||
{
|
||||
$word = str_replace("I", "ı", $word);
|
||||
return mb_strtolower($word, $charset);
|
||||
}
|
||||
|
||||
function uCase($word, $charset = "UTF-8")
|
||||
{
|
||||
$word = preg_replace("#(^\i)#", "İ", $word);
|
||||
$word = preg_replace("#(^\ı)#", "I", $word);
|
||||
return mb_convert_case($word, MB_CASE_TITLE, $charset);
|
||||
}
|
||||
|
||||
function reIndexArrayKeys(array $targetArray, $startNo = 0)
|
||||
{
|
||||
if (!$targetArray) {
|
||||
return [];
|
||||
}
|
||||
return array_combine(range($startNo, ($startNo - 1) + count($targetArray)), $targetArray);
|
||||
}
|
||||
|
||||
function singleElementXMLArray($array = [])
|
||||
{
|
||||
|
||||
return fillOnUndefined($array, 0) && is_array($array) ? $array : [$array];
|
||||
}
|
||||
|
||||
function toArray($value): array
|
||||
{
|
||||
return is_array($value) ? $value : ($value !== null ? [$value] : []);
|
||||
}
|
||||
|
||||
|
||||
function singleElementArray($arrayElement, array $extraParams = null)
|
||||
{
|
||||
|
||||
$isMultiArray = true;
|
||||
|
||||
if (!is_array($arrayElement)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
foreach ($arrayElement as $perItem) {
|
||||
if (gettype($perItem) != "array") {
|
||||
$isMultiArray = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$isMultiArray) {
|
||||
$isMultiArray = true;
|
||||
foreach (array_keys($arrayElement) as $perKey) {
|
||||
if (!is_numeric($perKey)) {
|
||||
$isMultiArray = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $isMultiArray ? $arrayElement : array($arrayElement);
|
||||
|
||||
}
|
||||
|
||||
function generateRandomString($length = 5)
|
||||
{
|
||||
return \App\Core\Helper\PhpHelper::generateRandomString($length);
|
||||
}
|
||||
|
||||
function humanReadableDate($date)
|
||||
{
|
||||
return date('d/m/Y', strtotime($date));
|
||||
}
|
||||
|
||||
function language_key($title)
|
||||
{
|
||||
return Str::slug($title, $separator = '_', $language = 'en');
|
||||
}
|
||||
|
||||
function getGuid()
|
||||
{
|
||||
$hash = md5(uniqid());
|
||||
$guid = substr($hash, 0, 8) .
|
||||
'-' .
|
||||
substr($hash, 8, 4) .
|
||||
'-' .
|
||||
substr($hash, 12, 4) .
|
||||
'-' .
|
||||
substr($hash, 16, 4) .
|
||||
'-' .
|
||||
substr($hash, 20, 12);
|
||||
|
||||
return $guid;
|
||||
}
|
||||
|
||||
function moneyDoubleFormat($money)
|
||||
{
|
||||
return number_format($money, 2, ',', '');
|
||||
}
|
||||
|
||||
|
||||
function moneyDoubleFormatDecimal($money)
|
||||
{
|
||||
return floatval(number_format($money, 2, '.', ''));
|
||||
}
|
||||
|
||||
function moneyFourFormatDecimal($money)
|
||||
{
|
||||
return floatval(number_format($money, 4, '.', ''));
|
||||
}
|
||||
|
||||
|
||||
function getCodeGenerate($prefix = 'ENW')
|
||||
{
|
||||
return $prefix . date('ymd') . '-' . upperCase(generateRandomString(8));
|
||||
}
|
||||
|
||||
function getPaymentGenerate($prefix = 'PYM')
|
||||
{
|
||||
$prefix = is_null($prefix) ? 'PYM' : $prefix;
|
||||
return 'ENW' . $prefix . date('ymd') . '_' . upperCase(generateRandomString(8));
|
||||
}
|
||||
|
||||
function getTicketCodeGenerate($prefix = 'TCK')
|
||||
{
|
||||
return $prefix . upperCase(generateRandomString(8));
|
||||
}
|
||||
|
||||
function creditCardMask($cardNumber)
|
||||
{
|
||||
return substr($cardNumber, 0, 6) . '******' . substr($cardNumber, -4);
|
||||
}
|
||||
|
||||
function occupancyCodeFormatted($occupancyCode)
|
||||
{
|
||||
|
||||
$occupancyFormatted = [];
|
||||
|
||||
$adultCount = substr_count($occupancyCode, 'A');
|
||||
if ($adultCount > 0) {
|
||||
$occupancyFormatted[] = $adultCount . ' Adult';
|
||||
}
|
||||
|
||||
$childCount = substr_count($occupancyCode, 'C');
|
||||
if ($childCount > 0) {
|
||||
|
||||
$childAges = [];
|
||||
$roomsChildArray = explode('C', $occupancyCode);
|
||||
for ($i = 1; $i < count($roomsChildArray); $i++) {
|
||||
if (!empty($roomsChildArray[$i]) || $roomsChildArray[$i] == 0) {
|
||||
$childAges[] = $roomsChildArray[$i];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($childAges)) {
|
||||
$childAges = implode(', ', $childAges);
|
||||
}
|
||||
|
||||
$occupancyFormatted[] = $childCount . ' Child' . (!empty($childAges) ? ' (' . $childAges . ')' : null);
|
||||
}
|
||||
|
||||
if (!empty($occupancyFormatted)) {
|
||||
$occupancyFormatted = implode(', ', $occupancyFormatted);
|
||||
}
|
||||
|
||||
return $occupancyFormatted;
|
||||
}
|
||||
|
||||
function occupancyCodeParser($occupancyCode)
|
||||
{
|
||||
|
||||
$occupancy = [];
|
||||
$occupancy['ADT'] = 0;
|
||||
$occupancy['CHD'] = 0;
|
||||
$occupancy['AGE'] = [];
|
||||
|
||||
$adultCount = substr_count($occupancyCode, 'A');
|
||||
if ($adultCount > 0) {
|
||||
$occupancy['ADT'] = $adultCount;
|
||||
}
|
||||
|
||||
$childCount = substr_count($occupancyCode, 'C');
|
||||
if ($childCount > 0) {
|
||||
|
||||
$childAges = [];
|
||||
$roomsChildArray = explode('C', $occupancyCode);
|
||||
for ($i = 1; $i < count($roomsChildArray); $i++) {
|
||||
if (!empty($roomsChildArray[$i])) {
|
||||
$childAges[] = $roomsChildArray[$i];
|
||||
}
|
||||
}
|
||||
|
||||
$occupancy['CHD'] = $childCount;
|
||||
$occupancy['AGE'] = $childAges;
|
||||
|
||||
//$occupancyFormatted[] = $childCount . ' Child' . (!empty($childAges) ? ' (' . $childAges . ')' : null);
|
||||
}
|
||||
|
||||
return $occupancy;
|
||||
}
|
||||
|
||||
|
||||
function occupancyGroup($maxAdult, $maxChild, $maxOccupancy, $excludeOccupancy = [])
|
||||
{
|
||||
|
||||
$occupancyGroup = [];
|
||||
//TODO: $excludeOccupancy
|
||||
for ($i = 0; $i < $maxAdult; $i++) {
|
||||
$occupancyCodeAdult = str_repeat('A', ($i + 1));
|
||||
if (strlen($occupancyCodeAdult) > $maxOccupancy) {
|
||||
break;
|
||||
}
|
||||
$occupancyGroup[] = $occupancyCodeAdult;
|
||||
|
||||
for ($j = 0; $j < $maxChild; $j++) {
|
||||
$occupancyCodeChild = str_repeat('C', ($j + 1));
|
||||
|
||||
if (strlen($occupancyCodeChild) > $maxOccupancy) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strlen($occupancyCodeAdult . $occupancyCodeChild) > $maxOccupancy) {
|
||||
break;
|
||||
}
|
||||
|
||||
$occupancyGroup[] = $occupancyCodeAdult . $occupancyCodeChild;
|
||||
}
|
||||
}
|
||||
|
||||
return $occupancyGroup;
|
||||
}
|
||||
|
||||
|
||||
function cancellationPolicyTextFormatted($isNonRefundable, $isFreeCancellation, $beforeArrivalDay, $type, $value, $currency, $languageCode = 'en')
|
||||
{
|
||||
|
||||
$formattedText = null;
|
||||
if (!$isFreeCancellation) {
|
||||
if ($isNonRefundable) {
|
||||
$formattedText = __('btn-irrevocable', [], $languageCode);
|
||||
} else {
|
||||
|
||||
$formattedText = __('be-if_canceled_up_to_days', ['day' => $beforeArrivalDay], $languageCode) . ', ' . $value . ($type == 'PER' ? '%' : $currency) . ' ' . __('be-search-impose_penalty', [], $languageCode);
|
||||
}
|
||||
} else {
|
||||
$formattedText = ($beforeArrivalDay > 0 ? __('be-up_to_days', ['day' => $beforeArrivalDay], $languageCode) : '') . ' ' . __('btn-free_cancellation', [], $languageCode);
|
||||
}
|
||||
|
||||
return $formattedText;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user