2017-08-04 16:28:16 +02:00
|
|
|
<?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/>.
|
|
|
|
*/
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2018-09-05 15:00:19 +02:00
|
|
|
use Models\Plugin;
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
/**
|
2017-09-21 15:51:39 +02:00
|
|
|
* Classe per la gestione delle informazioni relative ai plugin installati.
|
2017-08-04 16:28:16 +02:00
|
|
|
*
|
|
|
|
* @since 2.3
|
|
|
|
*/
|
|
|
|
class Plugins
|
|
|
|
{
|
2017-08-31 11:32:49 +02:00
|
|
|
/** @var array Elenco dei plugin disponibili */
|
2017-08-04 16:28:16 +02:00
|
|
|
protected static $plugins = [];
|
2018-08-11 15:37:38 +02:00
|
|
|
protected static $references = [];
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
/**
|
2017-09-21 15:51:39 +02:00
|
|
|
* Restituisce tutte le informazioni di tutti i plugin installati.
|
2017-08-04 16:28:16 +02:00
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function getPlugins()
|
|
|
|
{
|
|
|
|
if (empty(self::$plugins)) {
|
|
|
|
$plugins = [];
|
2018-08-11 15:37:38 +02:00
|
|
|
$references = [];
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2018-08-11 15:37:38 +02:00
|
|
|
$modules = Modules::getModules();
|
|
|
|
foreach ($modules as $module) {
|
|
|
|
foreach ($module->plugins as $result) {
|
|
|
|
$plugins[$result['id']] = $result;
|
|
|
|
$references[$result['name']] = $result['id'];
|
|
|
|
}
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
self::$plugins = $plugins;
|
2018-08-11 15:37:38 +02:00
|
|
|
self::$references = $references;
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return self::$plugins;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Restituisce le informazioni relative a un singolo modulo specificato.
|
|
|
|
*
|
2017-09-21 15:51:39 +02:00
|
|
|
* @param string|int $plugin
|
2017-08-04 16:28:16 +02:00
|
|
|
*
|
2018-09-05 10:36:41 +02:00
|
|
|
* @return Plugin
|
2017-08-04 16:28:16 +02:00
|
|
|
*/
|
2017-09-22 15:19:59 +02:00
|
|
|
public static function get($plugin)
|
2017-08-04 16:28:16 +02:00
|
|
|
{
|
2018-08-11 15:37:38 +02:00
|
|
|
$plugins = self::getPlugins();
|
|
|
|
|
|
|
|
if (!is_numeric($plugin) && !empty(self::$references[$plugin])) {
|
2018-08-30 18:20:30 +02:00
|
|
|
$plugin = self::$references[$plugin];
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
2017-09-21 15:51:39 +02:00
|
|
|
|
2018-08-11 15:37:38 +02:00
|
|
|
return $plugins[$plugin];
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
2018-06-26 09:41:43 +02:00
|
|
|
|
2018-09-05 10:36:41 +02:00
|
|
|
/**
|
|
|
|
* Restituisce il modulo attualmente in utilizzo.
|
|
|
|
*
|
|
|
|
* @return Plugin
|
|
|
|
*/
|
|
|
|
public static function getCurrent()
|
|
|
|
{
|
2019-01-02 14:15:16 +01:00
|
|
|
return Plugin::getCurrent();
|
2018-09-05 10:36:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Imposta il modulo attualmente in utilizzo.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
*/
|
|
|
|
public static function setCurrent($id)
|
|
|
|
{
|
|
|
|
Plugin::setCurrent($id);
|
|
|
|
|
|
|
|
// Fix modulo
|
|
|
|
$plugin = self::getCurrent();
|
2018-09-19 10:44:32 +02:00
|
|
|
if (isset($plugin)) {
|
2024-03-22 17:11:27 +01:00
|
|
|
Modules::setCurrent($plugin->module->first()->id);
|
2018-09-19 10:44:32 +02:00
|
|
|
}
|
2018-09-05 10:36:41 +02:00
|
|
|
}
|
|
|
|
|
2018-06-26 09:41:43 +02:00
|
|
|
/**
|
|
|
|
* Individua il percorso per il file.
|
|
|
|
*
|
2018-09-19 10:44:32 +02:00
|
|
|
* @param string|int $element
|
2018-06-26 09:41:43 +02:00
|
|
|
* @param string $file
|
|
|
|
*
|
|
|
|
* @return string|null
|
|
|
|
*/
|
2018-09-19 10:44:32 +02:00
|
|
|
public static function filepath($element, $file)
|
2018-06-26 09:41:43 +02:00
|
|
|
{
|
2018-10-30 16:31:06 +01:00
|
|
|
$element = self::get($element);
|
2018-11-30 16:10:15 +01:00
|
|
|
|
2018-10-30 16:31:06 +01:00
|
|
|
return $element ? $element->filepath($file) : null;
|
2018-06-26 09:41:43 +02:00
|
|
|
}
|
2019-07-05 10:47:45 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Costruisce un link HTML per il modulo e il record indicati.
|
|
|
|
*
|
2020-09-23 13:36:37 +02:00
|
|
|
* @param string|int $plugin
|
|
|
|
* @param int $id_record
|
|
|
|
* @param string $testo
|
|
|
|
* @param bool|string $alternativo
|
|
|
|
* @param string $extra
|
|
|
|
* @param bool $blank
|
2019-07-05 10:47:45 +02:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function link($plugin, $id_record = null, $testo = null, $alternativo = true, $extra = null, $blank = true)
|
|
|
|
{
|
|
|
|
$plugin = self::get($plugin);
|
|
|
|
$alternativo = is_bool($alternativo) && $alternativo ? $testo : $alternativo;
|
|
|
|
|
|
|
|
if (!empty($plugin) && in_array($plugin->permission, ['r', 'rw'])) {
|
|
|
|
$anchor = 'tab_'.$plugin->id;
|
|
|
|
|
2024-04-22 16:15:55 +02:00
|
|
|
return Modules::link($plugin->module->name, $id_record, $testo, $alternativo, $extra, $blank, $anchor);
|
2019-07-05 10:47:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $alternativo;
|
|
|
|
}
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|