blib/lib/CGI/OptimalQuery/SavedSearches.pm untested

filter: Statementstmt 0.0% 0 / 44 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 75 SCAR 48.8
CC
11
Cov
0%
get_html
132.0
escapeHTML
2.0
BEGIN
2.0
CRAP 132.0
1 package CGI::OptimalQuery::SavedSearches;
2  
3 use strict;
4 use warnings;
5 no warnings qw( uninitialized redefine );
6 use CGI::OptimalQuery::Base();
7  
8 sub escapeHTML { CGI::OptimalQuery::Base::escapeHTML(@_) }
9  
10 sub get_html {
11 my ($q,$dbh,$userid) = @_;
12  
13 my $oracleReadLen;
14 if ($$dbh{Driver}{Name} eq 'Oracle') {
15 ($oracleReadLen) = $dbh->selectrow_array("SELECT max(dbms_lob.getlength(params)) FROM oq_saved_search WHERE user_id=?", undef, $userid);
16 }
17 local $dbh->{LongReadLen} = $oracleReadLen
18 if $oracleReadLen && $oracleReadLen > $dbh->{LongReadLen};
19  
20 local $$dbh{FetchHashKeyName} = 'NAME_uc';
21  
22 my $sth = $dbh->prepare(
23 "SELECT *
24 FROM oq_saved_search
25 WHERE user_id=?
26 ORDER BY oq_title, user_title");
27  
28 $sth->execute($userid);
29 my $last_oq_title = '';
30 my $buf = '';
31 while (my $h = $sth->fetchrow_hashref()) {
32 next if $$h{IS_DEFAULT};
33  
34 my $state_params='';
35 if ($$h{PARAMS}) {
36 my $params = eval '{'.$$h{PARAMS}.'}';
37 foreach my $k (keys %$params) {
38 next if $k =~ /^(module|show|rows_page|page|hiddenFilter|filter|queryDescr|sort)$/;
39 my $v = $$params{$k};
40 if (ref($v) eq 'ARRAY') {
41 $state_params .= '&'.$k.'='.$_ for @$v;
42 } else {
43 $state_params .= '&'.$k.'='.$v;
44 }
45 }
46 }
47  
48 if ($last_oq_title ne $$h{OQ_TITLE}) {
49 $buf .= '</ul>' if $last_oq_title;
50 $last_oq_title = $$h{OQ_TITLE};
51 $buf .= "<h4>".escapeHTML($$h{OQ_TITLE})."</h4><ul>";
52 }
53 $buf .= "<li>
54 <a href='".escapeHTML("$$h{URI}?OQLoadSavedSearch=$$h{ID}".$state_params)."' title='load saved search' class='opwin oqssload'>".escapeHTML($$h{USER_TITLE})."</a>
55 <button type=button title='delete saved search' class=oqssdelete data-url='".escapeHTML("$$h{URI}?OQDeleteSavedSearch=$$h{ID}".$state_params)."'>&#10005;</button>
56 </li>";
57 }
58 $buf .= '</ul>' if $last_oq_title;
59  
60 if ($buf) {
61 $buf = '<div id=loadsavedsearches>'.$buf.'</div>
62 <script>
63 $("#loadsavedsearches").on("click", ".oqssdelete", function(){
64 var $t = $(this);
65 var $li = $t.closest("li");
66 $.ajax({
67 type: "get",
68 url: $t.attr("data-url"),
69 success: function() {
70 if ($li.siblings().length==0) {
71 var $ul = $li.parent();
72 $ul.add($ul.prev("h4")).remove();
73 }
74 else {
75 $li.remove();
76 }
77 }
78 });
79 return false;
80 });
81 </script>';
82 }
83 return $buf;
84 }
85 1;