From 15f9762d018239d01888bf6f4c3af12431f5c1ff Mon Sep 17 00:00:00 2001 From: Paolo Date: Fri, 4 Mar 2022 12:26:37 +0100 Subject: [PATCH] - Fixed errors/violations noticed by PHPMD and PHPCS - Removed parameter perform_sql from public method controllers/system/extensions/CLI_Manager->installExtension - Added new public method controllers/system/extensions/CLI_Manager->installExtensionNoSQL - Improved code quality in controllers/system/extensions/Manager->toggleExtension - controllers/system/extensions/Manager->uploadExtension better check of HTTP POST parameter notPerformSql - application/views/system/extensions/manager.php renamed checkbox performSql to notPerformSql - application/views/system/extensions/tableWidget.php removed PHP close tag at the end of the file - Improved code quality in application/widgets/TableWidget.php - Removed private method _getColumnsNames from application/widgets/TableWidget.php - Improved code quality in application/libraries/ExtensionsLib.php - Added new private methods _getExtensionsPath and _getUploadPath to application/libraries/ExtensionsLib.php - Changed application/libraries/ExtensionsLib->_toggleExtension to public method toggleExtension - Removed private properties UPLOAD_PATH and EXTENSIONS_PATH from application/libraries/ExtensionsLib - Added use imports in application/libraries/ExtensionsLib - application/libraries/ExtensionsLib->installExtension changed parameters default values --- .../system/extensions/CLI_Manager.php | 12 +- .../controllers/system/extensions/Manager.php | 33 +- application/libraries/ExtensionsLib.php | 328 +++++++++--------- .../views/system/extensions/manager.php | 4 +- .../views/system/extensions/tableWidget.php | 3 +- application/widgets/TableWidget.php | 95 +++-- 6 files changed, 235 insertions(+), 240 deletions(-) diff --git a/application/controllers/system/extensions/CLI_Manager.php b/application/controllers/system/extensions/CLI_Manager.php index fab511d09..b5288cbae 100644 --- a/application/controllers/system/extensions/CLI_Manager.php +++ b/application/controllers/system/extensions/CLI_Manager.php @@ -30,9 +30,17 @@ class CLI_Manager extends CLI_Controller * @param $filename Url Encoded Pfad zum tgz File der Extension * @param $perform_sql boolean ob die SQL Befehle ausgeführt werden */ - public function installExtension($extensionName, $filename, $perform_sql = true) + public function installExtension($extensionName, $filename) { - $this->extensionslib->installExtension($extensionName, urldecode($filename), $perform_sql); + $this->extensionslib->installExtension($extensionName, urldecode($filename), true); + } + + /** + * Install an extension, same as installExtension but without running the SQL statements + */ + public function installExtensionNoSQL($extensionName, $filename) + { + $this->extensionslib->installExtension($extensionName, urldecode($filename), false); } } diff --git a/application/controllers/system/extensions/Manager.php b/application/controllers/system/extensions/Manager.php index 571b283e8..62fa70806 100644 --- a/application/controllers/system/extensions/Manager.php +++ b/application/controllers/system/extensions/Manager.php @@ -31,10 +31,10 @@ class Manager extends Auth_Controller $this->load->library('ExtensionsLib'); $this->loadPhrases( - array( - 'extensions' - ) - ); + array( + 'extensions' + ) + ); } /** @@ -54,21 +54,16 @@ class Manager extends Auth_Controller */ public function toggleExtension() { - $toggleExtension = false; - $extension_id = $this->input->post('extension_id'); $enabled = $this->input->post('enabled'); - if ($enabled === true) - { - $toggleExtension = $this->extensionslib->enableExtension($extension_id); - } - else - { - $toggleExtension = $this->extensionslib->disableExtension($extension_id); - } + // Clean the parameter + if ($enabled !== true) $enable = false; - $this->outputJsonSuccess($toggleExtension); + // Output the enable/disable of the extension + $this->outputJsonSuccess( + $this->extensionslib->toggleExtension($extension_id, $enable) + ); } /** @@ -94,9 +89,13 @@ class Manager extends Auth_Controller */ public function uploadExtension() { - $performSql = $this->input->post('performSql'); + $notPerformSql = $this->input->post('notPerformSql'); - $this->extensionslib->installExtension(null, null, $performSql); + // It converts the notPerformSql parameter from the checkbox value to a boolean one + if ($notPerformSql == 'on') $notPerformSql = true; + if ($notPerformSql !== true) $notPerformSql = false; + + $this->extensionslib->installExtension(null, null, !$notPerformSql); } } diff --git a/application/libraries/ExtensionsLib.php b/application/libraries/ExtensionsLib.php index 39a83931b..6f1ef0869 100644 --- a/application/libraries/ExtensionsLib.php +++ b/application/libraries/ExtensionsLib.php @@ -2,6 +2,9 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); +use \stdClass as stdClass; +use \PharData as PharData; + /** * Library to manage core extensions */ @@ -15,11 +18,18 @@ class ExtensionsLib const EXTENSION_JSON_NAME = 'extension.json'; // file that contains extension data const EXTENSIONS_DIR_NAME = 'extensions'; // name of the directories where will be created the symlinks - private $_ci; + const UPLOAD_PATH = 'tmp/'; - private $ARCHIVE_EXTENSIONS = array('.tgz', '.tbz2'); // accepted file extensions for an uploaded extension - private $UPLOAD_PATH; // temporary directory to store the upload file and checks the archive - private $EXTENSIONS_PATH; // directory where all the extensions are + private $_ci; // Code igniter instance + + private $_errorOccurred; // boolean, true if an error occurred while installing an extension + private $_currentInstalledExtensionVersion; // contains the version of the current installation of an extension + + // NOTE: the following have been declared as properties to maintain compatibility with previous PHP versions + // where arrays cannot be declared as constants + + // Accepted file extensions for an uploaded extension + private $ARCHIVE_EXTENSIONS = array('.tgz', '.tbz2'); // Directories that are part of the extension archive private $SOFTLINK_TARGET_DIRECTORIES = array( @@ -27,17 +37,11 @@ class ExtensionsLib DOC_ROOT => array('public') ); - private $_errorOccurred; // boolean, true if an error occurred while installing an extension - private $_currentInstalledExtensionVersion; // contains the version of the current installation of an extension - /** * Class constructor */ public function __construct() { - $this->UPLOAD_PATH = APPPATH.'tmp/'; - $this->EXTENSIONS_PATH = APPPATH.'extensions/'; - // Get code igniter instance $this->_ci =& get_instance(); @@ -72,20 +76,20 @@ class ExtensionsLib * @param $extensionName string Name of Extension (optional) * @param $filename Path to tgz Extension File (optional) */ - public function installExtension($extensionName = null, $filename = null, $perform_sql = true) + public function installExtension($extensionName, $filename, $perform_sql) { $extensionDB = null; // contains data from DB about an extension $extensionJson = null; // contains the extension.json data $this->_printInfo('WARNING!!! Please do not change page or stop this procedure before it is finished'); - if (!is_null($extensionName) && !is_null($filename)) - { - $uploadData = new stdClass(); - $uploadData->fullPath = $filename; - $uploadData->extensionName = $extensionName; - } - else + // Create an object with the given paramenters + $uploadData = new stdClass(); + $uploadData->fullPath = $filename; + $uploadData->extensionName = $extensionName; + + // If no extension name or file name are provided + if (is_null($extensionName) || is_null($filename)) { $this->_loadUploadLibrary(); // loads CI upload library $uploadData = $this->_uploadExtension(); // perform the upload of the file and returns info about it @@ -98,7 +102,8 @@ class ExtensionsLib $uploadData = null; // then it is a wrong one! } - if ($uploadData != null) // if no error occurred + // If the no error occurred + if ($uploadData != null) { $this->_extractExtension($uploadData->fullPath); // extract the archive of the uploaded extension @@ -128,13 +133,14 @@ class ExtensionsLib // Remove any previous installation from file system and database $this->_cleanPreviousInstallation($extensionJson); - $this->_installExtension($extensionJson); // records extension data in DB + // Records extension data in DB + $this->_installExtension($extensionJson); if (!$this->_errorOccurred && $perform_sql === true) // if no error occurred { - // Loads and executes neede SQL scripts + // Loads and executes needed SQL scripts $this->_loadSQLs( - $this->UPLOAD_PATH.$extensionJson->name.'/'.ExtensionsLib::SQL_DIRECTORY, + $this->_getUploadPath().$extensionJson->name.DIRECTORY_SEPARATOR.ExtensionsLib::SQL_DIRECTORY, $extensionJson ); } @@ -151,14 +157,6 @@ class ExtensionsLib $this->_createSymLinks($extensionJson->name); } } - else - { - $this->_errorOccurred = true; - } - } - else - { - $this->_errorOccurred = true; } if ($this->_errorOccurred === false) // if no errors occurred @@ -193,16 +191,21 @@ class ExtensionsLib if (getData($result)[0]->server_kurzbz != SERVER_NAME) return false; $extensionName = getData($result)[0]->name; // extension name - $this->_delSoftLinks($extensionName); // not to be checked, could fail if the extension is disabled - // remove the extension from the extensions installation directory - $delExtension = $this->_rrm($this->EXTENSIONS_PATH.$extensionName); + + // Not to be checked, could fail if the extension is disabled + $this->_delSoftLinks($extensionName); + + // Remove the extension from the extensions installation directory + $delExtension = $this->_rrm($this->_getExtensionsPath().$extensionName); // Select all the version of this extension $this->_ci->ExtensionsModel->addSelect('extension_id'); $result = $this->_ci->ExtensionsModel->loadWhere(array('name' => $extensionName, 'server_kurzbz' => SERVER_NAME)); - if (hasData($result)) // if something was found + + // If something was found + if (hasData($result)) { - foreach (getData($result) as $key => $extension) // loops on them + foreach (getData($result) as $extension) // loops on them { // Remove them all $result = $this->_ci->ExtensionsModel->delete($extension->extension_id); @@ -230,19 +233,49 @@ class ExtensionsLib } /** - * To enable an extension + * To enable/disable an extension */ - public function enableExtension($extensionId) + public function toggleExtension($extensionId, $enabled) { - return $this->_toggleExtension($extensionId, true); - } + $_toggleExtension = false; - /** - * To disable an extension - */ - public function disableExtension($extensionId) - { - return $this->_toggleExtension($extensionId, false); + // Loads data from DB about the given extension + $result = $this->_ci->ExtensionsModel->load($extensionId); + if (hasData($result)) + { + // If this server is _not_ the same where the extension was installed then exit with a failure + if (getData($result)[0]->server_kurzbz != SERVER_NAME) return false; + + $extensionName = getData($result)[0]->name; // extension name + + // If to be enabled + if ($enabled === true) + { + // Add the symlinks + $_toggleExtension = $this->_addSoftLinks($extensionName); + } + else // If to be disabled + { + // Remove all the symlinks + $_toggleExtension = $this->_delSoftLinks($extensionName); + } + + if ($_toggleExtension) // if is a success + { + // Updates DB + $result = $this->_ci->ExtensionsModel->update($extensionId, array('enabled' => $enabled)); + if (isSuccess($result)) + { + $_toggleExtension = true; + } + else // if DB update fails remove symlinks from file system + { + $this->_delSoftLinks($extensionName); + } + } + } + + return $_toggleExtension; } // ------------------------------------------------------------------------------------------------- @@ -256,7 +289,7 @@ class ExtensionsLib $this->_ci->load->library( 'upload', array( - 'upload_path' => $this->UPLOAD_PATH, + 'upload_path' => $this->_getUploadPath(), 'allowed_types' => '*', 'overwrite' => true ) @@ -320,7 +353,7 @@ class ExtensionsLib // Extracts the uploaded file $pd = new PharData($uploadPath); - $pd->extractTo($this->UPLOAD_PATH, null, true); + $pd->extractTo($this->_getUploadPath(), null, true); } catch (UnexpectedValueException $uva) { @@ -375,18 +408,14 @@ class ExtensionsLib $this->_errorOccurred = true; $this->_printFailure('data base error: '.getData($result)); } - else // otherwise + elseif (hasData($result)) { - if (hasData($result)) // if found - { - $extensionDB = getData($result)[0]; // return it! - } - else - { - $this->_printMessage('not found'); - } + $extensionDB = getData($result)[0]; } + // If no data have been found + if ($extensionDB == null) $this->_printMessage('not found'); + $this->_printSuccess(!$this->_errorOccurred); $this->_printEnd(); @@ -402,10 +431,10 @@ class ExtensionsLib $this->_printStart('Checking extension file system structure'); // Checks if the root directory of this archive has the same name of the extension - if (is_dir($this->UPLOAD_PATH.$extensionName)) + if (is_dir($this->_getUploadPath().$extensionName)) { // Checks if file extension.json exists inside the uploaded archive - if (!file_exists($this->UPLOAD_PATH.$extensionName.'/'.ExtensionsLib::EXTENSION_JSON_NAME)) + if (!file_exists($this->_getUploadPath().$extensionName.DIRECTORY_SEPARATOR.ExtensionsLib::EXTENSION_JSON_NAME)) { $this->_errorOccurred = true; $this->_printFailure('missing extension.json'); @@ -427,11 +456,14 @@ class ExtensionsLib */ private function _chkExtensionJson($extensionName, $extensionDB) { + // Set a default FHComplete version + $fhcomplete_version = 0; + $this->_printStart('Parsing and checking extension.json'); // Decodes extension.json $extensionJson = json_decode( - file_get_contents($this->UPLOAD_PATH.$extensionName.'/'.ExtensionsLib::EXTENSION_JSON_NAME) + file_get_contents($this->_getUploadPath().$extensionName.DIRECTORY_SEPARATOR.ExtensionsLib::EXTENSION_JSON_NAME) ); // Checks if the parameter name of the extension.json has the same value of the extension name @@ -634,8 +666,11 @@ class ExtensionsLib // Loops through the versions for ($sqlDir = $startVersion; $sqlDir <= $extensionJson->version; $sqlDir++) { + // Gets all the SQL files in the directory having the same name of the version + $files = glob($pkgSQLsPath.DIRECTORY_SEPARATOR.$sqlDir.'/*'.ExtensionsLib::SQL_FILE_EXTENSION); + // If a directory with the same value of the version is present in the sql scripts directory - if (($files = glob($pkgSQLsPath.'/'.$sqlDir.'/*'.ExtensionsLib::SQL_FILE_EXTENSION)) != false) + if ($files != false) { // Loads every sql files foreach ($files as $file) @@ -646,7 +681,10 @@ class ExtensionsLib $this->_printMessage($sql); // Try to execute that - if (!isSuccess($result = @$this->_ci->ExtensionsModel->executeQuery($sql))) + $result = @$this->_ci->ExtensionsModel->executeQuery($sql); + + // If was not a success + if (!isSuccess($result)) { $this->_errorOccurred = true; $this->_printFailure(' error occurred while executing the query'); @@ -660,7 +698,7 @@ class ExtensionsLib $this->_ci->eprintflib->printEOL(); } } - } + } } $this->_printSuccess(!$this->_errorOccurred); @@ -675,12 +713,12 @@ class ExtensionsLib { $this->_printStart('Moving the upload extension from upload folder to extension folder'); - $this->_printMessage('Current extension directory: '.$this->UPLOAD_PATH.$extensionName); - $this->_printMessage('Directory where it will be moved: '.$this->EXTENSIONS_PATH.$extensionName); + $this->_printMessage('Current extension directory: '.$this->_getUploadPath().$extensionName); + $this->_printMessage('Directory where it will be moved: '.$this->_getExtensionsPath().$extensionName); - if (!file_exists($this->EXTENSIONS_PATH.$extensionName)) + if (!file_exists($this->_getExtensionsPath().$extensionName)) { - if (rename($this->UPLOAD_PATH.$extensionName.'/', $this->EXTENSIONS_PATH.$extensionName)) + if (rename($this->_getUploadPath().$extensionName.DIRECTORY_SEPARATOR, $this->_getExtensionsPath().$extensionName)) { $this->_printSuccess(true); } @@ -722,13 +760,21 @@ class ExtensionsLib { $_delSoftLinks = false; + // For every set of target directories where: + // rootPath: is the prefix of the absolute path for the target directory + // targetDirectories: is an array of target directories foreach ($this->SOFTLINK_TARGET_DIRECTORIES as $rootPath => $targetDirectories) { - foreach ($targetDirectories as $key => $targetDirectory) + // For every target directory in the current set + foreach ($targetDirectories as $targetDirectory) { - if (file_exists($rootPath.$targetDirectory.'/'.ExtensionsLib::EXTENSIONS_DIR_NAME.'/'.$extensionName)) + // If the symlink exists + if (file_exists($rootPath.$targetDirectory.DIRECTORY_SEPARATOR.ExtensionsLib::EXTENSIONS_DIR_NAME.DIRECTORY_SEPARATOR.$extensionName)) { - $_delSoftLinks = unlink($rootPath.$targetDirectory.'/'.ExtensionsLib::EXTENSIONS_DIR_NAME.'/'.$extensionName); + // Try to delete it + $_delSoftLinks = unlink( + $rootPath.$targetDirectory.DIRECTORY_SEPARATOR.ExtensionsLib::EXTENSIONS_DIR_NAME.DIRECTORY_SEPARATOR.$extensionName + ); } } } @@ -741,29 +787,23 @@ class ExtensionsLib */ private function _rrm($dir) { - if (!file_exists($dir)) + // If the directory does not exist return success + if (!file_exists($dir)) return true; + + // If it is not a directory then delete it and return the result + if (!is_dir($dir)) return unlink($dir); + + // For each subdirectory + foreach (scandir($dir) as $subdir) { - return true; - } - - if (!is_dir($dir)) - { - return unlink($dir); - } - - foreach (scandir($dir) as $item) - { - if ($item == '.' || $item == '..') - { - continue; - } - - if (!$this->_rrm($dir.DIRECTORY_SEPARATOR.$item)) - { - return false; - } + // If it is the same directory or the parent directory skip to the next one + if ($subdir == '.' || $subdir == '..') continue; + + // Try to remove a subdirectory, if it fails then return a failure + if (!$this->_rrm($dir.DIRECTORY_SEPARATOR.$subdir)) return false; } + // Delete the directory and return the result return rmdir($dir); } @@ -773,42 +813,41 @@ class ExtensionsLib private function _addSoftLinks($extensionName) { $_addSoftLinks = false; - $extensionPath = $this->EXTENSIONS_PATH.$extensionName.'/'; + $extensionPath = $this->_getExtensionsPath().$extensionName.DIRECTORY_SEPARATOR; - // For every target directory + // For every set of target directories where: + // rootPath: is the prefix of the absolute path for the target directory + // targetDirectories: is an array of target directories foreach ($this->SOFTLINK_TARGET_DIRECTORIES as $rootPath => $targetDirectories) { - foreach ($targetDirectories as $key => $targetDirectory) + // For every target directory in the current set + foreach ($targetDirectories as $targetDirectory) { - // If destination of the symlink does not exist - if (!file_exists($rootPath.$targetDirectory.'/'.ExtensionsLib::EXTENSIONS_DIR_NAME.'/'.$extensionName)) + // Checks if the link already exists + $_addSoftLinks = file_exists( + $rootPath.$targetDirectory.DIRECTORY_SEPARATOR.ExtensionsLib::EXTENSIONS_DIR_NAME.DIRECTORY_SEPARATOR.$extensionName + ); + + // If the symlink does not exist + if (!$_addSoftLinks) { - // If the target directory does not exist than creates that - if (!is_dir($extensionPath.$targetDirectory)) - { - mkdir($extensionPath.$targetDirectory); - } + // If the target directory does not exist than creates it + if (!is_dir($extensionPath.$targetDirectory)) mkdir($extensionPath.$targetDirectory); - if (!file_exists($rootPath.$targetDirectory.'/'.ExtensionsLib::EXTENSIONS_DIR_NAME.'/'.$extensionName)) - { - // Create the symlink - $_addSoftLinks = symlink( - $extensionPath.$targetDirectory, - $rootPath.$targetDirectory.'/'.ExtensionsLib::EXTENSIONS_DIR_NAME.'/'.$extensionName - ); - }else - { - $_addSoftLinks = true; - } + // Create the symlink + $_addSoftLinks = @symlink( + // Target + $extensionPath.$targetDirectory, + // Link + $rootPath.$targetDirectory.DIRECTORY_SEPARATOR.ExtensionsLib::EXTENSIONS_DIR_NAME.DIRECTORY_SEPARATOR.$extensionName + ); + // On failure if (!$_addSoftLinks) { log_message('error', 'Failed to create Symlink to '.$extensionPath.$targetDirectory); break; } - }else - { - $_addSoftLinks = true; } } } @@ -833,9 +872,9 @@ class ExtensionsLib $this->_printMessage('Removing the extracted data from the upload directory'); if ($uploadData != null && isset($uploadData->extensionName) - && file_exists($this->UPLOAD_PATH.$uploadData->extensionName)) + && file_exists($this->_getUploadPath().$uploadData->extensionName)) { - $this->_rrm($this->UPLOAD_PATH.$uploadData->extensionName); + $this->_rrm($this->_getUploadPath().$uploadData->extensionName); } // If the upload of the file is a success and the extension name is present and no previous installation were found @@ -852,13 +891,10 @@ class ExtensionsLib $this->delExtension(getData($result)[0]->extension_id); } } - else // otherwise + // Otherwise remove them all only from DB + elseif ($extensionJson != null && isset($extensionJson->extension_id)) { - // Remove them all only from DB - if ($extensionJson != null && isset($extensionJson->extension_id)) - { - $this->_ci->ExtensionsModel->delete($extensionJson->extension_id); - } + $this->_ci->ExtensionsModel->delete($extensionJson->extension_id); } $this->_printMessage('Rollback finished'); @@ -867,49 +903,19 @@ class ExtensionsLib } /** - * To enable/disable an extension + * Returns the absolute upload path */ - private function _toggleExtension($extensionId, $enabled) + private function _getUploadPath() { - $_toggleExtension = false; + return APPPATH.self::UPLOAD_PATH; + } - // Loads data from DB about the given extension - $result = $this->_ci->ExtensionsModel->load($extensionId); - if (hasData($result)) - { - // If this server is _not_ the same where the extension was installed then exit with a failure - if (getData($result)[0]->server_kurzbz != SERVER_NAME) return false; - - $extensionName = getData($result)[0]->name; // extension name - - // If to be enabled - if ($enabled === true) - { - // Add the symlinks - $_toggleExtension = $this->_addSoftLinks($extensionName); - } - else // If to be disabled - { - // Remove all the symlinks - $_toggleExtension = $this->_delSoftLinks($extensionName); - } - - if ($_toggleExtension) // if is a success - { - // Updates DB - $result = $this->_ci->ExtensionsModel->update($extensionId, array('enabled' => $enabled)); - if (isSuccess($result)) - { - $_toggleExtension = true; - } - else // if DB update fails remove symlinks from file system - { - $this->_delSoftLinks($extensionName); - } - } - } - - return $_toggleExtension; + /** + * Returns the absolute extensions path + */ + private function _getExtensionsPath() + { + return APPPATH.self::EXTENSIONS_DIR_NAME.DIRECTORY_SEPARATOR; } /** diff --git a/application/views/system/extensions/manager.php b/application/views/system/extensions/manager.php index 43b61267f..e3116fcdb 100644 --- a/application/views/system/extensions/manager.php +++ b/application/views/system/extensions/manager.php @@ -52,10 +52,10 @@
- +
- +
diff --git a/application/views/system/extensions/tableWidget.php b/application/views/system/extensions/tableWidget.php index d2b6fe1aa..e9885bb68 100644 --- a/application/views/system/extensions/tableWidget.php +++ b/application/views/system/extensions/tableWidget.php @@ -32,7 +32,7 @@ 'Dependencies', 'Enabled' ), - 'formatRow' => function($datasetRaw) { + 'formatRow' => function ($datasetRaw) { if ($datasetRaw->{'description'} == null) { @@ -91,5 +91,4 @@ ); echo $this->widgetlib->widget('TableWidget', $tableWidgetArray); -?> diff --git a/application/widgets/TableWidget.php b/application/widgets/TableWidget.php index a0d452747..fca074f0b 100644 --- a/application/widgets/TableWidget.php +++ b/application/widgets/TableWidget.php @@ -213,51 +213,49 @@ class TableWidget extends Widget */ private function _checkParameters($args) { - // If no options are given to this widget... + // If no options are given to this widget then ends the execution if (!is_array($args) || (is_array($args) && count($args) == 0)) { show_error('Second parameter of the widget call must be a NOT empty associative array'); } - else // ...otherwise + + // The unique id parameter is mandatory + if (!isset($args[TableWidgetLib::TABLE_UNIQUE_ID])) { - // The unique id parameter is mandatory - if (!isset($args[TableWidgetLib::TABLE_UNIQUE_ID])) - { - show_error('The parameter "'.TableWidgetLib::TABLE_UNIQUE_ID.'" must be specified'); - } + show_error('The parameter "'.TableWidgetLib::TABLE_UNIQUE_ID.'" must be specified'); + } - // The query parameter is mandatory - if (!isset($args[TableWidgetLib::QUERY])) - { - show_error('The parameter "'.TableWidgetLib::QUERY.'" must be specified'); - } + // The query parameter is mandatory + if (!isset($args[TableWidgetLib::QUERY])) + { + show_error('The parameter "'.TableWidgetLib::QUERY.'" must be specified'); + } - // The dataset representation parameter is mandatory - if (!isset($args[TableWidgetLib::DATASET_REPRESENTATION])) - { - show_error('The parameter "'.TableWidgetLib::DATASET_REPRESENTATION.'" must be specified'); - } + // The dataset representation parameter is mandatory + if (!isset($args[TableWidgetLib::DATASET_REPRESENTATION])) + { + show_error('The parameter "'.TableWidgetLib::DATASET_REPRESENTATION.'" must be specified'); + } - // Checks if the dataset representation parameter is valid - if (isset($args[TableWidgetLib::DATASET_REPRESENTATION]) - && $args[TableWidgetLib::DATASET_REPRESENTATION] != TableWidgetLib::DATASET_REP_TABLESORTER - && $args[TableWidgetLib::DATASET_REPRESENTATION] != TableWidgetLib::DATASET_REP_PIVOTUI - && $args[TableWidgetLib::DATASET_REPRESENTATION] != TableWidgetLib::DATASET_REP_TABULATOR) - { - show_error( - 'The parameter "'.TableWidgetLib::DATASET_REPRESENTATION. - '" must be IN ("' - .TableWidgetLib::DATASET_REP_TABLESORTER.'", "' - .TableWidgetLib::DATASET_REP_PIVOTUI.'", "' - .TableWidgetLib::DATASET_REP_TABULATOR.'")' - ); - } + // Checks if the dataset representation parameter is valid + if (isset($args[TableWidgetLib::DATASET_REPRESENTATION]) + && $args[TableWidgetLib::DATASET_REPRESENTATION] != TableWidgetLib::DATASET_REP_TABLESORTER + && $args[TableWidgetLib::DATASET_REPRESENTATION] != TableWidgetLib::DATASET_REP_PIVOTUI + && $args[TableWidgetLib::DATASET_REPRESENTATION] != TableWidgetLib::DATASET_REP_TABULATOR) + { + show_error( + 'The parameter "'.TableWidgetLib::DATASET_REPRESENTATION. + '" must be IN ("' + .TableWidgetLib::DATASET_REP_TABLESORTER.'", "' + .TableWidgetLib::DATASET_REP_PIVOTUI.'", "' + .TableWidgetLib::DATASET_REP_TABULATOR.'")' + ); + } - // If given the session timeout parameter must be a number - if (isset($args[TableWidgetLib::SESSION_TIMEOUT]) && !is_numeric($args[TableWidgetLib::SESSION_TIMEOUT])) - { - show_error('The parameter "'.TableWidgetLib::SESSION_TIMEOUT.'" must be a number'); - } + // If given the session timeout parameter must be a number + if (isset($args[TableWidgetLib::SESSION_TIMEOUT]) && !is_numeric($args[TableWidgetLib::SESSION_TIMEOUT])) + { + show_error('The parameter "'.TableWidgetLib::SESSION_TIMEOUT.'" must be a number'); } } @@ -330,8 +328,10 @@ class TableWidget extends Widget TableWidgetLib::SESSION_DATASET => $dataset->retval, // the entire dataset TableWidgetLib::SESSION_DATASET_RELOAD => false, // if the dataset must be reloaded, not needed the first time TableWidgetLib::SESSION_DATASET_REPRESENTATION => $this->_datasetRepresentation, // the choosen dataset representation - TableWidgetLib::SESSION_DATASET_REP_OPTIONS => $this->_datasetRepresentationOptions, // the choosen dataset representation options - TableWidgetLib::SESSION_DATASET_REP_FIELDS_DEFS => $this->_datasetRepFieldsDefs // the choosen dataset representation record fields definition + // The choosen dataset representation options + TableWidgetLib::SESSION_DATASET_REP_OPTIONS => $this->_datasetRepresentationOptions, + // The choosen dataset representation record fields definition + TableWidgetLib::SESSION_DATASET_REP_FIELDS_DEFS => $this->_datasetRepFieldsDefs ) ); } @@ -424,24 +424,6 @@ class TableWidget extends Widget return !isset($class) ? '' : $class; } - /** - * Utility method that retrieves the name of the columns present in a table JSON definition - */ - private function _getColumnsNames($columns) - { - $columnsNames = array(); - - foreach ($columns as $key => $obj) - { - if (isset($obj->name)) - { - $columnsNames[] = $obj->name; - } - } - - return $columnsNames; - } - /** * Loads a view using the given viewName and eventually other parameters */ @@ -451,3 +433,4 @@ class TableWidget extends Widget $ci->load->view($viewName, $parameters); } } +