-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using the new abstract database table storage class in dkan_datastore… (
#243) * Using the new abstract database table storage class in dkan_datastore database table storage class. * Fixing complexity issues. * Fix tests. * Fix cypress tests.
- Loading branch information
1 parent
88dcbb2
commit ab415d3
Showing
8 changed files
with
222 additions
and
174 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"uuid": "c9e2d352-e24c-4051-9158-f48127aa5692", | ||
"properties" : [ | ||
"record_number", | ||
"lon", | ||
"lat", | ||
"unit_type", | ||
|
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
54 changes: 54 additions & 0 deletions
54
modules/custom/dkan_common/src/Storage/QueryToQueryHelperTrait.php
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,54 @@ | ||
<?php | ||
|
||
namespace Drupal\dkan_common\Storage; | ||
|
||
use Drupal\Core\Database\Query\Select; | ||
use Drupal\dkan_datastore\Storage\Query; | ||
|
||
/** | ||
* Class QueryToQueryHelperTrait. | ||
* | ||
* Given a Query object, setup a Drupal's select query. | ||
*/ | ||
trait QueryToQueryHelperTrait { | ||
|
||
/** | ||
* Private. | ||
*/ | ||
private function setQueryConditions(Select $db_query, Query $query) { | ||
foreach ($query->conditions as $property => $value) { | ||
$db_query->condition($property, $value, "LIKE"); | ||
} | ||
} | ||
|
||
/** | ||
* Private. | ||
*/ | ||
private function setQueryOrderBy(Select $db_query, Query $query) { | ||
foreach ($query->sort['ASC'] as $property) { | ||
$db_query->orderBy($property); | ||
} | ||
|
||
foreach ($query->sort['DESC'] as $property) { | ||
$db_query->orderBy($property, 'DESC'); | ||
} | ||
} | ||
|
||
/** | ||
* Private. | ||
*/ | ||
private function setQueryLimitAndOffset(Select $db_query, Query $query) { | ||
if ($query->limit) { | ||
if ($query->offset) { | ||
$db_query->range($query->offset, $query->limit); | ||
} | ||
else { | ||
$db_query->range(0, $query->limit); | ||
} | ||
} | ||
elseif ($query->offset) { | ||
$db_query->range($query->limit); | ||
} | ||
} | ||
|
||
} |
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
Oops, something went wrong.