You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.4 KiB
PHP
36 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Helper;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class Common {
|
|
public static function convertRequestConfig(?array $requestConfig): array {
|
|
$config = [];
|
|
if (isset($requestConfig['timezone'])) $config['timezone'] = $requestConfig['timezone'];
|
|
if (isset($requestConfig['attendanceRadius'])) $config['attendance_radius'] = (double) $requestConfig['attendanceRadius'];
|
|
if (isset($requestConfig['mustInRadius'])) $config['must_in_radius'] = self::trueOrFalse($requestConfig['mustInRadius']);
|
|
if (isset($requestConfig['mustTakePicture'])) $config['must_take_picture'] = self::trueOrFalse($requestConfig['mustTakePicture']);
|
|
|
|
return $config;
|
|
}
|
|
|
|
public static function generateRandomString($length = 10) {
|
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
$charactersLength = strlen($characters);
|
|
$randomString = '';
|
|
for ($i = 0; $i < $length; $i++) {
|
|
$randomString .= $characters[random_int(0, $charactersLength - 1)];
|
|
}
|
|
return $randomString;
|
|
}
|
|
|
|
public static function trueOrFalse(mixed $value): bool {
|
|
return ($value === "true" || $value === "1" || $value === 1 || $value === true) ? true : false;
|
|
}
|
|
|
|
public static function setTimezone($timezone) {
|
|
date_default_timezone_set($timezone);
|
|
DB::statement("SET TIME ZONE '$timezone'");
|
|
}
|
|
} |