Files
opensourcepos/app/Helpers/report_helper.php
Edwin Smith af51e4c735 Clean up work on reports listing view and lang() methods (#3707)
* reworked reports and listing page to handle lang() functions in CI_4

* removed old methods

* update code style

* updated bracket style

---------

Co-authored-by: objecttothis <17935339+objecttothis@users.noreply.github.com>
2024-06-15 17:19:15 +02:00

51 lines
1020 B
PHP

<?php
function get_report_link(string $report_name, string $report_prefix = '', string $lang_key = ''): array
{
$path = 'reports/';
if ($report_prefix !== '')
{
$path .= $report_prefix . '_';
}
/**
* Sanitize the report name in case it has come from the permissions table.
*/
$report_name = str_replace('reports_', '', $report_name);
$path .= $report_name;
if ($lang_key === '')
{
$lang_key = 'Reports.' . $report_name;
}
return [
'path' => site_url($path),
'label' => lang($lang_key),
];
}
/**
* @param string $permission_id
* @param string[] $restrict_views
*
* @return bool
*/
function can_show_report($permission_id, array $restrict_views = []): bool
{
if (strpos($permission_id, 'reports_') === false)
{
return false;
}
foreach ($restrict_views as $restrict_view)
{
if (strpos($permission_id, $restrict_view) !== false)
{
return false;
}
}
return true;
}