forked from aces/Loris
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[data_release] refactoring to use data framework.
- Loading branch information
lorisadmin
committed
Feb 12, 2024
1 parent
8c8f32d
commit 456ec3a
Showing
3 changed files
with
194 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php declare(strict_types=1); | ||
/** | ||
* This class implements a data Instance which represents a single | ||
* module in the acknowledgements menu table. | ||
* | ||
* PHP Version 7 | ||
* | ||
* @category Core | ||
* @package Main | ||
* @subpackage Core | ||
* @author Dave MacFarlane <[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 ModuleRow represents a row in the acknowledgements menu table. | ||
* | ||
* The acknowledgements requires a specific "row" concept because | ||
* the \Module class does not have any concept of the Active flag | ||
* for the module in order to serialize it as JSON for the data | ||
* table. | ||
* | ||
* @category Core | ||
* @package Main | ||
* @subpackage Core | ||
* @author Dave MacFarlane <[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 HelpRow | ||
* | ||
* @param array $row The row | ||
* @param \CenterID $cid The CenterID | ||
*/ | ||
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; | ||
} | ||
} |