Skip to content

Commit

Permalink
trying to fix lint after adjustements
Browse files Browse the repository at this point in the history
  • Loading branch information
ridz1208 committed Dec 2, 2024
1 parent 3642b3a commit 4602e2d
Show file tree
Hide file tree
Showing 13 changed files with 25,041 additions and 52,555 deletions.
44,962 changes: 24,889 additions & 20,073 deletions modules/biobank/js/biobankIndex.js

Large diffs are not rendered by default.

32,390 changes: 0 additions & 32,390 deletions modules/biobank/js/components/BiobankIndex.js

This file was deleted.

1 change: 0 additions & 1 deletion modules/biobank/js/components/BiobankIndex.js.map

This file was deleted.

6 changes: 3 additions & 3 deletions modules/biobank/jsx/processForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ const SpecimenProcessForm = (props) => {

// ProcessForm.propTypes
SpecimenProcessForm.propTypes = {
edit: PropTypes.bool.isRequired,
edit: PropTypes.bool,
process: PropTypes.shape({
data: PropTypes.object,
protocolId: PropTypes.number,
Expand All @@ -271,7 +271,7 @@ SpecimenProcessForm.propTypes = {
label: PropTypes.string.isRequired,
})
),
units: PropTypes.obj.isRequired,
units: PropTypes.obj,
protocols: PropTypes.arrayOf(PropTypes.string),
processes: PropTypes.arrayOf(PropTypes.string),
protocolAttributes: PropTypes.arrayOf(
Expand Down Expand Up @@ -300,7 +300,7 @@ SpecimenProcessForm.propTypes = {
typeId: PropTypes.string,
}),
}).isRequired,
hideProtocol: PropTypes.bool.isRequired,
hideProtocol: PropTypes.bool,
increaseCoordinate: PropTypes.func.isRequired,
createSpecimens: PropTypes.func.isRequired,
printLabel: PropTypes.func.isRequired,
Expand Down
Binary file added modules/biobank/php/.condition.class.inc.swp
Binary file not shown.
4 changes: 1 addition & 3 deletions modules/biobank/php/barcodes.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ namespace LORIS\biobank;

define('MAX_BARCODES_PER_REQUEST', 1000); // Adjust this value as needed

use Psr\Http\Message\ServerRequestInterface;

/**
* {@inheritDoc}
*
Expand Down Expand Up @@ -85,7 +83,7 @@ class Barcodes extends Endpoint
FROM biobank_container
WHERE SUBSTRING(Barcode, 1, 2) = :year";
$qparams = [':year' => $currentYear];
$maxNumberResult = $this->loris->getDatabaseConnection()
$maxNumberResult = (array) $this->loris->getDatabaseConnection()
->pselectOne($query, $qparams);

$maxNumber = $maxNumberResult['max_number'] ?? 0;
Expand Down
33 changes: 33 additions & 0 deletions modules/biobank/php/condition.class.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php declare(strict_types=1);

namespace LORIS\biobank;

/**
* Condition Class
*
* Defines a Condition object for modifying resource access.
* A Condition represents a filter or restriction applied to resource access
* in a query. It specifies the field to filter, the value to match, the
* comparison operator, and the logical operator for combining multiple conditions.
*
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License
*/
class Condition
{
/**
* Constructs a Condition instance.
*
* @param string $field The field to filter by
* @param ?string $value The value to compare against
* @param ?Operator $operator The comparison operator
* @param ?LogicalOperator $logicalOperator The logical operator for combining
* with other conditions
*/
public function __construct(
public string $field,
public ?string $value,
public ?Operator $operator = Operator::EQUALS,
public ?LogicalOperator $logicalOperator = LogicalOperator::AND,
) {
}
}
52 changes: 50 additions & 2 deletions modules/biobank/php/endpoint.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,54 @@ abstract class Endpoint
*/
abstract protected function getSubHandler(string $subpath): ?Endpoint;

/**
* //TODO: to be moved to a service layer.
* Handles getting multiple resources.
*
* @param QueryParams $params The number of requested barcodes
*
* @return array The data to be returned as JSON
*/
abstract protected function get(QueryParams $params): array;

/**
* //TODO: to be moved to a service layer.
* Shows a specific resource.
*
* @param string $resourceId The resource identifier that is requested
*
* @return array
*/
abstract protected function getOne(string $resourceId): array;

/**
* //TODO: to be moved to a service layer.
* Handles updating a specific resource.
*
* @param array $resource The resource to be updated
*
* @return array
*/
abstract protected function update(string $resource): array;

/**
* //TODO: to be moved to a service layer.
* Handles file upload requests.
*
* @param array $uploadedFiles The files to be uploaded
*
* @return void
*/
abstract protected function upload(array $uploadedFiles): void;

/**
* //TODO: to be moved to a service layer.
* Handles creating a new resource.
*
* @return array
*/
abstract protected function create(): array;

/**
* Defines the allowed HTTP methods for this endpoint.
*
Expand All @@ -77,7 +125,7 @@ abstract class Endpoint
) : void {
if (!$user->hasPermission($this->getPermission($permission))) {
throw new Forbidden(
get_called_class() . ": {$permission->name()} Permission Denied"
get_called_class() . ": {$permission->value} Permission Denied"
);
}
}
Expand All @@ -100,7 +148,7 @@ abstract class Endpoint
// Determine subendpoint handler based on the subpath
if (count($pathparts) > 1) {
$subpath = $pathparts[1];
$subhandler = $this->getSubHandler($pathparts[1]);
$subhandler = $this->getSubHandler($subpath);

if ($subhandler !== null) {
// Remove the handled part of the path and pass the remainder
Expand Down
16 changes: 16 additions & 0 deletions modules/biobank/php/logicaloperator.class.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php declare(strict_types=1);

namespace LORIS\biobank;

/**
* Enum LogicalOperator
*
* Defines the allowed LogicalOperators for chaining query conditions.
*
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License
*/
enum LogicalOperator: string
{
case AND = 'AND';
case OR = 'OR';
}
42 changes: 42 additions & 0 deletions modules/biobank/php/operator.class.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php declare(strict_types=1);

