@@ -8,8 +8,8 @@ php:
|
|||||||
# - '7.3'
|
# - '7.3'
|
||||||
- '7.4'
|
- '7.4'
|
||||||
|
|
||||||
env:
|
#env:
|
||||||
- DB=mysql
|
# - DB=mysql
|
||||||
# - DB=mariadb
|
# - DB=mariadb
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
@@ -23,8 +23,8 @@ cache:
|
|||||||
services:
|
services:
|
||||||
- mysql
|
- mysql
|
||||||
|
|
||||||
addons:
|
#addons:
|
||||||
mariadb: '10.2'
|
# mariadb: '10.2'
|
||||||
|
|
||||||
install:
|
install:
|
||||||
- php --version
|
- php --version
|
||||||
|
|||||||
@@ -107,9 +107,12 @@ if [ "$TRAVIS" = "true" ]; then
|
|||||||
make clean
|
make clean
|
||||||
|
|
||||||
cd /tmp
|
cd /tmp
|
||||||
|
ls -al $TRAVIS_BUILD_DIR/../
|
||||||
|
|
||||||
tar -czf $TAR_NAME -C $TRAVIS_BUILD_DIR/../
|
tar -czf $TAR_NAME -C $TRAVIS_BUILD_DIR/../
|
||||||
sha256sum $TAR_NAME >"$TAR_NAME.sha256"
|
sha256sum $TAR_NAME >"$TAR_NAME.sha256"
|
||||||
tar2zip $TAR_NAME
|
tar2zip $TAR_NAME
|
||||||
|
sha256sum $ZIP_NAME >"$ZIP_NAME.sha256"
|
||||||
|
|
||||||
ls -al /tmp
|
ls -al /tmp
|
||||||
|
|
||||||
@@ -117,8 +120,8 @@ if [ "$TRAVIS" = "true" ]; then
|
|||||||
mkdir -p $TRAVIS_BUILD_DIR/build
|
mkdir -p $TRAVIS_BUILD_DIR/build
|
||||||
cd $TRAVIS_BUILD_DIR/build
|
cd $TRAVIS_BUILD_DIR/build
|
||||||
|
|
||||||
mv "/tmp/$TAR_NAME" "/tmp/$ZIP_NAME" "/tmp/$TAR_NAME.sha256" .
|
mv "/tmp/$TAR_NAME" "/tmp/$ZIP_NAME" "/tmp/$TAR_NAME.sha256" "/tmp/$ZIP_NAME.sha256".
|
||||||
artifacts upload --target-paths "/" $ZIP_NAME $TAR_NAME $TRAVIS_BUILD_DIR/VERSION $TAR_NAME.sha256
|
artifacts upload --target-paths "/" $ZIP_NAME $TAR_NAME $TRAVIS_BUILD_DIR/VERSION $TAR_NAME.sha256 $ZIP_NAME.sha256
|
||||||
|
|
||||||
# Upload the version for a tagged release. Move to a version file in different
|
# Upload the version for a tagged release. Move to a version file in different
|
||||||
# tags. Within phpVMS, we have an option of which version to track in the admin
|
# tags. Within phpVMS, we have an option of which version to track in the admin
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use App\Contracts\Command;
|
use App\Contracts\Command;
|
||||||
use App\Facades\Utils;
|
use App\Support\Units\Time;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ class AcarsReplay extends Command
|
|||||||
protected function startPirep($flight): string
|
protected function startPirep($flight): string
|
||||||
{
|
{
|
||||||
// convert the planned flight time to be completely in minutes
|
// convert the planned flight time to be completely in minutes
|
||||||
$pft = Utils::hoursToMinutes(
|
$pft = Time::hoursToMinutes(
|
||||||
$flight->planned_hrsenroute,
|
$flight->planned_hrsenroute,
|
||||||
$flight->planned_minenroute
|
$flight->planned_minenroute
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
namespace App\Contracts;
|
namespace App\Contracts;
|
||||||
|
|
||||||
use App\Facades\Utils;
|
|
||||||
use App\Models\Award as AwardModel;
|
use App\Models\Award as AwardModel;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Models\UserAward;
|
use App\Models\UserAward;
|
||||||
|
use App\Support\Utils;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
|||||||
@@ -1,222 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Facades;
|
|
||||||
|
|
||||||
use GuzzleHttp\Client;
|
|
||||||
use Illuminate\Support\Facades\Facade;
|
|
||||||
|
|
||||||
class Utils extends Facade
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected static function getFacadeAccessor(): string
|
|
||||||
{
|
|
||||||
return 'utils';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Simple check on the first character if it's an object or not
|
|
||||||
*
|
|
||||||
* @param $obj
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public static function isObject($obj): bool
|
|
||||||
{
|
|
||||||
if (!$obj) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($obj[0] === '{' || $obj[0] === '[') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Download a URI. If a file is given, it will save the downloaded
|
|
||||||
* content into that file
|
|
||||||
*
|
|
||||||
* @param string $uri
|
|
||||||
* @param null $file
|
|
||||||
*
|
|
||||||
* @throws \RuntimeException
|
|
||||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function downloadUrl($uri, $file = null): string
|
|
||||||
{
|
|
||||||
$opts = [];
|
|
||||||
if ($file !== null) {
|
|
||||||
$opts['sink'] = $file;
|
|
||||||
}
|
|
||||||
|
|
||||||
$client = new Client();
|
|
||||||
$response = $client->request('GET', $uri, $opts);
|
|
||||||
|
|
||||||
$body = $response->getBody()->getContents();
|
|
||||||
if ($response->getHeader('content-type') === 'application/json') {
|
|
||||||
$body = \GuzzleHttp\json_decode($body);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $body;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a 40 character API key that a user can use
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function generateApiKey(): string
|
|
||||||
{
|
|
||||||
$key = substr(sha1(time().mt_rand()), 0, 20);
|
|
||||||
return $key;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $minutes
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public static function minutesToTimeParts($minutes): array
|
|
||||||
{
|
|
||||||
$hours = floor($minutes / 60);
|
|
||||||
$minutes %= 60;
|
|
||||||
|
|
||||||
return ['h' => $hours, 'm' => $minutes];
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function minutesToTimeString($minutes): string
|
|
||||||
{
|
|
||||||
$hm = self::minutesToTimeParts($minutes);
|
|
||||||
return $hm['h'].'h '.$hm['m'].'m';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert seconds to an array of hours, minutes, seconds
|
|
||||||
*
|
|
||||||
* @param int $seconds
|
|
||||||
*
|
|
||||||
* @throws \Exception
|
|
||||||
*
|
|
||||||
* @return array['h', 'm', 's']
|
|
||||||
*/
|
|
||||||
public static function secondsToTimeParts($seconds): array
|
|
||||||
{
|
|
||||||
$dtF = new \DateTimeImmutable('@0', new \DateTimeZone('UTC'));
|
|
||||||
$dtT = new \DateTimeImmutable("@$seconds", new \DateTimeZone('UTC'));
|
|
||||||
|
|
||||||
$t = $dtF->diff($dtT);
|
|
||||||
|
|
||||||
$retval = [];
|
|
||||||
$retval['h'] = (int) $t->format('%h');
|
|
||||||
$retval['m'] = (int) $t->format('%i');
|
|
||||||
$retval['s'] = (int) $t->format('%s');
|
|
||||||
|
|
||||||
return $retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert seconds to HH MM format
|
|
||||||
*
|
|
||||||
* @param int $seconds
|
|
||||||
* @param bool $incl_sec
|
|
||||||
*
|
|
||||||
* @throws \Exception
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function secondsToTimeString($seconds, $incl_sec = false): string
|
|
||||||
{
|
|
||||||
$hms = self::secondsToTimeParts($seconds);
|
|
||||||
$format = $hms['h'].'h '.$hms['m'].'m';
|
|
||||||
if ($incl_sec) {
|
|
||||||
$format .= ' '.$hms['s'].'s';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $format;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $minutes
|
|
||||||
*
|
|
||||||
* @return float|int
|
|
||||||
*/
|
|
||||||
public static function minutesToSeconds($minutes)
|
|
||||||
{
|
|
||||||
return $minutes * 60;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert the seconds to minutes and then round it up
|
|
||||||
*
|
|
||||||
* @param $seconds
|
|
||||||
*
|
|
||||||
* @return float|int
|
|
||||||
*/
|
|
||||||
public static function secondsToMinutes($seconds)
|
|
||||||
{
|
|
||||||
return ceil($seconds / 60);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert hours to minutes. Pretty complex
|
|
||||||
*
|
|
||||||
* @param $minutes
|
|
||||||
*
|
|
||||||
* @return float|int
|
|
||||||
*/
|
|
||||||
public static function minutesToHours($minutes)
|
|
||||||
{
|
|
||||||
return $minutes / 60;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $hours
|
|
||||||
* @param null $minutes
|
|
||||||
*
|
|
||||||
* @return float|int
|
|
||||||
*/
|
|
||||||
public static function hoursToMinutes($hours, $minutes = null)
|
|
||||||
{
|
|
||||||
$total = (int) $hours * 60;
|
|
||||||
if ($minutes) {
|
|
||||||
$total += (int) $minutes;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $total;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Bitwise operator for setting days of week to integer field
|
|
||||||
*
|
|
||||||
* @param int $datefield initial datefield
|
|
||||||
* @param array $day_enums Array of values from config("enum.days")
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public static function setDays(int $datefield, array $day_enums): int
|
|
||||||
{
|
|
||||||
foreach ($day_enums as $day) {
|
|
||||||
$datefield |= $day;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $datefield;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Bit check if a day exists within a integer bitfield
|
|
||||||
*
|
|
||||||
* @param int $datefield datefield from database
|
|
||||||
* @param int $day_enum Value from config("enum.days")
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public static function hasDay(int $datefield, int $day_enum): bool
|
|
||||||
{
|
|
||||||
return ($datefield & $day_enum) === $datefield;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,6 @@
|
|||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
use App\Contracts\Controller;
|
use App\Contracts\Controller;
|
||||||
use App\Facades\Utils;
|
|
||||||
use App\Http\Requests\CreatePirepRequest;
|
use App\Http\Requests\CreatePirepRequest;
|
||||||
use App\Http\Requests\UpdatePirepRequest;
|
use App\Http\Requests\UpdatePirepRequest;
|
||||||
use App\Models\Enums\PirepSource;
|
use App\Models\Enums\PirepSource;
|
||||||
@@ -260,7 +259,7 @@ class PirepController extends Controller
|
|||||||
|
|
||||||
$hours = (int) $attrs['hours'];
|
$hours = (int) $attrs['hours'];
|
||||||
$minutes = (int) $attrs['minutes'];
|
$minutes = (int) $attrs['minutes'];
|
||||||
$pirep->flight_time = Utils::hoursToMinutes($hours) + $minutes;
|
$pirep->flight_time = Time::hoursToMinutes($hours) + $minutes;
|
||||||
|
|
||||||
$this->saveCustomFields($pirep, $request);
|
$this->saveCustomFields($pirep, $request);
|
||||||
$this->saveFares($pirep, $request);
|
$this->saveFares($pirep, $request);
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
use App\Contracts\Controller;
|
use App\Contracts\Controller;
|
||||||
use App\Facades\Utils;
|
|
||||||
use App\Http\Requests\CreateUserRequest;
|
use App\Http\Requests\CreateUserRequest;
|
||||||
use App\Http\Requests\UpdateUserRequest;
|
use App\Http\Requests\UpdateUserRequest;
|
||||||
use App\Models\Rank;
|
use App\Models\Rank;
|
||||||
@@ -15,6 +14,7 @@ use App\Repositories\PirepRepository;
|
|||||||
use App\Repositories\UserRepository;
|
use App\Repositories\UserRepository;
|
||||||
use App\Services\UserService;
|
use App\Services\UserService;
|
||||||
use App\Support\Timezonelist;
|
use App\Support\Timezonelist;
|
||||||
|
use App\Support\Utils;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
namespace App\Http\Controllers\Auth;
|
namespace App\Http\Controllers\Auth;
|
||||||
|
|
||||||
use App\Contracts\Controller;
|
use App\Contracts\Controller;
|
||||||
use App\Facades\Utils;
|
|
||||||
use App\Models\Enums\UserState;
|
use App\Models\Enums\UserState;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Repositories\AirlineRepository;
|
use App\Repositories\AirlineRepository;
|
||||||
@@ -11,6 +10,7 @@ use App\Repositories\AirportRepository;
|
|||||||
use App\Services\UserService;
|
use App\Services\UserService;
|
||||||
use App\Support\Countries;
|
use App\Support\Countries;
|
||||||
use App\Support\Timezonelist;
|
use App\Support\Timezonelist;
|
||||||
|
use App\Support\Utils;
|
||||||
use Illuminate\Contracts\Validation\Validator;
|
use Illuminate\Contracts\Validation\Validator;
|
||||||
use Illuminate\Foundation\Auth\RegistersUsers;
|
use Illuminate\Foundation\Auth\RegistersUsers;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
namespace App\Http\Controllers\Frontend;
|
namespace App\Http\Controllers\Frontend;
|
||||||
|
|
||||||
use App\Contracts\Controller;
|
use App\Contracts\Controller;
|
||||||
use App\Facades\Utils;
|
|
||||||
use App\Http\Requests\CreatePirepRequest;
|
use App\Http\Requests\CreatePirepRequest;
|
||||||
use App\Http\Requests\UpdatePirepRequest;
|
use App\Http\Requests\UpdatePirepRequest;
|
||||||
use App\Models\Enums\PirepSource;
|
use App\Models\Enums\PirepSource;
|
||||||
@@ -324,7 +323,7 @@ class PirepController extends Controller
|
|||||||
// Any special fields
|
// Any special fields
|
||||||
$hours = (int) $request->input('hours', 0);
|
$hours = (int) $request->input('hours', 0);
|
||||||
$minutes = (int) $request->input('minutes', 0);
|
$minutes = (int) $request->input('minutes', 0);
|
||||||
$pirep->flight_time = Utils::hoursToMinutes($hours) + $minutes;
|
$pirep->flight_time = Time::hoursToMinutes($hours) + $minutes;
|
||||||
|
|
||||||
// Set the correct fuel units
|
// Set the correct fuel units
|
||||||
$pirep->block_fuel = new Fuel((float) $request->input('block_fuel'), setting('units.fuel'));
|
$pirep->block_fuel = new Fuel((float) $request->input('block_fuel'), setting('units.fuel'));
|
||||||
|
|||||||
@@ -3,13 +3,13 @@
|
|||||||
namespace App\Http\Controllers\Frontend;
|
namespace App\Http\Controllers\Frontend;
|
||||||
|
|
||||||
use App\Contracts\Controller;
|
use App\Contracts\Controller;
|
||||||
use App\Facades\Utils;
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Repositories\AirlineRepository;
|
use App\Repositories\AirlineRepository;
|
||||||
use App\Repositories\AirportRepository;
|
use App\Repositories\AirportRepository;
|
||||||
use App\Repositories\UserRepository;
|
use App\Repositories\UserRepository;
|
||||||
use App\Support\Countries;
|
use App\Support\Countries;
|
||||||
use App\Support\Timezonelist;
|
use App\Support\Timezonelist;
|
||||||
|
use App\Support\Utils;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
|||||||
23
app/Providers/DirectiveServiceProvider.php
Normal file
23
app/Providers/DirectiveServiceProvider.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Blade;
|
||||||
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keep custom directives that can be used in templates
|
||||||
|
*/
|
||||||
|
class DirectiveServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
public function boot(): void
|
||||||
|
{
|
||||||
|
Blade::directive('minutestotime', function ($expr) {
|
||||||
|
return "<?php echo \App\Support\Units\Time::minutesToTimeString($expr); ?>";
|
||||||
|
});
|
||||||
|
|
||||||
|
Blade::directive('minutestohours', function ($expr) {
|
||||||
|
return "<?php echo \App\Support\Units\Time::minutesToHours($expr); ?>";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,36 @@ use Carbon\Carbon;
|
|||||||
|
|
||||||
class Dates
|
class Dates
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Bitwise operator for setting days of week to integer field
|
||||||
|
*
|
||||||
|
* @param int $datefield initial datefield
|
||||||
|
* @param array $day_enums Array of values from config("enum.days")
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public static function setDays(int $datefield, array $day_enums): int
|
||||||
|
{
|
||||||
|
foreach ($day_enums as $day) {
|
||||||
|
$datefield |= $day;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $datefield;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bit check if a day exists within a integer bitfield
|
||||||
|
*
|
||||||
|
* @param int $datefield datefield from database
|
||||||
|
* @param int $day_enum Value from config("enum.days")
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function hasDay(int $datefield, int $day_enum): bool
|
||||||
|
{
|
||||||
|
return ($datefield & $day_enum) === $datefield;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the list of months, given a start date
|
* Get the list of months, given a start date
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -55,10 +55,18 @@ class HttpClient
|
|||||||
*/
|
*/
|
||||||
public function download($uri, $local_path)
|
public function download($uri, $local_path)
|
||||||
{
|
{
|
||||||
$response = $this->httpClient->request('GET', $uri, [
|
$opts = [];
|
||||||
'sink' => $local_path,
|
if ($local_path !== null) {
|
||||||
]);
|
$opts['sink'] = $local_path;
|
||||||
|
}
|
||||||
|
|
||||||
return $response;
|
$response = $this->httpClient->request('GET', $uri, $opts);
|
||||||
|
|
||||||
|
$body = $response->getBody()->getContents();
|
||||||
|
if ($response->getHeader('content-type') === 'application/json') {
|
||||||
|
$body = \GuzzleHttp\json_decode($body);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $body;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,6 @@ namespace App\Support\Units;
|
|||||||
|
|
||||||
use Illuminate\Contracts\Support\Arrayable;
|
use Illuminate\Contracts\Support\Arrayable;
|
||||||
|
|
||||||
/**
|
|
||||||
* Class Time
|
|
||||||
*/
|
|
||||||
class Time implements Arrayable
|
class Time implements Arrayable
|
||||||
{
|
{
|
||||||
public $hours;
|
public $hours;
|
||||||
@@ -90,4 +87,118 @@ class Time implements Arrayable
|
|||||||
{
|
{
|
||||||
return $this->getMinutes();
|
return $this->getMinutes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $minutes
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function minutesToTimeParts($minutes): array
|
||||||
|
{
|
||||||
|
$hours = floor($minutes / 60);
|
||||||
|
$minutes %= 60;
|
||||||
|
|
||||||
|
return ['h' => $hours, 'm' => $minutes];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function minutesToTimeString($minutes): string
|
||||||
|
{
|
||||||
|
$hm = self::minutesToTimeParts($minutes);
|
||||||
|
return $hm['h'].'h '.$hm['m'].'m';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert seconds to an array of hours, minutes, seconds
|
||||||
|
*
|
||||||
|
* @param int $seconds
|
||||||
|
*
|
||||||
|
* @throws \Exception
|
||||||
|
*
|
||||||
|
* @return array['h', 'm', 's']
|
||||||
|
*/
|
||||||
|
public static function secondsToTimeParts($seconds): array
|
||||||
|
{
|
||||||
|
$dtF = new \DateTimeImmutable('@0', new \DateTimeZone('UTC'));
|
||||||
|
$dtT = new \DateTimeImmutable("@$seconds", new \DateTimeZone('UTC'));
|
||||||
|
|
||||||
|
$t = $dtF->diff($dtT);
|
||||||
|
|
||||||
|
$retval = [];
|
||||||
|
$retval['h'] = (int) $t->format('%h');
|
||||||
|
$retval['m'] = (int) $t->format('%i');
|
||||||
|
$retval['s'] = (int) $t->format('%s');
|
||||||
|
|
||||||
|
return $retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert seconds to HH MM format
|
||||||
|
*
|
||||||
|
* @param int $seconds
|
||||||
|
* @param bool $incl_sec
|
||||||
|
*
|
||||||
|
* @throws \Exception
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function secondsToTimeString($seconds, $incl_sec = false): string
|
||||||
|
{
|
||||||
|
$hms = self::secondsToTimeParts($seconds);
|
||||||
|
$format = $hms['h'].'h '.$hms['m'].'m';
|
||||||
|
if ($incl_sec) {
|
||||||
|
$format .= ' '.$hms['s'].'s';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $format;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $minutes
|
||||||
|
*
|
||||||
|
* @return float|int
|
||||||
|
*/
|
||||||
|
public static function minutesToSeconds($minutes)
|
||||||
|
{
|
||||||
|
return $minutes * 60;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert the seconds to minutes and then round it up
|
||||||
|
*
|
||||||
|
* @param $seconds
|
||||||
|
*
|
||||||
|
* @return float|int
|
||||||
|
*/
|
||||||
|
public static function secondsToMinutes($seconds)
|
||||||
|
{
|
||||||
|
return ceil($seconds / 60);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert hours to minutes. Pretty complex
|
||||||
|
*
|
||||||
|
* @param $minutes
|
||||||
|
*
|
||||||
|
* @return float|int
|
||||||
|
*/
|
||||||
|
public static function minutesToHours($minutes)
|
||||||
|
{
|
||||||
|
return $minutes / 60;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $hours
|
||||||
|
* @param null $minutes
|
||||||
|
*
|
||||||
|
* @return float|int
|
||||||
|
*/
|
||||||
|
public static function hoursToMinutes($hours, $minutes = null)
|
||||||
|
{
|
||||||
|
$total = (int) $hours * 60;
|
||||||
|
if ($minutes) {
|
||||||
|
$total += (int) $minutes;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $total;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,37 @@ use Nwidart\Modules\Facades\Module;
|
|||||||
*/
|
*/
|
||||||
class Utils
|
class Utils
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Returns a 40 character API key that a user can use
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function generateApiKey(): string
|
||||||
|
{
|
||||||
|
$key = substr(sha1(time().mt_rand()), 0, 20);
|
||||||
|
return $key;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple check on the first character if it's an object or not
|
||||||
|
*
|
||||||
|
* @param $obj
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function isObject($obj): bool
|
||||||
|
{
|
||||||
|
if (!$obj) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($obj[0] === '{' || $obj[0] === '[') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable the debug toolbar
|
* Enable the debug toolbar
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -74,13 +74,14 @@ return [
|
|||||||
* Application Service Providers...
|
* Application Service Providers...
|
||||||
*/
|
*/
|
||||||
App\Providers\AppServiceProvider::class,
|
App\Providers\AppServiceProvider::class,
|
||||||
App\Providers\CronServiceProvider::class,
|
|
||||||
App\Providers\BroadcastServiceProvider::class,
|
|
||||||
App\Providers\AuthServiceProvider::class,
|
App\Providers\AuthServiceProvider::class,
|
||||||
App\Providers\EventServiceProvider::class,
|
|
||||||
App\Providers\RouteServiceProvider::class,
|
|
||||||
App\Providers\MeasurementsProvider::class,
|
|
||||||
App\Providers\BindServiceProviders::class,
|
App\Providers\BindServiceProviders::class,
|
||||||
|
App\Providers\BroadcastServiceProvider::class,
|
||||||
|
App\Providers\CronServiceProvider::class,
|
||||||
|
App\Providers\DirectiveServiceProvider::class,
|
||||||
|
App\Providers\EventServiceProvider::class,
|
||||||
|
App\Providers\MeasurementsProvider::class,
|
||||||
|
App\Providers\RouteServiceProvider::class,
|
||||||
],
|
],
|
||||||
|
|
||||||
'aliases' => [
|
'aliases' => [
|
||||||
@@ -120,7 +121,6 @@ return [
|
|||||||
'Theme' => Igaster\LaravelTheme\Facades\Theme::class,
|
'Theme' => Igaster\LaravelTheme\Facades\Theme::class,
|
||||||
'Updater' => Codedge\Updater\UpdaterFacade::class,
|
'Updater' => Codedge\Updater\UpdaterFacade::class,
|
||||||
'URL' => Illuminate\Support\Facades\URL::class,
|
'URL' => Illuminate\Support\Facades\URL::class,
|
||||||
'Utils' => App\Facades\Utils::class,
|
|
||||||
'Validator' => Illuminate\Support\Facades\Validator::class,
|
'Validator' => Illuminate\Support\Facades\Validator::class,
|
||||||
'Version' => PragmaRX\Version\Package\Facade::class,
|
'Version' => PragmaRX\Version\Package\Facade::class,
|
||||||
'View' => Illuminate\Support\Facades\View::class,
|
'View' => Illuminate\Support\Facades\View::class,
|
||||||
|
|||||||
@@ -2,10 +2,11 @@
|
|||||||
|
|
||||||
namespace Modules\Importer\Services\Importers;
|
namespace Modules\Importer\Services\Importers;
|
||||||
|
|
||||||
use App\Facades\Utils;
|
|
||||||
use App\Models\Enums\UserState;
|
use App\Models\Enums\UserState;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Services\UserService;
|
use App\Services\UserService;
|
||||||
|
use App\Support\Units\Time;
|
||||||
|
use App\Support\Utils;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
@@ -62,7 +63,7 @@ class UserImport extends BaseImporter
|
|||||||
'home_airport_id' => $row->hub,
|
'home_airport_id' => $row->hub,
|
||||||
'curr_airport_id' => $row->hub,
|
'curr_airport_id' => $row->hub,
|
||||||
'flights' => (int) $row->totalflights,
|
'flights' => (int) $row->totalflights,
|
||||||
'flight_time' => Utils::hoursToMinutes($row->totalhours),
|
'flight_time' => Time::hoursToMinutes($row->totalhours),
|
||||||
'state' => $state,
|
'state' => $state,
|
||||||
'created_at' => $this->parseDate($row->joindate),
|
'created_at' => $this->parseDate($row->joindate),
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
namespace Modules\Installer\Http\Controllers;
|
namespace Modules\Installer\Http\Controllers;
|
||||||
|
|
||||||
use App\Contracts\Controller;
|
use App\Contracts\Controller;
|
||||||
use App\Facades\Utils;
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Repositories\AirlineRepository;
|
use App\Repositories\AirlineRepository;
|
||||||
use App\Services\AnalyticsService;
|
use App\Services\AnalyticsService;
|
||||||
@@ -13,6 +12,7 @@ use App\Services\Installer\MigrationService;
|
|||||||
use App\Services\Installer\SeederService;
|
use App\Services\Installer\SeederService;
|
||||||
use App\Services\UserService;
|
use App\Services\UserService;
|
||||||
use App\Support\Countries;
|
use App\Support\Countries;
|
||||||
|
use App\Support\Utils;
|
||||||
use Illuminate\Database\QueryException;
|
use Illuminate\Database\QueryException;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<td style="text-align: center;">{{ $ac->airport_id }}</td>
|
<td style="text-align: center;">{{ $ac->airport_id }}</td>
|
||||||
<td style="text-align: center;">
|
<td style="text-align: center;">
|
||||||
{{ Utils::minutesToTimeString($ac->flight_hours) }}
|
@minutestotime($ac->flight_hours)
|
||||||
</td>
|
</td>
|
||||||
<td style="text-align: center;">
|
<td style="text-align: center;">
|
||||||
@if($ac->status == \App\Models\Enums\AircraftStatus::ACTIVE)
|
@if($ac->status == \App\Models\Enums\AircraftStatus::ACTIVE)
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<span class="description"><b>Flight Time</b>
|
<span class="description"><b>Flight Time</b>
|
||||||
{{ Utils::minutesToTimeString($pirep->flight_time) }}
|
@minutestotime($pirep->flight_time)
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
@if($pirep->aircraft)
|
@if($pirep->aircraft)
|
||||||
|
|||||||
@@ -56,7 +56,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Flight Time</td>
|
<td>Flight Time</td>
|
||||||
<td>{{ Utils::minutesToTimeString($pirep->flight_time) }}</td>
|
<td>@minutestotime($pirep->flight_time)</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Flight Level</td>
|
<td>Flight Level</td>
|
||||||
|
|||||||
@@ -104,7 +104,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Flight Time</td>
|
<td>Flight Time</td>
|
||||||
<td>{{ Utils::minutesToTimeString($user->flight_time) }}</td>
|
<td>@minutestotime($user->flight_time)</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>IP Address</td>
|
<td>IP Address</td>
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
<div class="icon-background">
|
<div class="icon-background">
|
||||||
<i class="far fa-clock icon"></i>
|
<i class="far fa-clock icon"></i>
|
||||||
</div>
|
</div>
|
||||||
<h3 class="header">{{ \App\Facades\Utils::minutesToTimeString($user->flight_time, false)}}</h3>
|
<h3 class="header">@minutestotime($user->flight_time), {{$user->flight_time}}</h3>
|
||||||
<h5 class="description">@lang('dashboard.totalhours')</h5>
|
<h5 class="description">@lang('dashboard.totalhours')</h5>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -25,15 +25,15 @@
|
|||||||
<div>
|
<div>
|
||||||
@if($pirep->state === PirepState::PENDING)
|
@if($pirep->state === PirepState::PENDING)
|
||||||
<div class="badge badge-warning">
|
<div class="badge badge-warning">
|
||||||
@elseif($pirep->state === PirepState::ACCEPTED)
|
@elseif($pirep->state === PirepState::ACCEPTED)
|
||||||
<div class="badge badge-success">
|
<div class="badge badge-success">
|
||||||
@elseif($pirep->state === PirepState::REJECTED)
|
@elseif($pirep->state === PirepState::REJECTED)
|
||||||
<div class="badge badge-danger">
|
<div class="badge badge-danger">
|
||||||
@else
|
@else
|
||||||
<div class="badge badge-info">
|
<div class="badge badge-info">
|
||||||
@endif
|
@endif
|
||||||
{{ PirepState::label($pirep->state) }}</div>
|
{{ PirepState::label($pirep->state) }}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-10">
|
<div class="col-sm-10">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@@ -41,7 +41,7 @@
|
|||||||
<table class="table-condensed" width="100%">
|
<table class="table-condensed" width="100%">
|
||||||
<tr>
|
<tr>
|
||||||
<td nowrap><span class="title">@lang('pireps.flighttime') </span></td>
|
<td nowrap><span class="title">@lang('pireps.flighttime') </span></td>
|
||||||
<td>{{ Utils::minutesToTimeString($pirep->flight_time) }}</td>
|
<td>@minutestotime($pirep->flight_time)</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td nowrap><span class="title">@lang('common.aircraft') </span></td>
|
<td nowrap><span class="title">@lang('common.aircraft') </span></td>
|
||||||
|
|||||||
@@ -47,7 +47,7 @@
|
|||||||
<div class="card text-center">
|
<div class="card text-center">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="social-description">
|
<div class="social-description">
|
||||||
<h2>{{ \App\Facades\Utils::minutesToTimeString($user->flight_time, false) }}</h2>
|
<h2>@minutestotime($user->flight_time)</h2>
|
||||||
<p>@lang('flights.flighthours')</p>
|
<p>@lang('flights.flighthours')</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -74,7 +74,7 @@
|
|||||||
<div class="card text-center">
|
<div class="card text-center">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="social-description">
|
<div class="social-description">
|
||||||
<h2>{{ \App\Facades\Utils::minutesToHours($user->transfer_time) }}h</h2>
|
<h2>@minutestohours($user->transfer_time)h</h2>
|
||||||
<p>@lang('profile.transferhours')</p>
|
<p>@lang('profile.transferhours')</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
@endif
|
@endif
|
||||||
</td>
|
</td>
|
||||||
<td align="center">{{ $user->flights }}</td>
|
<td align="center">{{ $user->flights }}</td>
|
||||||
<td align="center">{{ \App\Facades\Utils::minutesToTimeString($user->flight_time) }}</td>
|
<td align="center">@minutestotime($user->flight_time)</td>
|
||||||
</tr>
|
</tr>
|
||||||
@endforeach
|
@endforeach
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Facades\Utils;
|
use App\Support\ICAO;
|
||||||
|
use App\Support\Units\Time;
|
||||||
|
use App\Support\Utils;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
class UtilsTest extends TestCase
|
class UtilsTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testDates()
|
public function testDates()
|
||||||
{
|
{
|
||||||
$carbon = new \Carbon\Carbon('2018-04-28T12:55:40Z');
|
$carbon = new Carbon('2018-04-28T12:55:40Z');
|
||||||
$this->assertNotNull($carbon);
|
$this->assertNotNull($carbon);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -15,46 +18,49 @@ class UtilsTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testSecondsToTimeParts()
|
public function testSecondsToTimeParts()
|
||||||
{
|
{
|
||||||
$t = Utils::secondsToTimeParts(3600);
|
$t = Time::secondsToTimeParts(3600);
|
||||||
$this->assertEquals(['h' => 1, 'm' => 0, 's' => 0], $t);
|
$this->assertEquals(['h' => 1, 'm' => 0, 's' => 0], $t);
|
||||||
|
|
||||||
$t = Utils::secondsToTimeParts(3720);
|
$t = Time::secondsToTimeParts(3720);
|
||||||
$this->assertEquals(['h' => 1, 'm' => 2, 's' => 0], $t);
|
$this->assertEquals(['h' => 1, 'm' => 2, 's' => 0], $t);
|
||||||
|
|
||||||
$t = Utils::secondsToTimeParts(3722);
|
$t = Time::secondsToTimeParts(3722);
|
||||||
$this->assertEquals(['h' => 1, 'm' => 2, 's' => 2], $t);
|
$this->assertEquals(['h' => 1, 'm' => 2, 's' => 2], $t);
|
||||||
|
|
||||||
$t = Utils::secondsToTimeParts(60);
|
$t = Time::secondsToTimeParts(60);
|
||||||
$this->assertEquals(['h' => 0, 'm' => 1, 's' => 0], $t);
|
$this->assertEquals(['h' => 0, 'm' => 1, 's' => 0], $t);
|
||||||
|
|
||||||
$t = Utils::secondsToTimeParts(62);
|
$t = Time::secondsToTimeParts(62);
|
||||||
$this->assertEquals(['h' => 0, 'm' => 1, 's' => 2], $t);
|
$this->assertEquals(['h' => 0, 'm' => 1, 's' => 2], $t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
public function testSecondsToTime()
|
public function testSecondsToTime()
|
||||||
{
|
{
|
||||||
$t = Utils::secondsToTimeString(3600);
|
$t = Time::secondsToTimeString(3600);
|
||||||
$this->assertEquals('1h 0m', $t);
|
$this->assertEquals('1h 0m', $t);
|
||||||
|
|
||||||
$t = Utils::secondsToTimeString(3720);
|
$t = Time::secondsToTimeString(3720);
|
||||||
$this->assertEquals('1h 2m', $t);
|
$this->assertEquals('1h 2m', $t);
|
||||||
|
|
||||||
$t = Utils::secondsToTimeString(3722);
|
$t = Time::secondsToTimeString(3722);
|
||||||
$this->assertEquals('1h 2m', $t);
|
$this->assertEquals('1h 2m', $t);
|
||||||
|
|
||||||
$t = Utils::secondsToTimeString(3722, true);
|
$t = Time::secondsToTimeString(3722, true);
|
||||||
$this->assertEquals('1h 2m 2s', $t);
|
$this->assertEquals('1h 2m 2s', $t);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMinutesToTime()
|
public function testMinutesToTime()
|
||||||
{
|
{
|
||||||
$t = Utils::minutesToTimeParts(65);
|
$t = Time::minutesToTimeParts(65);
|
||||||
$this->assertEquals(['h' => 1, 'm' => 5], $t);
|
$this->assertEquals(['h' => 1, 'm' => 5], $t);
|
||||||
|
|
||||||
$t = Utils::minutesToTimeString(65);
|
$t = Time::minutesToTimeString(65);
|
||||||
$this->assertEquals('1h 5m', $t);
|
$this->assertEquals('1h 5m', $t);
|
||||||
|
|
||||||
$t = Utils::minutesToTimeString(43200);
|
$t = Time::minutesToTimeString(43200);
|
||||||
$this->assertEquals('720h 0m', $t);
|
$this->assertEquals('720h 0m', $t);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,9 +70,12 @@ class UtilsTest extends TestCase
|
|||||||
$this->assertNotNull($api_key);
|
$this->assertNotNull($api_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
public function testHexCode()
|
public function testHexCode()
|
||||||
{
|
{
|
||||||
$hex_code = \App\Support\ICAO::createHexCode();
|
$hex_code = ICAO::createHexCode();
|
||||||
$this->assertNotNull($hex_code);
|
$this->assertNotNull($hex_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,9 +91,9 @@ class UtilsTest extends TestCase
|
|||||||
];
|
];
|
||||||
|
|
||||||
foreach ($tests as $case) {
|
foreach ($tests as $case) {
|
||||||
$this->assertEquals('phpvms.net', \App\Support\Utils::getRootDomain($case));
|
$this->assertEquals('phpvms.net', Utils::getRootDomain($case));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assertEquals('phpvms', \App\Support\Utils::getRootDomain('http://phpvms'));
|
$this->assertEquals('phpvms', Utils::getRootDomain('http://phpvms'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user