| 1 | package CGI::Widget::DBI::Browse; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use base qw/ CGI::Widget::DBI::Search::Base /; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use vars qw/ $VERSION /; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | $CGI::Widget::DBI::Browse::VERSION = '0.17'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use DBI; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use CGI::Widget::DBI::Search 0.31; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use URI::Escape qw/uri_escape uri_escape_utf8/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Scalar::Util qw/blessed/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | #use constant DEFAULT_CACHE_EXPIRATION => '30 days'; # SQL interval format | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | CGI::Widget::DBI::Browse - Database browsing widget | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | use CGI; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | use CGI::Widget::DBI::Browse; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | my $q = CGI->new; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | my $wb = CGI::Widget::DBI::Browse->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | q => $q, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # database connection info | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | -dbi_connect_dsn => 'DBI:Pg:dbname=my_pg_database;host=localhost', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | -dbi_user => 'pguser', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | -dbi_pass => 'pgpass', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # database schema info | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | -sql_table => 'table1 t1 inner join table2 t2 using (key_col)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | -sql_retrieve_columns => [ qw/t1.name t1.description t2.extra_information/ ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # or if you already have a search widget, you can use the settings from it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # my $wb = CGI::Widget::DBI::Browse->new(ws => $search_widget_obj); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # list of category columns (how to represent data as a tree) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | $wb->{-category_columns} = [ qw/main_category sub_category1 sub_category2/ ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # output to browser | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | print $q->header; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | print $q->start_html; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # show current page in tree | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # (default is a list of distinct values in the first category_column) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | print $wb->display_results(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | print $q->end_html; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | Implements user-interface for browsing a database table or joined tables. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | Just provide a list of hierarchical categories for your data, and it allows | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | the user to walk down the category tree to find the database records they | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | want. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | Specifically, this module simply makes successive calls to the search widget | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | module (L<CGI::Widget::DBI::Search>) filtering results by the category of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | records the user is currently viewing (node in a tree representation of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | your data). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | =head1 CONSTRUCTOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | =item new(@config_options) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | Creates and initializes a new CGI::Widget::DBI::Browse object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | =head2 Possible configuration options: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | =item Database connection options | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | -dbi_connect_dsn => DBI data source name (full connection string) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | -dbi_user => database username | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | -dbi_pass => database password | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | -dbi_host => host to connect to database (overridden by -dbi_connect_dsn) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | -sql_database => database to connect to (overridden by -dbi_connect_dsn) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | =item Database retrieval options | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | -sql_table => Database table(s) to query, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | -sql_table_columns => [ARRAY] List of all columns in sql_table, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | -sql_retrieve_columns => [ARRAY] List of columns for retrieval, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | ... Also accepts all the options that CGI::Widget::DBI::Search does; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | they are simply passed through ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | =item Schema description configuration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | -category_columns => [ARRAY] List of columns to be used as "categories," | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | or internal nodes, allowing hierarchical navigation of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | a tree-based representation of your data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | -category_sql_retrieve_columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | => {HASH} Extra columns to be retrieved for a given category | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | column. Keys should be a subset of -category_columns, and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | values should be an arrayref containing the extra columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | (or column aliases) to retrieve for that category column. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | Typically used in conjunction with -category_column_closures. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | -category_column_closures | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | => {HASH} of (CODE): Reference to a hash containing a code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | reference for each category column which should be passed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | through before displaying. Similar to the -columndata_closures | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | option of CGI::Widget::DBI::Search. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | =item Search result display options | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | -max_category_results_per_page | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | => Maximum number of database records to display | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | on a page while navigating by category (default: 100) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | -skip_to_results => If true, skips directly to display of database records | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | while in category browsing mode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | -auto_skip_to_results => If set, skips directly to results if in category browsing mode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | but there are no category members at the current level, or if | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | there is exactly one category member with value '' (empty string). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | Note: this will have no effect if the search widget ('ws' object) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | is not set to -show_total_numresults. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | -post_auto_skip_callback | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | => (CODE): If set along with -auto_skip_to_results, and auto-skip | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | mode is in effect, this callback routine will be called before | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | the actual search and displaying results are executed. Useful | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | when behavior of the widget is dependent on whether we are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | browsing or not. (i.e. the return value of is_browsing()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | =item Performance options | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | -cache_categories => Turn on automatic caching of categories. Creates a table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | called browse_widget_category_cache which stores records | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | for each internal node in the browse tree. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | BEWARE: currently there is no cache expiration mechanism; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | also, the the cache table is a hard-coded name, so be careful | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | if you use more than one browse widget in the same database. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | sub initialize { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
initialize: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | if (blessed($self->{ws}) && $self->{ws}->isa('CGI::Widget::DBI::Search')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($self->{"ws"}) and $self->{"ws"}->isa("CGI::Widget::DBI::Search")
MC/DC0%0/2
builtin::blessed($self->{"ws"}) and $self->{"ws"}->isa("CGI::Widget::DBI::Search")
builtin::blessed($self->{"ws"})
$self->{"ws"}->isa("CGI::Widget::DBI::Search")
Truth table0%0/3
A and B
A= builtin::blessed($self->{"ws"})B= $self->{"ws"}->isa("CGI::Widget::DBI::Search")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | $self->{q} = $self->{ws}->{q}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | $self->{ws} = CGI::Widget::DBI::Search->new($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | # search results shown in grid format by default, when using browse widget | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | $self->{ws}->{-display_mode} ||= 'grid'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"ws"}{"-display_mode"} ||= "grid"
MC/DC0%0/1
$self->{"ws"}{"-display_mode"} ||= "grid"
$self->{"ws"}{"-display_mode"}
Truth table0%0/2
A
A= $self->{"ws"}{"-display_mode"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | sub _break_circular_references { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_break_circular_references: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | delete $self->{old_ws}->{display}->{b}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | delete $self->{ws}->{display}->{b}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | =item is_browsing() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | Returns true if the widget is in browse mode, viewing navigable categories (branch nodes) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | rather than viewing actual results (leaf nodes). Returns the actual category column name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | currently browsing on. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | =item parent_category_column() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | Returns the previous category column in -category_columns relative to the node currently | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | being viewed. If we are at the top-level category (root node in the browse tree), then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | this method returns undef. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | =item ancestor_category_columns() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | Returns a list of all previous category columns in -category_columns relative to the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | current node. If we are the root node, an empty list is returned. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | =item display_results() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | Displays results from CGI::Widget::DBI::Search (in grid display mode) of data values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | specified by -category_columns and current state of query object in object variable 'q'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | sub is_browsing { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_browsing: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | $self->_set_category_index() if ! defined $self->{_category_idx}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | return $self->{-category_columns}->[ $self->{_category_idx} ] if $self->_is_browsing(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | sub _is_browsing { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_browsing: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | return defined($self->{_category_idx}) && ! $self->{-skip_to_results} && ! $self->{q}->param('_browse_skip_to_results_'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
defined $self->{'_category_idx'} && !$self->{'-skip_to_results'} && !$self->{'q'}->param('_browse_skip_to_results_')
defined $self->{"_category_idx"} and not $self->{"-skip_to_results"}
MC/DC0%0/3
defined $self->{'_category_idx'} && !$self->{'-skip_to_results'} && !$self->{'q'}->param('_browse_skip_to_results_')
defined $self->{"_category_idx"}
not $self->{"-skip_to_results"}
!$self->{'q'}->param('_browse_skip_to_results_')
Truth table0%0/4
A and not(B) && not(C)
A= defined $self->{"_category_idx"}B= not $self->{"-skip_to_results"}C= !$self->{'q'}->param('_browse_skip_to_results_')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | sub parent_category_column { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parent_category_column: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | $self->_set_category_index() if ! defined $self->{_category_idx}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | return $self->{-category_columns}->[ -1 ] if ! $self->_is_browsing() && ! $self->{'auto_skip_in_effect'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->_is_browsing or $self->{"auto_skip_in_effect"}
MC/DC0%0/2
$self->_is_browsing or $self->{"auto_skip_in_effect"}
$self->_is_browsing
$self->{"auto_skip_in_effect"}
Truth table0%0/3
A or B
A= $self->_is_browsingB= $self->{"auto_skip_in_effect"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | return undef if $self->{_category_idx} == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | return $self->{-category_columns}->[ $self->{_category_idx} - 1 ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | sub ancestor_category_columns { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ancestor_category_columns: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | $self->_set_category_index() if ! defined $self->{_category_idx}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | my $end_idx = $self->_is_browsing() || $self->{'auto_skip_in_effect'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | ? $self->{_category_idx} - 1 : $#{ $self->{-category_columns} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->_is_browsing or $self->{"auto_skip_in_effect"}
MC/DC0%0/2
$self->_is_browsing or $self->{"auto_skip_in_effect"}
$self->_is_browsing
$self->{"auto_skip_in_effect"}
Truth table0%0/3
A or B
A= $self->_is_browsingB= $self->{"auto_skip_in_effect"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | return @{ $self->{-category_columns} }[0 .. $end_idx]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | sub _set_category_index { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_category_index: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | my $q = $self->{q}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | my @categories = @{ $self->{-category_columns} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | foreach my $i (0 .. $#categories) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | if (! $q->param($categories[$i])) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | $self->{_category_idx} = $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | sub configure_search_for_category_browse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
configure_search_for_category_browse: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | my $ws = $self->{ws}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | my $category_column = $self->is_browsing(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | # first, save search widget object in case we need it back, if -auto_skip_to_results is on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | $self->{old_ws} = $self->{ws}->new( $self->{ws} ) if $self->{-auto_skip_to_results}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | $ws->{-display_class} = undef; # need to clear in case it was manually set | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | $ws->{-display_mode} = 'grid'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | # display a list of (sub)categories/branch nodes instead of items/leaf nodes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | $ws->{-opt_precols_sql} = 'DISTINCT'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | my @extra_category_retr_cols = map { $ws->full_sql_column_for_alias($_) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | @{ $self->{-category_sql_retrieve_columns}->{$category_column} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | $ws->{-sql_search_columns} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | $ws->{-sql_retrieve_columns} = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | $ws->full_sql_column_for_alias($category_column), @extra_category_retr_cols, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | $ws->{-where_clause} .= ($ws->{-where_clause} ? ' AND ' : '') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | . $ws->sql_column_with_tbl_alias_for_alias($category_column) . ' IS NOT NULL'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | $ws->{-display_columns} = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | $category_column => $ws->{-display_columns}->{$category_column} || $category_column | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$ws->{'-display_columns'}{$category_column} || $category_column
MC/DC0%0/2
$ws->{'-display_columns'}{$category_column} || $category_column
$ws->{'-display_columns'}{$category_column}
$category_column
Truth table0%0/3
A || B
A= $ws->{'-display_columns'}{$category_column}B= $category_column
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | $ws->{-columndata_closures} = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | $category_column => _category_columndata_closure($self, $category_column) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | $ws->{-default_orderby_columns} = [ $ws->sql_column_with_tbl_alias_for_alias($category_column) ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | $ws->{-max_results_per_page} = $self->{-max_category_results_per_page} || 100; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'-max_category_results_per_page'} || 100
MC/DC0%0/1
$self->{'-max_category_results_per_page'} || 100
$self->{'-max_category_results_per_page'}
Truth table0%0/2
A
A= $self->{'-max_category_results_per_page'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | $ws->{-browse_mode} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | =head1 CACHING METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | =item category_value_is_cached($category, $value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | Returns true if cache entries exist in the category cache table for the key/value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | pair $category/$value. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | =item cache_results_for_category_value($category, $value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | Executes a category search as normal, using CGI::Widget::DBI::Search in -dry_run | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | mode to just generate the SQL, and stores the results in category cache table. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | sub _create_category_cache_table { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_category_cache_table: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | $self->{ws}->{-dbh}->do(<<'END_SQL'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | CREATE TABLE IF NOT EXISTS browse_widget_category_cache ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | category_column VARCHAR(32), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | category_value VARCHAR(96), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | child_value VARCHAR(96), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | last_modified TIMESTAMP, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | UNIQUE INDEX unq_all (category_column, category_value, child_value), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | INDEX idx_category_value (category_column, category_value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | ) ENGINE = MyISAM | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | END_SQL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | sub _where_clause_for_category_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | my ($self, $category, $value) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_where_clause_for_category_value: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | return 'category_column '.(defined $category ? '=?' : 'IS NULL') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | .' AND category_value '.(defined $value ? '=?' : 'IS NULL'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | sub _bind_params_for_category_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | ▶ | my ($self, $category, $value) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bind_params_for_category_value: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | return (defined $category ? $category : (), defined $value ? $value : ()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | sub category_value_is_cached { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | my ($self, $category, $value) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
category_value_is_cached: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | my $sth = $self->{ws}->{-dbh}->prepare_cached( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | 'SELECT count(1) FROM browse_widget_category_cache WHERE ' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | . $self->_where_clause_for_category_value($category, $value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | $sth->execute($self->_bind_params_for_category_value($category, $value)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | my $cnt = $sth->fetchrow_arrayref()->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | $sth->finish(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | return $cnt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | sub cache_results_for_category_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | my ($self, $category, $value) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cache_results_for_category_value: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | my $ws = $self->{ws}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | my $category_column = $self->is_browsing(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | local $ws->{-dry_run} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | local $ws->{-show_total_numresults} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | $ws->search(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | my $sth = $ws->{-dbh}->prepare_cached(qq{ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | INSERT INTO browse_widget_category_cache (category_column, category_value, child_value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | SELECT DISTINCT ? AS category_column, ? AS category_value, search.$category_column AS child_value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | FROM ( @{[ $ws->{'_sql'} ]} ) search | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | $sth->execute($category, $value, @{ $ws->{-bind_params} }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | $sth->finish(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | =head1 DISPLAY METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | =item display_results() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | Main rendering method of the database browse. Typically this is the only method that actually *needs* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | to be called from the delegating class, after configuration, since this calls all other methods as necessary. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | =item display_cached_category_results() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | Displays a node in the browse tree, identically to how display_results() would, only by using the cache table. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | Specifically, it configures the search widget by directly injecting data retrieved from the cache table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | and calling the search widget's display_results() method, skipping the call to its search() method. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | Also, if there is no cache entry for the current node in the browse tree, this calls cache_results_for_category_value() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | first to cache the results. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | Note: this method is called automatically by display_results() if -cache_categories is true. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | =item add_breadcrumbs_to_header() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | Appends breadcrumb navigation HTML to the -optional_header of the enclosed search widget object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | based on the current state of the browse widget. Also sets the 'category_title' object of this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | browse widget object to a string representation of the current location in the browse tree. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | Note: this method is called automatically by display_results(). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | =item link_for_category_column($category_col, $row) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | Emits an href link to the requested $category_col in the browse tree for the category data from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | $row. This is typically used as a callback from a column's -columndata_closures rendering. E.g. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | $wb->{ws}->{-columndata_closures}->{'state_or_province'} = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | my ($obj, $row) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | return $obj->{b}->link_for_category_column('state_or_province', $row); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | For it to work as expected, all columns listed in -category_columns must also be in the select | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | results, i.e. present in -sql_retrieve_columns. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | sub display_results { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
display_results: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | my $q = $self->{q}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | my $ws = $self->{ws}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | die 'Required configuration setting -category_columns not set.' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | ▶ | if ref $self->{-category_columns} ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | # set category filter condition | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | $self->{'filter_columns'} = [ grep($q->param($_), @{ $self->{-category_columns} }) ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | ▶ | if (@{ $self->{'filter_columns'} }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | $ws->{-where_clause} = ($ws->{-where_clause} ? '('.$ws->{-where_clause}.') AND ' : '').join( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | ▶ | ' AND ', map {$_.' = ?'} map { $ws->sql_column_with_tbl_alias_for_alias($_) } @{ $self->{'filter_columns'} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | ▶ | $ws->{-bind_params} = [ @{ $ws->{-bind_params} || [] }, map { $q->param($_) } @{ $self->{'filter_columns'} } ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | $ws->{-href_extra_vars}->{$_} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | $ws->{-form_extra_vars}->{$_} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | } @{ $self->{'filter_columns'} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | my $category_column = $self->is_browsing(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | ▶ | if ($category_column) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | $self->configure_search_for_category_browse(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | ▶ | return $self->display_cached_category_results() if $self->{-cache_categories}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | $ws->{-href_extra_vars}->{'_browse_skip_to_results_'} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | $ws->{-form_extra_vars}->{'_browse_skip_to_results_'} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | $self->add_breadcrumbs_to_header(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | $self->build_results(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | my $html; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | ▶ | if ($self->{ws}->init_display_class()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | $self->{ws}->{display}->{b} = $self; # circular ref, must break with _break_circular_references() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | $html = $self->{ws}->{display}->display(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | $self->_break_circular_references(); # must always break ref to avoid memory leak, even if error occurred | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | if ($@) { die $@; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | return $html; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | sub build_results { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_results: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | $self->{ws}->search(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | $self->auto_skip_to_results(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | sub auto_skip_to_results { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
auto_skip_to_results: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | my $ws = $self->{ws}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | my $category_column = $self->is_browsing(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | ▶ | if ($self->{-auto_skip_to_results} && $category_column && $ws->{-show_total_numresults} && $ws->{'numresults'} <= 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$self->{"-auto_skip_to_results"} and $category_column and $ws->{"-show_total_numresults"} and $ws->{"numresults"} <= 1
$self->{"-auto_skip_to_results"} and $category_column and $ws->{"-show_total_numresults"}
$self->{"-auto_skip_to_results"} and $category_column
MC/DC0%0/4
$self->{"-auto_skip_to_results"} and $category_column and $ws->{"-show_total_numresults"} and $ws->{"numresults"} <= 1
$self->{"-auto_skip_to_results"}
$category_column
$ws->{"-show_total_numresults"}
$ws->{"numresults"} <= 1
Truth table0%0/5
A and B and C and D
A= $self->{"-auto_skip_to_results"}B= $category_columnC= $ws->{"-show_total_numresults"}D= $ws->{"numresults"} <= 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | # skip to results if we are browsing but we reach a category which has just 0 or 1 members | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | $self->{ws} = $self->{old_ws}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | $self->{-skip_to_results} = $self->{'auto_skip_in_effect'} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | $self->{'_added_breadcrumbs'} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | $self->add_breadcrumbs_to_header(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | $self->{-post_auto_skip_callback}->($self) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | ▶ | if ref $self->{-post_auto_skip_callback} eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | $self->{ws}->search(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | sub display_cached_category_results { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
display_cached_category_results: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | my $ws = $self->{ws}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | my $category_column = $self->is_browsing(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | $self->_create_category_cache_table(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | my $parent_category = $self->parent_category_column(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | my $parent_value = $self->decode_utf8($self->{q}->param($parent_category)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | ▶ | if (! $self->category_value_is_cached($parent_category, $parent_value)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | $self->cache_results_for_category_value($parent_category, $parent_value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | my $sth = $ws->{-dbh}->prepare_cached(qq| | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | SELECT child_value AS $category_column | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | FROM browse_widget_category_cache | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | WHERE @{[ $self->_where_clause_for_category_value($parent_category, $parent_value) ]} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | ORDER BY $category_column | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | |); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | $sth->execute($self->_bind_params_for_category_value($parent_category, $parent_value)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | $ws->{'results'} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | ▶ | while (my $row = $sth->fetchrow_hashref()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | push(@{ $ws->{'results'} }, $row); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | $sth->finish(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | # extra cost to using -cache_categories with -category_sql_retrieve_columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | # - presumably this extra query would be faster than not caching categories at all | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | ▶ | if (my $extra_cols = $self->{-category_sql_retrieve_columns}->{$category_column}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | $sth = $ws->{-dbh}->prepare_cached(qq| | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | SELECT DISTINCT @{[ join ',', map { $ws->full_sql_column_for_alias($_) } ($category_column, @$extra_cols) ]} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | FROM @{[ $ws->{-sql_table} ]} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | WHERE @{[ $ws->full_sql_column_for_alias($category_column) ]} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | IN ( @{[ join ',', map {'?'} @{ $ws->{'results'} } ]} ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | ORDER BY $category_column | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | |); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | $sth->execute(map { $_->{$category_column} } @{ $ws->{'results'} }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | ▶ | while (my $row = $sth->fetchrow_hashref()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | ▶ | $ws->{'results'}->[$i] = { %{ $ws->{'results'}->[$i] || {} }, %$row }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | $sth->finish(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | $self->add_breadcrumbs_to_header(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | return $ws->display_results(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | ▶ | sub category_title { return shift->{'category_title'} || '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
category_title: not called CC=2 SCAR=17.9
Pod
undocumented
Condition0%0/2
+(shift())->{'category_title'} || ''
MC/DC0%0/1
+(shift())->{'category_title'} || ''
+(shift())->{'category_title'}
Truth table0%0/2
A
A= +(shift())->{'category_title'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | sub add_breadcrumbs_to_header { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_breadcrumbs_to_header: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | ▶ | return if $self->{'_added_breadcrumbs'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | my $q = $self->{q}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 0 | my $ws = $self->{ws}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | # add breadcrumbs in search header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 0 | my @cume_category_filters; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | my $extra_vars = $ws->extra_vars_for_uri([ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | ▶ | @{ $self->{'filter_columns'} }, '_browse_skip_to_results_', @{ $self->{-exclude_vars_from_breadcrumbs}||[] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | ]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | $self->{'category_title'} = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | $self->{'breadcrumbs'} = ['Top']; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | $self->{'breadcrumb_links'} = [ '<a href="?'.$extra_vars.'" class="breadcrumbNavLink">'.$ws->translate('Top').'</a>' ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | foreach (@{ $self->{'filter_columns'} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | my $breadcrumb_name = $self->decode_utf8($q->param($_)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | ▶ | $self->{'category_title'} = join(' > ', $self->{'category_title'} || (), $breadcrumb_name || ()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$self->{'category_title'} || ()
$breadcrumb_name || ()
MC/DC0%0/2
$self->{'category_title'} || ()
$self->{'category_title'}
()
MC/DC0%0/2
$breadcrumb_name || ()
$breadcrumb_name
()
Truth table0%0/3
A || B
A= $self->{'category_title'}B= ()
Truth table0%0/3
A || B
A= $breadcrumb_nameB= ()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | push(@cume_category_filters, _uri_param_pair($_, $breadcrumb_name)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | push(@{ $self->{'breadcrumbs'} }, $breadcrumb_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | ▶ | push(@{ $self->{'breadcrumb_links'} }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$extra_vars || ()
MC/DC0%0/2
$extra_vars || ()
$extra_vars
()
Truth table0%0/3
A || B
A= $extra_varsB= ()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | '<a href="?'.join('&', @cume_category_filters, $extra_vars||()).'" class="breadcrumbNavLink">'.$breadcrumb_name.'</a>'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | my $skip_to_results = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | ▶ | if ($self->is_browsing() && ! $self->{-skip_to_results}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/3
$self->is_browsing and not $self->{"-skip_to_results"}
MC/DC0%0/2
$self->is_browsing and not $self->{"-skip_to_results"}
$self->is_browsing
not $self->{"-skip_to_results"}
Truth table0%0/3
A and not(B)
A= $self->is_browsingB= not $self->{"-skip_to_results"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | ▶ | $skip_to_results = ' <i> → <a href="?'.join( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$extra_vars || ()
MC/DC0%0/2
$extra_vars || ()
$extra_vars
()
Truth table0%0/3
A || B
A= $extra_varsB= ()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | '&', @cume_category_filters, '_browse_skip_to_results_=1', $extra_vars||(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | ).'" id="skipToResultsLink"><span>'.$ws->translate('Show all items in this category').'</span></a></i>'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | } elsif ($q->param('_browse_skip_to_results_')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | $self->{'category_title'} .= ' ('.$ws->translate('all results').')'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | } elsif (! $self->{-skip_to_results}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | # -skip_to_results typically used for searching, so don't add anything to the title | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | $self->{'category_title'} .= ' ('.$ws->translate('results').')'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | $ws->{-optional_header} .= '<div id="breadcrumbNavDiv">'.join(' > ', @{ $self->{'breadcrumb_links'} }).$skip_to_results.'</div>' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | . '<div class="categoryContentDiv" id="categoryContentDiv-'.join('__', @{ $self->{'breadcrumbs'} }).'"></div>'; # available for CSS-configured content | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | $self->{'_added_breadcrumbs'} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | sub _uri_param_pair { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | ▶ | my ($key, $val) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_uri_param_pair: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | ▶ | return uri_escape($key).'='.uri_escape_utf8($val||''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$val || ''
MC/DC0%0/1
$val || ''
$val
Truth table0%0/2
A
A= $val
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | sub link_for_category_column { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | ▶ | my ($self, $category_col, $row, @exclude_params) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
link_for_category_column: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | my (@cols, $col_found); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 0 | foreach (@{ $self->{-category_columns} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | push(@cols, $_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | ▶ | if ($_ eq $category_col) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | $col_found = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | my $extra_vars = $self->{ws}->extra_vars_for_uri([ @{ $self->{'filter_columns'} }, '_browse_skip_to_results_', @exclude_params ]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 0 | my $category_decoded = $self->decode_utf8($row->{$category_col}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | return $col_found | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 0 | ▶ | ? '<a href="?'.join('&', (map { _uri_param_pair($_, $self->decode_utf8($row->{$_})) } @cols), $extra_vars || ()).'" id="jumpToCategoryLink">' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$extra_vars || ()
MC/DC0%0/2
$extra_vars || ()
$extra_vars
()
Truth table0%0/3
A || B
A= $extra_varsB= ()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | .$category_decoded.'</a>' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | : $category_decoded; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | sub _category_columndata_closure { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 0 | ▶ | my ($self, $category_col) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_category_columndata_closure: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | my $existing_category_filters = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | join('&', map { _uri_param_pair($_, $self->decode_utf8($self->{q}->param($_))) } @{ $self->{'filter_columns'} }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | return sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 0 | ▶ | my ($sd, $row) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 0 | my $category_decoded = $self->decode_utf8($row->{$category_col}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | my $category_display_value = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | ref $self->{-category_column_closures}->{$category_col} eq 'CODE' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | ▶ | ? $self->{-category_column_closures}->{$category_col}->($sd, $row) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | : $category_decoded; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | my $extra_vars = $sd->extra_vars_for_uri([ @{ $self->{'filter_columns'} }, '_browse_skip_to_results_' ]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | ▶ | return '<a href="?'.join( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$existing_category_filters || ()
$extra_vars || ()
MC/DC0%0/2
$existing_category_filters || ()
$existing_category_filters
()
MC/DC0%0/2
$extra_vars || ()
$extra_vars
()
Truth table0%0/3
A || B
A= $existing_category_filtersB= ()
Truth table0%0/3
A || B
A= $extra_varsB= ()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | '&', $existing_category_filters || (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | _uri_param_pair($category_col, $category_decoded), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | $extra_vars || (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | ).'" id="categoryNavLink-'.CGI::escapeHTML($category_decoded).'">'.$category_display_value.'</a>'; # TODO: HTML::Escape is faster than CGI | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||