namespace LORIS\biobank;

/**
* Enum Operator
*
* Defines the allowed Operators for accessing resources.
*
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License
*/
enum Operator: string
{
case EQUALS = 'eq'; // Equals
case NOT_EQUALS = 'neq'; // Not equals
case GREATER_THAN = 'gt'; // Greater than
case LESS_THAN = 'lt'; // Less than
case GREATER_THAN_OR_EQUALS = 'gte'; // Greater than or equals
case LESS_THAN_OR_EQUALS = 'lte'; // Less than or equals
case LIKE = 'like'; // Like (pattern match)
case IN = 'in'; // In (value in set)


/**
* Converts the Operator enum value to its corresponding SQL representation.
*
* @return string The SQL operator corresponding to the enum value.
*/
public function toSql(): string
{
return match ($this) {
self::EQUALS => '=',
self::NOT_EQUALS => '!=',
self::GREATER_THAN => '>',
self::LESS_THAN => '<',
self::GREATER_THAN_OR_EQUALS => '>=',
self::LESS_THAN_OR_EQUALS => '<=',
self::LIKE => 'LIKE',
self::IN => 'IN',
};
}
}
13 changes: 0 additions & 13 deletions modules/biobank/php/queryparams.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,6 @@ class QueryParams
return $this;
}

/**
* Sets the group-by clause for the query.
*
* @param string $groupBy The field to group by.
*
* @return self
*/
public function groupBy(string $groupBy): self
{
$this->groupBy = $groupBy;
return $this;
}

/**
* Sets the limit for the query results.
*
Expand Down
65 changes: 1 addition & 64 deletions modules/biobank/php/queryparamshandler.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace LORIS\biobank;
* Class QueryParamsHandler
*
* Handles the parsing of query parameters into a `QueryParams` object.
* This includes parsing fields, conditions, includes, limits, offsets, and
* This includes parsing fields, conditions, limits, offsets, and
* count-only queries from the provided array of query parameters.
*
* @package LORIS
Expand Down Expand Up @@ -44,7 +44,6 @@ final class QueryParamsHandler
$queryParams = new QueryParams();
$queryParams->select(...$this->parseFields())
->where(...$this->parseConditions())
->include(...$this->parseIncludes()) // New include parsingi
->limit($this->parseLimit())
->offset($this->parseOffset())
->count($this->parseCount()); // Handle count
Expand Down Expand Up @@ -72,68 +71,6 @@ final class QueryParamsHandler
[];
}

/**
* Parses the 'include' query parameter for relationships.
*
* @return array The parsed includes as With objects.
*/
protected function parseIncludes(): array
{
$includes = [];

if (isset($this->queryParams['include'])) {
$includes = $this->parseNestedIncludes(
explode(',', $this->queryParams['include'])
);
}

return $includes;
}

/**
* Recursively parses nested includes.
*
* @param array $includes The array of includes to process.
*
* @return array The parsed includes as With objects.
*/
protected function parseNestedIncludes(array $includes): array
{
$result = [];

foreach ($includes as $include) {
$result[] = $this->createWithObject($include);
}

return $result;
}

/**
* Creates a With object representing an included relation.
*
* @param string $include The include string representing the relation.
*
* @return With The With object representing the relation.
*/
protected function createWithObject(string $include): With
{
// Split the include string into parts
$parts = explode('.', $include);
$name = array_shift($parts);

// Recursively build the nested With structure
$subIncludes = [];
if (!empty($parts)) {
$subIncludes[] = $this->createWithObject(implode('.', $parts));
}

// Parse conditions for the include, if any exist (this is a placeholder for
// actual logic)
$conditions = []; // This should be replaced with actual condition parsing

return new With($name, $conditions, $subIncludes);
}

/**
* Parses the 'conditions' query parameter.
*
Expand Down
12 changes: 6 additions & 6 deletions modules/biobank/php/specimendao.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -606,11 +606,11 @@ class SpecimenDAO extends \LORIS\Data\ProvisionerInstance
/**
* Saves the Specimen Project to the database.
*
* @param string $candId - The candidate for which to generate the sample number
* @param int $candId - The candidate for which to generate the sample number
*
* @return string The sample number of the specimen
* @return int The sample number of the specimen
*/
private function _getSampleNumber($candId)
private function _getSampleNumber(int $candId)
{
// Query to get the maximum SampleNumber for the given candidate
$query = "
Expand All @@ -622,7 +622,7 @@ class SpecimenDAO extends \LORIS\Data\ProvisionerInstance

$sampleNumber = $this->db->pselectOneInt($query, ['candId' => $candId]);

return (string) $sampleNumber + 1;
return $sampleNumber + 1;
}

/**
Expand All @@ -646,9 +646,9 @@ class SpecimenDAO extends \LORIS\Data\ProvisionerInstance
'SessionID' => $specimen->getSessionId(),
];

// I'd prefere a better way of doing this, but for now this is the simplest
// I'd prefer a better way of doing this, but for now this is the simplest
// way to ensure that the Sample Number does NOT get updated.
if (!$specimen->getId()) {
if ($specimen->getId() == null) {
$sampleNumber = $this->_getSampleNumber($specimen->getCandidateId());
$specimenData['SampleNumber'] = $sampleNumber;
}
Expand Down

0 comments on commit 4602e2d

Please sign in to comment.