Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[data_release] refactoring to use data framework. #9051

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 59 additions & 51 deletions modules/data_release/php/data_release.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
*
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -247,6 +198,63 @@ 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;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be mistaken, but this documentation comment does not seem to coincide with the documentation of the base method, no ? It seems to me that returning null means the provisionner does not support the HasAnyPermissionOrUserSiteMatch filter.

Other than that LGTM.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @maximemulder, thank you for the review. Very appreciated.

This is what I found in the declaration of the method.
image

The data release docs are not site tied. That's way I'm returning null in the implementation. The page don't use site filtering.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it will be more accurate to specify this in the documentation of the implementation itself: That this page don't use site filtering ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be more accurate, or you could use the {@inheritDoc} annotation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it will be more accurate to specify this in the documentation of the implementation itself: That this page don't use site filtering ?

Sorry for the wait, but yes, just like Dave said, specifying either that or inheriting the parent documentation should do the job.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, somehow this escaped to my attention. Should be fixed now. Thank you.


/**
* {@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
*
Expand Down
76 changes: 76 additions & 0 deletions modules/data_release/php/datareleaseprovisioner.class.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php declare(strict_types=1);
/**
* 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 <[email protected]>
* @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 <[email protected]>
* @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);
}
}
51 changes: 51 additions & 0 deletions modules/data_release/php/datareleaserow.class.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php declare(strict_types=1);
/**
* This class implements a data Instance which represents a single
* entry in the data_release menu table.
*
* PHP Version 7
*
* @category Core
* @package Main
* @subpackage Core
* @author Rolando Acosta <[email protected]>
* @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 <[email protected]>
* @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;
}
}
Loading