Skip to content

Commit

Permalink
Add new helpers (nabeelio#1790)
Browse files Browse the repository at this point in the history
* Add new helpers

* check_module : Allows checking installed modules/addons and returns either true or false according to their existence and activeness
* decode_days : Allows decoding days of flights, when building schedule list pages

* StyleCI fixes

* StyleCI Fix 2
  • Loading branch information
FatihKoz authored Mar 27, 2024
1 parent 6db9759 commit d774ffe
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions app/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Contracts\View\Factory;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Cache;
use Nwidart\Modules\Facades\Module;

/*
* array_key_first only exists in PHP 7.3+
Expand Down Expand Up @@ -425,3 +426,41 @@ function docs_link($key)
return config('phpvms.docs.root').config('phpvms.docs.'.$key);
}
}

if (!function_exists('check_module')) {
/**
* Check if a module is installed and active
*
* @param string $module_name
*
* @return bool
*/
function check_module($module_name)
{
$phpvms_module = Module::find($module_name);

return filled($phpvms_module) ? $phpvms_module->isEnabled() : false;
}
}

if (!function_exists('decode_days')) {
/**
* Decode days of flights for schedule display
*
* @param int $flight_days
*
* @return string Monday, Tuesday, Friday, Sunday
*/
function decode_days($flight_days)
{
$days = [];

for ($i = 0; $i < 7; $i++) {
if ($flight_days & pow(2, $i)) {
$days[] = jddayofweek($i, 1);
}
}

return implode(', ', $days);
}
}

0 comments on commit d774ffe

Please sign in to comment.