diff --git a/config/schema/islandora_mirador_annotation.schema.yml b/config/schema/islandora_mirador_annotation.schema.yml new file mode 100644 index 00000000..6e5f8f6e --- /dev/null +++ b/config/schema/islandora_mirador_annotation.schema.yml @@ -0,0 +1,3 @@ +views.filter.has_annotated_member_pages: + type: views.filter.boolean + label: 'Has annotated member pages' diff --git a/islandora_mirador_annotation.views.inc b/islandora_mirador_annotation.views.inc new file mode 100644 index 00000000..d6df824d --- /dev/null +++ b/islandora_mirador_annotation.views.inc @@ -0,0 +1,15 @@ + t('Has annotated member pages'), + 'help' => t('Whether this node has member nodes containing Mirador annotations.'), + 'filter' => [ + 'id' => 'has_annotated_member_pages', + 'type' => 'yes-no', + ], + ]; +} diff --git a/src/Plugin/views/filter/HasAnnotatedMemberPages.php b/src/Plugin/views/filter/HasAnnotatedMemberPages.php new file mode 100644 index 00000000..581f5a12 --- /dev/null +++ b/src/Plugin/views/filter/HasAnnotatedMemberPages.php @@ -0,0 +1,49 @@ +ensureMyTable(); + + $operator = $this->value ? 'EXISTS' : 'NOT EXISTS'; + + $expression = " + $operator ( + SELECT 1 + FROM {node__field_member_of} member + INNER JOIN {islandora_mirador_annotation} annotation + ON member.entity_id = CAST( + SUBSTRING_INDEX( + SUBSTRING_INDEX( + annotation.canvas_id, + '/node/', + -1 + ), + '/', + 1 + ) AS UNSIGNED + ) + WHERE member.field_member_of_target_id = {$this->tableAlias}.nid + AND member.deleted = 0 + ) + "; + + $this->query->addWhereExpression( + $this->options['group'], + $expression + ); + } + +}