Fix name class dashboards
This commit is contained in:
@@ -56,7 +56,7 @@ class G
|
||||
'ldapadvanced' => LdapAdvanced::class,
|
||||
'dashletopenvscompleted' => DashletOpenVsCompleted::class,
|
||||
'dashletrssreader' => DashletRssReader::class,
|
||||
'dashletprocesspakerenterprise' => DashletProcessMakerEnterprise::class,
|
||||
'dashletprocessmakerenterprise' => DashletProcessMakerEnterprise::class,
|
||||
'dashletprocessmakercommunity' => DashletProcessMakerCommunity::class,
|
||||
];
|
||||
|
||||
@@ -5883,7 +5883,8 @@ class G
|
||||
/**
|
||||
* Instanciate an adapter by name.
|
||||
*
|
||||
* @param string $name Adapter name or class name
|
||||
* @param string $name Adapter name or class name :P
|
||||
*
|
||||
* @param string[] $parameters Constructor parameters
|
||||
*/
|
||||
public static function factory($name, ...$parameters)
|
||||
@@ -5893,4 +5894,29 @@ class G
|
||||
$rc = new ReflectionClass($class);
|
||||
return $rc->newInstanceArgs($parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return current class
|
||||
*
|
||||
* @param $name string name class
|
||||
* @return string name of class
|
||||
*/
|
||||
public static function nameClass($name)
|
||||
{
|
||||
$key = strtolower($name);
|
||||
return isset(self::$adapters[$key]) ? self::$adapters[$key] : $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify class exists
|
||||
*
|
||||
* @param $name
|
||||
* @return bool true or false
|
||||
*/
|
||||
public static function classExists($name)
|
||||
{
|
||||
$key = strtolower($name);
|
||||
$class = isset(self::$adapters[$key]) ? self::$adapters[$key] : $name;
|
||||
return class_exists($class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,13 +12,71 @@ class PmDashlet extends DashletInstance implements DashletInterface
|
||||
|
||||
// Interface functions
|
||||
|
||||
/**
|
||||
* verify if file exists or no, return the path of file.
|
||||
*
|
||||
* @param $name file
|
||||
* @param string $type CORE or PLUGIN
|
||||
* @return stdClass information of file
|
||||
*/
|
||||
private function verifyExistsFile($name, $type = 'CORE')
|
||||
{
|
||||
$response = new stdClass();
|
||||
$response->exists = false;
|
||||
$response->path = '';
|
||||
$response->plugin = '';
|
||||
$response->className = $name;
|
||||
|
||||
//Compatibility with old files
|
||||
$paths = [
|
||||
'classes' . PATH_SEP . $name . '.php',
|
||||
'classes' . PATH_SEP . ucfirst($name) . '.php',
|
||||
'classes' . PATH_SEP . 'class.' . $name . '.php'
|
||||
];
|
||||
|
||||
switch ($type) {
|
||||
case 'CORE':
|
||||
foreach ($paths as $key => $path) {
|
||||
if (file_exists(PATH_CORE . $path)) {
|
||||
$response->exists = true;
|
||||
$response->path = PATH_CORE . $path;
|
||||
$response->className = $key == 1 ? ucfirst($name) : $name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'PLUGIN':
|
||||
foreach (self::getIncludePath() as $plugin => $pathPlugin) {
|
||||
foreach ($paths as $key => $path) {
|
||||
if (file_exists($pathPlugin . $path)) {
|
||||
$response->exists = true;
|
||||
$response->path = $pathPlugin . $path;
|
||||
$response->className = $key == 1 ? ucfirst($name) : $name;
|
||||
$response->plugin = $plugin;
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
public static function getAdditionalFields($className)
|
||||
{
|
||||
try {
|
||||
if (! class_exists( $className )) {
|
||||
self::setIncludePath();
|
||||
require_once 'classes' . PATH_SEP . 'class.' . $className . '.php';
|
||||
if (!G::classExists($className)) {
|
||||
$file = self::verifyExistsFile($className, 'PLUGIN');
|
||||
if ($file->exists) {
|
||||
$className = $file->className;
|
||||
require_once $file->path;
|
||||
}
|
||||
} else {
|
||||
$className = G::nameClass($className);
|
||||
}
|
||||
eval("\$additionalFields = $className::getAdditionalFields(\$className);");
|
||||
return $additionalFields;
|
||||
@@ -37,9 +95,12 @@ class PmDashlet extends DashletInstance implements DashletInterface
|
||||
}
|
||||
$className = $this->dashletInstance['DAS_CLASS'];
|
||||
|
||||
if (! class_exists( $className )) {
|
||||
self::setIncludePath();
|
||||
require_once 'classes' . PATH_SEP . 'class.' . $className . '.php';
|
||||
if (!G::classExists($className)) {
|
||||
$file = self::verifyExistsFile($className, 'PLUGIN');
|
||||
if ($file->exists) {
|
||||
$className = $file->className;
|
||||
require_once $file->path;
|
||||
}
|
||||
}
|
||||
$this->dashletObject = new $className();
|
||||
$this->dashletObject->setup($this->dashletInstance);
|
||||
@@ -100,10 +161,12 @@ class PmDashlet extends DashletInstance implements DashletInterface
|
||||
}
|
||||
$row['DAS_INS_STATUS_LABEL'] = ($row['DAS_INS_STATUS'] == '1' ? G::LoadTranslation('ID_ACTIVE') : G::LoadTranslation('ID_INACTIVE'));
|
||||
$row['DAS_INS_TITLE'] = (isset($arrayField['DAS_INS_TITLE']) && !empty($arrayField['DAS_INS_TITLE'])) ? $arrayField['DAS_INS_TITLE'] : '';
|
||||
if (! class_exists( $row['DAS_CLASS'] )) {
|
||||
self::setIncludePath();
|
||||
@include 'classes' . PATH_SEP . 'class.' . $row['DAS_CLASS'] . '.php';
|
||||
if (! class_exists( $row['DAS_CLASS'] )) {
|
||||
if (!G::classExists($row['DAS_CLASS'])) {
|
||||
$file = self::verifyExistsFile($row['DAS_CLASS'], 'PLUGIN');
|
||||
if ($file->exists) {
|
||||
$row['DAS_CLASS'] = $file->className;
|
||||
require_once $file->path;
|
||||
} else {
|
||||
$dataset->next();
|
||||
continue;
|
||||
}
|
||||
@@ -115,7 +178,6 @@ class PmDashlet extends DashletInstance implements DashletInterface
|
||||
$row['DAS_INS_OWNER_TITLE'] = G::LoadTranslation('ID_ALL_USERS');
|
||||
break;
|
||||
case 'USER':
|
||||
require_once 'classes/model/Users.php';
|
||||
$userInstance = new Users();
|
||||
try {
|
||||
$user = $userInstance->load($row['DAS_INS_OWNER_UID']);
|
||||
@@ -126,7 +188,6 @@ class PmDashlet extends DashletInstance implements DashletInterface
|
||||
}
|
||||
break;
|
||||
case 'DEPARTMENT':
|
||||
require_once 'classes/model/Department.php';
|
||||
$departmentInstance = new Department();
|
||||
try {
|
||||
$department = $departmentInstance->load($row['DAS_INS_OWNER_UID']);
|
||||
@@ -137,7 +198,6 @@ class PmDashlet extends DashletInstance implements DashletInterface
|
||||
}
|
||||
break;
|
||||
case 'GROUP':
|
||||
require_once 'classes/model/Groupwf.php';
|
||||
$groupInstance = new Groupwf();
|
||||
try {
|
||||
$group = $groupInstance->load($row['DAS_INS_OWNER_UID']);
|
||||
@@ -201,9 +261,6 @@ class PmDashlet extends DashletInstance implements DashletInterface
|
||||
{
|
||||
try {
|
||||
$dashletsInstances = array();
|
||||
// Include required classes
|
||||
require_once 'classes/model/Department.php';
|
||||
require_once 'classes/model/Users.php';
|
||||
// Check for "public" dashlets
|
||||
$criteria = new Criteria('workflow');
|
||||
$criteria->addSelectColumn(DashletInstancePeer::DAS_INS_UID);
|
||||
@@ -333,12 +390,24 @@ class PmDashlet extends DashletInstance implements DashletInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get template for class
|
||||
*
|
||||
* @param $className string name of file
|
||||
* @return mixed string template dashboard
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function getXTemplate($className)
|
||||
{
|
||||
try {
|
||||
if (! class_exists( $className )) {
|
||||
self::setIncludePath();
|
||||
require_once 'classes' . PATH_SEP . 'class.' . $className . '.php';
|
||||
if (!G::classExists($className)) {
|
||||
$file = self::verifyExistsFile($className, 'PLUGIN');
|
||||
if ($file->exists) {
|
||||
$className = $file->className;
|
||||
require_once $file->path;
|
||||
}
|
||||
} else {
|
||||
$className = G::nameClass($className);
|
||||
}
|
||||
|
||||
eval("\$additionalFields = $className::getXTemplate(\$className);");
|
||||
@@ -350,53 +419,40 @@ class PmDashlet extends DashletInstance implements DashletInterface
|
||||
|
||||
public static function verifyPluginDashlet($className)
|
||||
{
|
||||
// 1-- if name class is in core
|
||||
$fileExist = PATH_CORE . 'classes' . PATH_SEP . 'class.' . $className . '.php';
|
||||
if (file_exists($fileExist)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 2-- if name class is in plugin
|
||||
|
||||
//---- verify the name plugin of the class
|
||||
$pluginName = '';
|
||||
$oPluginRegistry = PluginRegistry::loadSingleton();
|
||||
$pluginsDashlets = $oPluginRegistry->getDashlets();
|
||||
|
||||
foreach ($pluginsDashlets as $pluginDashlet) {
|
||||
$fileExist = PATH_PLUGINS . $pluginDashlet . PATH_SEP . 'classes' . PATH_SEP . 'class.' . $className . '.php';
|
||||
if (file_exists($fileExist)) {
|
||||
$pluginName = $pluginDashlet;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//---- verify if the plugin is active
|
||||
if ($pluginName == '') {
|
||||
return false;
|
||||
$fileExists = false;
|
||||
if (G::classExists($className)) {
|
||||
$fileExists = true;
|
||||
} else {
|
||||
// 2-- if name class is in plugin
|
||||
$file = self::verifyExistsFile($className, 'PLUGIN');
|
||||
if ($file->exists && !empty($file->plugin)) {
|
||||
//---- verify if the plugin is active
|
||||
if ($handle = opendir(PATH_PLUGINS)) {
|
||||
while (false !== ($file = readdir( $handle ))) {
|
||||
if (strpos( $file, '.php', 1 ) && is_file( PATH_PLUGINS . $file )) {
|
||||
include_once (PATH_PLUGINS . $file);
|
||||
$pluginDetail = $oPluginRegistry->getPluginDetails( $file );
|
||||
if ($pluginDetail->getNamespace() == $pluginName) {
|
||||
return $pluginDetail->isEnabled();
|
||||
$oPluginRegistry = PluginRegistry::loadSingleton();
|
||||
while (false !== ($filePlugin = readdir($handle))) {
|
||||
if (strpos($filePlugin, '.php', 1) && is_file(PATH_PLUGINS . $filePlugin)) {
|
||||
include_once(PATH_PLUGINS . $filePlugin);
|
||||
$pluginDetail = $oPluginRegistry->getPluginDetails($filePlugin);
|
||||
if ($pluginDetail->getNamespace() == $file->plugin) {
|
||||
$fileExists = $pluginDetail->isEnabled();
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private static function setIncludePath ()
|
||||
private static function getIncludePath()
|
||||
{
|
||||
$oPluginRegistry = PluginRegistry::loadSingleton();
|
||||
$pluginsDashlets = $oPluginRegistry->getDashlets();
|
||||
$paths = [];
|
||||
foreach ($pluginsDashlets as $pluginDashlet) {
|
||||
set_include_path( get_include_path() . PATH_SEPARATOR . PATH_PLUGINS . $pluginDashlet . PATH_SEP );
|
||||
}
|
||||
$paths[$pluginDashlet] = PATH_PLUGINS . $pluginDashlet . PATH_SEP;
|
||||
}
|
||||
return $paths;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user