From 5af50f0b69e26160c113fb4e45fc2a0dab51a179 Mon Sep 17 00:00:00 2001 From: lorisadmin Date: Mon, 12 Feb 2024 22:41:08 +0000 Subject: [PATCH 1/3] [data_release] refactoring to use data framework. --- .../data_release/php/data_release.class.inc | 112 ++++++++++-------- .../php/datareleaseprovisioner.class.inc | 76 ++++++++++++ .../data_release/php/datareleaserow.class.inc | 52 ++++++++ 3 files changed, 189 insertions(+), 51 deletions(-) create mode 100644 modules/data_release/php/datareleaseprovisioner.class.inc create mode 100644 modules/data_release/php/datareleaserow.class.inc diff --git a/modules/data_release/php/data_release.class.inc b/modules/data_release/php/data_release.class.inc index 4234b671416..83b974dc1a3 100644 --- a/modules/data_release/php/data_release.class.inc +++ b/modules/data_release/php/data_release.class.inc @@ -24,7 +24,7 @@ namespace LORIS\data_release; * @link https://www.github.com/aces/Loris */ -class Data_Release extends \NDB_Menu_Filter +class Data_Release extends \DataFrameworkMenu { public $AjaxModule = true; public $skipTemplate = true; @@ -48,55 +48,6 @@ class Data_Release extends \NDB_Menu_Filter ); } - /** - * Setup all the class variables needed for the data release menu page - * - * @return void - */ - function _setupVariables() - { - $user =& \User::singleton(); - $DB = $this->loris->getDatabaseConnection(); - - // set the class variables - $this->columns = [ - 'file_name AS fileName', - 'IF(version is null or version ="","Unversioned", version) AS version', - 'upload_date AS uploadDate', - 'dr.id as dataReleaseID', - ]; - $this->query = " FROM data_release dr"; - - if (!$user->hasPermission("superuser")) { - $this->query .= " JOIN data_release_permissions drp - ON (dr.id=drp.data_release_id) - JOIN users u ON (u.ID=drp.userid) - WHERE u.UserID=".$DB->quote($user->getUsername()); - } - - $this->group_by = ''; - $this->order_by = 'uploadDate'; - } - - /** - * Create the form for the data release menu page - * - * @return void - **/ - function setup() - { - parent::setup(); - - $db = $this->loris->getDatabaseConnection(); - - $this->fieldOptions = [ - 'users' => $this->getUsersList($db), - 'versions' => $this->getVersionsList($db), - 'filenames' => $this->getFilesList($db), - ]; - } - - /** * Greps the list of users available in the users database table. * @@ -143,7 +94,7 @@ class Data_Release extends \NDB_Menu_Filter * @param \Database $DB database handle * * @return array $versionList Array of version names indexed by version - * name. + * name. */ function getVersionsList(\Database $DB) { @@ -247,6 +198,65 @@ class Data_Release extends \NDB_Menu_Filter return $userFiles; } + /** + * Function getFieldOptions + * + * @return array + */ + protected function getFieldOptions() : array + { + $db = $this->loris->getDatabaseConnection(); + return [ + 'users' => $this->getUsersList($db), + 'versions' => $this->getVersionsList($db), + 'filenames' => $this->getFilesList($db), + ]; + } + + /** + * Tells the base class that this page's provisioner can support + * the UserSiteMatch filter. + * + * @return bool always false + */ + public function useSiteFilter() : bool + { + return false; + } + + /** + * Tells the base class that this page's provisioner can support the + * HasAnyPermissionOrUserSiteMatch filter. + * + * @return ?array of site permissions or null + * + */ + public function allSitePermissionNames() : ?array + { + return null; + } + + /** + * {@inheritDoc} + * + * @return bool + * + */ + public function useProjectFilter() : bool + { + return false; + } + + /** + * {@inheritDoc} + * + * @return \Loris\Data\Provisioner + */ + public function getBaseDataProvisioner(): \LORIS\Data\Provisioner + { + return new DataReleaseProvisioner(); + } + /** * Include the column formatter * diff --git a/modules/data_release/php/datareleaseprovisioner.class.inc b/modules/data_release/php/datareleaseprovisioner.class.inc new file mode 100644 index 00000000000..4e51f2a3d11 --- /dev/null +++ b/modules/data_release/php/datareleaseprovisioner.class.inc @@ -0,0 +1,76 @@ + + * @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3 + * @link https://www.github.com/aces/Loris/ + */ + +namespace LORIS\data_release; + +/** + * This class implements a data provisioner to get all data released files + * for the data_release menu page. + * + * PHP Version 7 + * + * @category Core + * @package Main + * @subpackage Core + * @author Rolando Acosta + * @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3 + * @link https://www.github.com/aces/Loris/ + */ + +class DataReleaseProvisioner extends \LORIS\Data\Provisioners\DBRowProvisioner +{ + /** + * Create a DataReleaseProvisioner, which gets releases for the + * data release menu table. + */ + function __construct() + { + $user =& \User::singleton(); + $query = " + SELECT + file_name AS fileName, + IF(version is null or version ='','Unversioned', version) AS version, + upload_date AS uploadDate, + dr.id as dataReleaseID + FROM data_release dr"; + + if (!$user->hasPermission("superuser")) { + $query.= " + INNER JOIN + data_release_permissions drp + ON + (dr.id=drp.data_release_id) + WHERE + drp.UserID=".$user->getID(); + } + + $query.= " ORDER BY uploadDate"; + + parent::__construct( $query, []); + } + + /** + * Returns an instance of a DataReleaseRow object for a given + * table row. + * + * @param array $row The database row from the LORIS Database class. + * + * @return \LORIS\Data\DataInstance An instance representing this row. + */ + public function getInstance($row) : \LORIS\Data\DataInstance + { + return new DataReleaseRow($row); + } +} diff --git a/modules/data_release/php/datareleaserow.class.inc b/modules/data_release/php/datareleaserow.class.inc new file mode 100644 index 00000000000..1e0aae55e25 --- /dev/null +++ b/modules/data_release/php/datareleaserow.class.inc @@ -0,0 +1,52 @@ + + * @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3 + * @link https://www.github.com/aces/Loris/ + */ + +namespace LORIS\data_release; + +/** + * A DataReleaseRow represents a row in the data_release menu table. + * + * @category Core + * @package Main + * @subpackage Core + * @author Rolando Acosta + * @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3 + * @link https://www.github.com/aces/Loris/ + */ +class DataReleaseRow implements \LORIS\Data\DataInstance +{ + protected $DBRow; + + /** + * Create a new DataReleaseRow + * + * @param array $row The row + * + */ + public function __construct(array $row) + { + $this->DBRow = $row; + } + + /** + * Implements \LORIS\Data\DataInstance interface for this row. + * + * @return array which can be serialized by json_encode() + */ + public function jsonSerialize() : array + { + return $this->DBRow; + } +} From aaee2ec0b25dba0cce12446c48a9c7ebb047e8ee Mon Sep 17 00:00:00 2001 From: lorisadmin Date: Tue, 13 Feb 2024 14:34:54 +0000 Subject: [PATCH 2/3] fixing format. --- modules/data_release/php/data_release.class.inc | 2 -- .../data_release/php/datareleaseprovisioner.class.inc | 10 +++++----- modules/data_release/php/datareleaserow.class.inc | 1 - 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/modules/data_release/php/data_release.class.inc b/modules/data_release/php/data_release.class.inc index 83b974dc1a3..ef45ba0d30c 100644 --- a/modules/data_release/php/data_release.class.inc +++ b/modules/data_release/php/data_release.class.inc @@ -229,7 +229,6 @@ class Data_Release extends \DataFrameworkMenu * HasAnyPermissionOrUserSiteMatch filter. * * @return ?array of site permissions or null - * */ public function allSitePermissionNames() : ?array { @@ -240,7 +239,6 @@ class Data_Release extends \DataFrameworkMenu * {@inheritDoc} * * @return bool - * */ public function useProjectFilter() : bool { diff --git a/modules/data_release/php/datareleaseprovisioner.class.inc b/modules/data_release/php/datareleaseprovisioner.class.inc index 4e51f2a3d11..73939c2c7bf 100644 --- a/modules/data_release/php/datareleaseprovisioner.class.inc +++ b/modules/data_release/php/datareleaseprovisioner.class.inc @@ -37,7 +37,7 @@ class DataReleaseProvisioner extends \LORIS\Data\Provisioners\DBRowProvisioner */ function __construct() { - $user =& \User::singleton(); + $user =& \User::singleton(); $query = " SELECT file_name AS fileName, @@ -47,7 +47,7 @@ class DataReleaseProvisioner extends \LORIS\Data\Provisioners\DBRowProvisioner FROM data_release dr"; if (!$user->hasPermission("superuser")) { - $query.= " + $query .= " INNER JOIN data_release_permissions drp ON @@ -56,10 +56,10 @@ class DataReleaseProvisioner extends \LORIS\Data\Provisioners\DBRowProvisioner drp.UserID=".$user->getID(); } - $query.= " ORDER BY uploadDate"; + $query .= " ORDER BY uploadDate"; - parent::__construct( $query, []); - } + parent::__construct($query, []); + } /** * Returns an instance of a DataReleaseRow object for a given diff --git a/modules/data_release/php/datareleaserow.class.inc b/modules/data_release/php/datareleaserow.class.inc index 1e0aae55e25..f1ec2d5c702 100644 --- a/modules/data_release/php/datareleaserow.class.inc +++ b/modules/data_release/php/datareleaserow.class.inc @@ -33,7 +33,6 @@ class DataReleaseRow implements \LORIS\Data\DataInstance * Create a new DataReleaseRow * * @param array $row The row - * */ public function __construct(array $row) { From 2d9fdaa2f38862199c9611b579be9269ab09201a Mon Sep 17 00:00:00 2001 From: racostas <37309344+racostas@users.noreply.github.com> Date: Tue, 12 Mar 2024 09:56:40 -0400 Subject: [PATCH 3/3] Update data_release.class.inc fixes method documentation. --- modules/data_release/php/data_release.class.inc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/data_release/php/data_release.class.inc b/modules/data_release/php/data_release.class.inc index ef45ba0d30c..63bb7ec4f8c 100644 --- a/modules/data_release/php/data_release.class.inc +++ b/modules/data_release/php/data_release.class.inc @@ -225,8 +225,7 @@ class Data_Release extends \DataFrameworkMenu } /** - * Tells the base class that this page's provisioner can support the - * HasAnyPermissionOrUserSiteMatch filter. + * {@inheritDoc} * * @return ?array of site permissions or null */