Skip to content

Commit

Permalink
Update with latest changes to swagger schema
Browse files Browse the repository at this point in the history
  • Loading branch information
driusan committed Dec 16, 2022
1 parent abeb634 commit 0b5d507
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 36 deletions.
11 changes: 3 additions & 8 deletions modules/dataquery/php/provisioners/recentqueries.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ class RecentQueries extends \LORIS\Data\Provisioners\DBRowProvisioner
function __construct(protected \LORIS\LorisInstance $loris, \User $user)
{
parent::__construct(
"SELECT dq.QueryID, RunTime, Query,
IF(dpq.QueryID IS NULL, 'Unstarred', 'Starred') as Starred,
IF(dsq.QueryID IS NULL, 'Unshared', 'Shared') as Shared,
name.Name
"SELECT drq.RunID, dq.QueryID, RunTime, Query
FROM dataquery_queries dq
JOIN dataquery_run_queries drq ON (dq.QueryID=drq.QueryID)
LEFT JOIN dataquery_starred_queries_rel dpq ON
Expand All @@ -35,7 +32,7 @@ class RecentQueries extends \LORIS\Data\Provisioners\DBRowProvisioner
(dq.QueryID=dsq.QueryID AND dsq.SharedBy=:userid)
LEFT JOIN dataquery_query_names name ON
(dq.QueryID=name.QueryID AND name.UserID=:userid)
WHERE drq.UserID=:userid
WHERE drq.UserID=:userid AND drq.RunID IS NOT NULL
ORDER BY drq.RunTime DESC",
['userid' => $user->getId()]
);
Expand All @@ -56,10 +53,8 @@ class RecentQueries extends \LORIS\Data\Provisioners\DBRowProvisioner
loris: $this->loris,
queryID: intval($row['QueryID']),
query: json_decode($row['Query'], true),
name: $row['Name'] ?? '',
starred: $row['Starred'] === 'Starred',
shared: $row['Shared'] === 'Shared',
),
RunID: intval($row['RunID']),
runTime: $row['RunTime'],
);
return $qr;
Expand Down
32 changes: 21 additions & 11 deletions modules/dataquery/php/queries.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,11 @@ class Queries extends \NDB_Page
return new \LORIS\Http\Response\JSON\OK(
[
'recent' => iterator_to_array(
$this->getRecentQueries($user),
$this->getRecentRuns($user),
false,
),
'shared' => iterator_to_array(
$this->getSharedQueries($user),
false,
),
'topqueries' => iterator_to_array(
$this->getTopQueries($user),
false,
'queries' => iterator_to_array(
$this->getUserAccessibleQueries($user),
),
]
);
Expand Down Expand Up @@ -129,13 +124,28 @@ class Queries extends \NDB_Page
*
* @return \Traversable
*/
public function getRecentQueries(\User $user) : iterable
public function getUserAccessibleQueries(\User $user) : iterable
{
return (new provisioners\RecentQueries($this->loris, $user))
//->filter(new AccessibleResourceFilter())
return (new provisioners\AllUserQueries($this->loris, $user))
// ->filter(new AccessibleResourceFilter())
->execute($user);
}


/**
* Get a list of recent query runs for this user
*
* @param \User $user The user getting the queries.
*
* @return \Traversable
*/
public function getRecentRuns(\User $user) : iterable
{
return (new provisioners\RecentQueries($this->loris, $user))
//->filter(new AccessibleResourceFilter())
->execute($user);
}

/**
* Get a list of shared queries for this user
*
Expand Down
31 changes: 15 additions & 16 deletions modules/dataquery/php/query.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ class Query implements \LORIS\StudyEntities\AccessibleResource,
\LORIS\Data\DataInstance
{
protected $data;
public readonly string $name;
protected $sharedBy;

/**
* Construct a Query object
*
Expand All @@ -49,10 +46,10 @@ class Query implements \LORIS\StudyEntities\AccessibleResource,
protected \LORIS\LorisInstance $loris,
public readonly int $queryID,
?array $query=null,
?string $name=null,
?array $sharedBy=null,
protected readonly ?string $name=null,
protected ?string $adminname=null,
protected ?array $sharedBy=null,
protected ?bool $starred=null,
protected ?bool $shared=null
) {
if ($query !== null) {
$this->data = $query;
Expand All @@ -71,13 +68,6 @@ class Query implements \LORIS\StudyEntities\AccessibleResource,
}
$this->data = json_decode($data, true);
}

if ($name !== null) {
$this->name = $name;
}
if ($sharedBy !== null) {
$this->sharedBy = $sharedBy;
}
}

/**
Expand Down Expand Up @@ -735,22 +725,31 @@ class Query implements \LORIS\StudyEntities\AccessibleResource,
*/
public function jsonSerialize() : mixed
{
$factory = \NDB_Factory::singleton();
$result = [
'self' => $factory->settings()->getBaseURL() . '/dataquery/queries/' . $this->queryID,
'QueryID' => $this->queryID,
'Query' => $this->data,
];
if ($this->name !== null && $this->name !== '') {
$result['Name'] = $this->name;
}
if ($this->adminname !== null && $this->adminname !== '') {
$result['AdminName'] = $this->adminname;
$result['Pinned'] = true;
} else {
$result['Pinned'] = false;
}

if ($this->sharedBy !== null) {
$result['SharedBy'] = $this->sharedBy;
$result['Public'] = true;
} else {
$result['Public'] = false;
}
if ($this->starred !== null) {
$result['Starred'] = $this->starred;
}
if ($this->shared !== null) {
$result['Shared'] = $this->shared;
}
return $result;
}
}
8 changes: 7 additions & 1 deletion modules/dataquery/php/queryrun.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,15 @@ class QueryRun implements \LORIS\StudyEntities\AccessibleResource,
*/
public function jsonSerialize() : mixed
{
$factory = \NDB_Factory::singleton();
$baseURL = $factory->settings()->getBaseURL();
$result = [
'self' => $baseURL
. '/dataquery/queries/' . $this->query->queryID . '/run/' . $this->runID,
'Query' => $this->query->queryID,
'RunTime' => $this->runTime,
'Query' => $this->query,
'QueryID' => $this->query->queryID,
'QueryRunID' => $this->runID,
];
return $result;
}
Expand Down

0 comments on commit 0b5d507

Please sign in to comment.