Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GBIF
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Res Telæ
GBIF
Commits
6340839b
Commit
6340839b
authored
Nov 19, 2021
by
Felip Manyer i Ballester
Browse files
Options
Downloads
Patches
Plain Diff
Fixed integration with VBO
parent
89b05513
Branches
Branches containing commit
Tags
2.0.1-alpha2
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/gbif2_views/src/Plugin/views/query/GbifOccurrence.php
+47
-2
47 additions, 2 deletions
...les/gbif2_views/src/Plugin/views/query/GbifOccurrence.php
modules/gbif2_views/src/Service/GbifVboViewsData.php
+1
-5
1 addition, 5 deletions
modules/gbif2_views/src/Service/GbifVboViewsData.php
with
48 additions
and
7 deletions
modules/gbif2_views/src/Plugin/views/query/GbifOccurrence.php
+
47
−
2
View file @
6340839b
...
...
@@ -73,6 +73,8 @@ class GbifOccurrence extends QueryPluginBase {
/**
* {@inheritdoc}
*
* We do not really use this, unless $field value is 'key'.
*/
public
function
addWhere
(
$group
,
$field
,
$value
=
NULL
,
$operator
=
NULL
)
{
// Ensure all variants of 0 are actually 0. Thus '', 0 and NULL are all
...
...
@@ -95,12 +97,23 @@ class GbifOccurrence extends QueryPluginBase {
* Builds the necessary info to execute the query.
*/
public
function
build
(
ViewExecutable
$view
)
{
// Filters.
$view
->
build_info
[
'query'
]
=
[];
// Filters.
foreach
(
$view
->
filter
as
$filter
)
{
$view
->
build_info
[
'query'
]
+=
$filter
->
generate
();
}
// Where conditions (only for key).
if
(
isset
(
$this
->
where
[
0
][
'conditions'
]))
{
foreach
(
$this
->
where
[
0
][
'conditions'
]
as
$condition
)
{
$operators
=
[
'='
,
'IN'
];
if
(
$condition
[
'field'
]
==
'key'
&&
in_array
(
$condition
[
'operator'
],
$operators
))
{
$view
->
build_info
[
'query'
][
'key'
]
=
$condition
[
'value'
];
}
}
}
// Pager.
$view
->
initPager
();
if
(
$view
->
pager
->
usePager
())
{
...
...
@@ -118,7 +131,7 @@ class GbifOccurrence extends QueryPluginBase {
public
function
execute
(
ViewExecutable
$view
)
{
$start
=
microtime
(
TRUE
);
$index
=
0
;
$results
=
$this
->
occ
->
search
(
$view
->
build_info
[
'query'
]
);
$results
=
$this
->
getResults
(
$view
);
foreach
(
$results
[
'results'
]
as
$data
)
{
$row
=
array_intersect_key
(
$data
,
$view
->
field
);
...
...
@@ -133,4 +146,36 @@ class GbifOccurrence extends QueryPluginBase {
$view
->
execute_time
=
microtime
(
TRUE
)
-
$start
;
}
/**
* Get view results.
*
* @param \Drupal\views\ViewExecutable $view
* The view resuls will be retrieved for.
*
* @return array
* An array with two keys:
* - results contains an array of GBIF occurrences,
* - count the number of results.
*/
protected
function
getResults
(
ViewExecutable
$view
)
{
$results
=
[];
if
(
isset
(
$view
->
build_info
[
'query'
][
'key'
]))
{
// If key is specified, GBIF search API is not called as it does not allow
// to specify this as a parameter. Instead, we directly retrieve
// occurrences. This behaviour takes precedence.
$keys
=
$view
->
build_info
[
'query'
][
'key'
];
$keys
=
is_array
(
$keys
)
?
$keys
:
[
$keys
];
foreach
(
$keys
as
$key
)
{
$results
[
'results'
][]
=
$this
->
occ
->
get
(
$key
);
}
$results
[
'count'
]
=
count
(
$keys
);
}
else
{
$results
=
$this
->
occ
->
search
(
$view
->
build_info
[
'query'
]);
}
return
$results
;
}
}
This diff is collapsed.
Click to expand it.
modules/gbif2_views/src/Service/GbifVboViewsData.php
+
1
−
5
View file @
6340839b
...
...
@@ -36,11 +36,7 @@ class GbifVboViewsData {
* The current view object.
*/
public
function
getEntityFromRow
(
ResultRow
$row
,
$relationship_id
,
ViewExecutable
$view
)
{
// We do not really need a full-blown entity in this context. This would be
// rather inefficient, though we could count on cache.
return
$this
->
entityTypeManager
->
getStorage
(
'gbif_occurrence'
)
->
create
([
'key'
=>
$row
->
key
,
]);
return
$this
->
entityTypeManager
->
getStorage
(
'gbif_occurrence'
)
->
load
(
$row
->
key
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment