openstamanager/lib/helpers.php

301 lines
6.0 KiB
PHP
Raw Normal View History

<?php
2020-09-07 15:04:06 +02:00
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
2021-01-20 15:08:51 +01:00
* Copyright (C) DevCode s.r.l.
2020-09-07 15:04:06 +02:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2020-11-06 10:46:42 +01:00
/*
2018-07-17 12:05:21 +02:00
* Funzioni di aiuto per la semplificazione del codice.
*
* @since 2.4.2
*/
2019-09-11 08:48:37 +02:00
use HTMLBuilder\HTMLBuilder;
2018-07-17 12:05:21 +02:00
/**
* Restituisce l'oggetto dedicato alla gestione della connessione con il database.
*
* @return \Database
*/
function database()
{
return \Database::getConnection();
}
/**
* Prepara il parametro inserito per l'inserimento in una query SQL.
* Attenzione: protezione di base contro SQL Injection.
*
* @param string $parameter
*
* @since 2.3
*
* @return mixed
*/
function prepare($parameter)
{
2022-03-25 18:47:13 +01:00
return database()->prepare((string) $parameter);
}
/**
* Restituisce il contenuto sanitarizzato dell'input dell'utente.
*
* @param string $param Nome del parametro
* @param string $method Posizione del parametro (post o get)
* @param bool $raw Restituire il valore non formattato
*
* @since 2.3
*
* @return string
*/
function filter($param, $method = null, $raw = false)
{
return \Filter::getValue($param, $method, $raw);
}
/**
* Restituisce il contenuto sanitarizzato dell'input dell'utente.
*
* @param string $param Nome del parametro
* @param bool $raw Restituire il valore non formattato
*
* @since 2.3
*
* @return string
*/
function post($param, $raw = false)
{
return \Filter::getValue($param, 'post', $raw);
}
/**
* Restituisce il contenuto sanitarizzato dell'input dell'utente.
*
* @param string $param Nome del parametro
* @param bool $raw Restituire il valore non formattato
*
* @since 2.3
*
* @return string
*/
function get($param, $raw = false)
{
return \Filter::getValue($param, 'get', $raw);
}
/**
* Legge il valore di un'impostazione dalla tabella zz_settings.
*
* @param string $name
2018-07-08 18:11:17 +02:00
* @param bool $again
*
2018-07-19 14:34:52 +02:00
* @since 2.4.2
*
2018-07-08 18:11:17 +02:00
* @return string
*/
2019-01-03 11:04:28 +01:00
function setting($name, $again = false)
{
2019-01-03 11:04:28 +01:00
return \Settings::getValue($name);
}
/**
* Restituisce l'oggetto dedicato alla gestione dei messaggi per l'utente.
*
2018-07-19 14:34:52 +02:00
* @since 2.4.2
*
* @return \Util\Messages
*/
function flash()
{
2018-07-19 17:49:41 +02:00
return App::flash();
}
/**
* Restituisce l'oggetto dedicato alla gestione dell'autenticazione degli utente.
*
2018-07-19 14:34:52 +02:00
* @since 2.4.2
*
* @return \Auth
*/
function auth()
{
return \Auth::getInstance();
}
/**
* Restituisce l'oggetto dedicato alla gestione della traduzione del progetto.
*
2018-07-19 14:34:52 +02:00
* @since 2.4.2
*
* @return \Translator
*/
function trans()
{
return \Translator::getInstance();
}
/**
* Restituisce l'oggetto dedicato alla gestione della conversione di numeri e date.
*
2018-07-19 14:34:52 +02:00
* @since 2.4.2
*
* @return \Intl\Formatter
*/
function formatter()
{
return \Translator::getFormatter();
}
/**
* Restituisce la traduzione del messaggio inserito.
*
* @param string $string
* @param array $parameters
* @param string $operations
*
* @since 2.3
*
* @return string
*/
function tr($string, $parameters = [], $operations = [])
{
return \Translator::translate($string, $parameters, $operations);
}
// Retrocompatibilità (con la funzione gettext)
if (!function_exists('_')) {
function _($string, $parameters = [], $operations = [])
{
return tr($string, $parameters, $operations);
}
}
2018-07-19 14:34:52 +02:00
/**
* Restituisce l'oggetto dedicato alla gestione dei log.
*
* @since 2.4.2
*
* @return \Monolog\Logger
*/
function logger()
{
return Monolog\Registry::getInstance('logs');
}
2019-02-22 10:37:37 +01:00
/**
* Restituisce il numero indicato formattato secondo la configurazione del sistema.
*
* @param float $number
* @param int $decimals
*
* @return string
*
* @since 2.4.8
*/
function numberFormat($number, $decimals = null)
2019-02-22 10:37:37 +01:00
{
return Translator::numberToLocale($number, $decimals);
}
/**
* Restituisce il timestamp indicato formattato secondo la configurazione del sistema.
*
* @param string $timestamp
+ *
* @return string
*
* @since 2.4.8
*/
function timestampFormat($timestamp)
{
return Translator::timestampToLocale($timestamp);
}
/**
* Restituisce la data indicata formattato secondo la configurazione del sistema.
*
* @param string $date
*
* @return string
*
* @since 2.4.8
*/
function dateFormat($date)
{
return Translator::dateToLocale($date);
}
/**
* Restituisce l'orario indicato formattato secondo la configurazione del sistema.
*
* @param string $time
*
* @return string
*
* @since 2.4.8
*/
function timeFormat($time)
{
return Translator::timeToLocale($time);
}
/**
* Restituisce il simbolo della valuta del gestione.
*
* @since 2.4.9
*
* @return string
*/
function currency()
{
return \Translator::getCurrency();
}
/**
* Restituisce il numero indicato formattato come una valuta secondo la configurazione del sistema.
*
* @param string $time
*
* @return string
*
* @since 2.4.9
*/
function moneyFormat($number, $decimals = null)
{
2023-08-04 14:54:28 +02:00
if (setting('Posizione del simbolo valuta') == 'Prima') {
return tr('_CURRENCY_ _TOTAL_', [
'_CURRENCY_' => currency(),
'_TOTAL_' => numberFormat($number, $decimals),
]);
} else {
return tr('_TOTAL_ _CURRENCY_', [
'_TOTAL_' => numberFormat($number, $decimals),
'_CURRENCY_' => currency(),
]);
}
}
2019-09-11 08:48:37 +02:00
/**
* Restituisce il numero indicato formattato come una valuta secondo la configurazione del sistema.
*
* @return string
*
* @since 2.4.11
*/
function input(array $json)
{
return HTMLBuilder::parse($json);
}