Skip to main content

Helper functions

Below is a list of Qore helper functions that can be used in either the back-end and/or front-end. .

Resources

Getting resources:

// Back-end
function resources(): array
function resource(string $name): QoreResource
// Front-end, getting resources from the state
computed: {
...
mapState('globals', {
stateResources: state => state.resources
})
}

Tenants

Getting tenants:

// Back-end
function tenants(): Builder
function tenant(): Tenant
// Front-end, can be used inside components using e.g.: this->$tenants
this->$tenants

Getting the database names:

function get_central_database_name(): string
function get_tenant_database_name(): string

Tenant variables

Retrieving tenant variables:

// Back-end
function tenant_variable(string $name): ?TenantVariable
function tenant_variable_value(string $name, string $content): ?TenantVariableValue

Preferences

Retrieving preferences:

// Back-end
function preference($key, $default = null): mixed
tenant()->getPreference($key, $default) // optional
auth()->user()->getPreference($key, $default) // optional
// Front-end, can be used inside components using e.g.: this->$preference(...)
$preference(key, defaultValue = null)
$tenantPreference(key, defaultValue = null)

Settings

Retrieving settings:

// Back-end
function setting(string $component, string $key, $default = null): mixed
// Front-end, can be used inside components using e.g.: this->$setting(...)
$setting(component, key)

Date formatting

When dealing with dates:

// Back-end
function date_presenter(Carbon $date, bool $applyTimezone = true, bool $asDiffForHumans = false): string
function date_time_presenter(Carbon $date, bool $applyTimezone = true, bool $asDiffForHumans = false): string
function time_presenter(Carbon $time, bool $applyTimezone = true): string
function apply_timezone(Carbon $date): Carbon
function is_date($value): bool
function pref_date_format(): string
function pref_time_format(): string
function pref_date_time_format(): string
// Front-end, can be used inside components using e.g.: this->$formatDate(...)
$formatDate(value, format = null)
$formatDateTime(value, format = null)
$defaultDateFormat()
$defaultDateTimeFormat()
$timeFormat()

Price formatting

The currency code defaults to the preference value (e.g.: EUR).

// Back-end
function format_price(int|float|string $number, ?string $currency_code = null): string
// Front-end, can be used inside components using e.g.: this->$formatPrice(...)
$formatPrice (price, currencyFormat)

Number formatting

To format numbers:

// Back-end
function format_number($number, string $format = 'number_format'): string
// Front-end, can be used inside components using e.g.: this->$formatNumber(...)
$formatNumber(num, type = 'number_format', decimals = 2)

Media

Qore back-end exposes 2 routes that allow downloading & streaming of media files:

Route::get('media/{uuid}/download', [MediaController::class, 'download']);
Route::get('media/{uuid}/stream', [MediaController::class, 'stream']);

In the front-end, you can use these routes once you have the uuid of a file:

// Generating URL to a file:
this.$mediaUrl(file, stream = false) // or: this.$mediaUrl({ id: file.uuid })

// When you have a file or UUID:
this.$downloadMedia(file, name, openInTab = true) // or: this.$downloadMedia({ id: file.uuid })

// When you have a Blob response:
this.$download(blob, fileName = null, openInTab = true)

// Converting data URL to file instance:
this.$dataURLToFile(dataUrl, filename)

Example of displaying a PDF in HTML:

<object 
:data="`${$mediaUrl({ id: pdf }, true)}?#scrollbar=0&toolbar=0&navpanes=0`"
type="application/pdf"
class="rounded-borders"
style="border: 0; width: 100%; min-height: 800px;"
/>

Extensions

Working with modules and plugins:

// Back-end
function modules(): array
function module(string $composerName): QoreModule
function module_is_active(string $composerName): bool
function plugins(): array
function plugin(string $composerName): QorePlugin
function plugin_is_active(string $composerName): bool
function extension(string $composerName): QoreExtension
function boot_extensions(): void
// Front-end, can be used inside components using e.g.: this->$modules
this->$modules
$module(name)
$isModuleActive(name)
this->$plugins
$plugin(name)
$isPluginActive(name)

Misc

Miscellaneous functions:

function enum_array_to_values(array|Arrayable $enums): array