|
Lines 117-129
sub get_count_by_tag_status {
Link Here
|
| 117 |
} |
117 |
} |
| 118 |
|
118 |
|
| 119 |
sub remove_tag { |
119 |
sub remove_tag { |
| 120 |
my $tag_id = shift or return undef; |
120 |
my $tag_id = shift or return; |
| 121 |
my $user_id = (@_) ? shift : undef; |
121 |
my $user_id = (@_) ? shift : undef; |
| 122 |
my $rows = (defined $user_id) ? |
122 |
my $rows = (defined $user_id) ? |
| 123 |
get_tag_rows({tag_id=>$tag_id, borrowernumber=>$user_id}) : |
123 |
get_tag_rows({tag_id=>$tag_id, borrowernumber=>$user_id}) : |
| 124 |
get_tag_rows({tag_id=>$tag_id}) ; |
124 |
get_tag_rows({tag_id=>$tag_id}) ; |
| 125 |
$rows or return 0; |
125 |
$rows or return 0; |
| 126 |
(scalar(@$rows) == 1) or return undef; # should never happen (duplicate ids) |
126 |
(scalar(@$rows) == 1) or return; # should never happen (duplicate ids) |
| 127 |
my $row = shift(@$rows); |
127 |
my $row = shift(@$rows); |
| 128 |
($tag_id == $row->{tag_id}) or return 0; |
128 |
($tag_id == $row->{tag_id}) or return 0; |
| 129 |
my $tags = get_tags({term=>$row->{term}, biblionumber=>$row->{biblionumber}}); |
129 |
my $tags = get_tags({term=>$row->{term}, biblionumber=>$row->{biblionumber}}); |
|
Lines 145-169
sub remove_tag {
Link Here
|
| 145 |
} |
145 |
} |
| 146 |
|
146 |
|
| 147 |
sub delete_tag_index { |
147 |
sub delete_tag_index { |
| 148 |
(@_) or return undef; |
148 |
(@_) or return; |
| 149 |
my $sth = C4::Context->dbh->prepare("DELETE FROM tags_index WHERE term = ? AND biblionumber = ? LIMIT 1"); |
149 |
my $sth = C4::Context->dbh->prepare("DELETE FROM tags_index WHERE term = ? AND biblionumber = ? LIMIT 1"); |
| 150 |
$sth->execute(@_); |
150 |
$sth->execute(@_); |
| 151 |
return $sth->rows || 0; |
151 |
return $sth->rows || 0; |
| 152 |
} |
152 |
} |
| 153 |
sub delete_tag_approval { |
153 |
sub delete_tag_approval { |
| 154 |
(@_) or return undef; |
154 |
(@_) or return; |
| 155 |
my $sth = C4::Context->dbh->prepare("DELETE FROM tags_approval WHERE term = ? LIMIT 1"); |
155 |
my $sth = C4::Context->dbh->prepare("DELETE FROM tags_approval WHERE term = ? LIMIT 1"); |
| 156 |
$sth->execute(shift); |
156 |
$sth->execute(shift); |
| 157 |
return $sth->rows || 0; |
157 |
return $sth->rows || 0; |
| 158 |
} |
158 |
} |
| 159 |
sub delete_tag_row_by_id { |
159 |
sub delete_tag_row_by_id { |
| 160 |
(@_) or return undef; |
160 |
(@_) or return; |
| 161 |
my $sth = C4::Context->dbh->prepare("DELETE FROM tags_all WHERE tag_id = ? LIMIT 1"); |
161 |
my $sth = C4::Context->dbh->prepare("DELETE FROM tags_all WHERE tag_id = ? LIMIT 1"); |
| 162 |
$sth->execute(shift); |
162 |
$sth->execute(shift); |
| 163 |
return $sth->rows || 0; |
163 |
return $sth->rows || 0; |
| 164 |
} |
164 |
} |
| 165 |
sub delete_tag_rows_by_ids { |
165 |
sub delete_tag_rows_by_ids { |
| 166 |
(@_) or return undef; |
166 |
(@_) or return; |
| 167 |
my $i=0; |
167 |
my $i=0; |
| 168 |
foreach(@_) { |
168 |
foreach(@_) { |
| 169 |
$i += delete_tag_row_by_id($_); |
169 |
$i += delete_tag_row_by_id($_); |
|
Lines 359-365
sub get_approval_rows { # i.e., from tags_approval
Link Here
|
| 359 |
} |
359 |
} |
| 360 |
|
360 |
|
| 361 |
sub is_approved { |
361 |
sub is_approved { |
| 362 |
my $term = shift or return undef; |
362 |
my $term = shift or return; |
| 363 |
my $sth = C4::Context->dbh->prepare("SELECT approved FROM tags_approval WHERE term = ?"); |
363 |
my $sth = C4::Context->dbh->prepare("SELECT approved FROM tags_approval WHERE term = ?"); |
| 364 |
$sth->execute($term); |
364 |
$sth->execute($term); |
| 365 |
unless ($sth->rows) { |
365 |
unless ($sth->rows) { |
|
Lines 370-376
sub is_approved {
Link Here
|
| 370 |
} |
370 |
} |
| 371 |
|
371 |
|
| 372 |
sub get_tag_index { |
372 |
sub get_tag_index { |
| 373 |
my $term = shift or return undef; |
373 |
my $term = shift or return; |
| 374 |
my $sth; |
374 |
my $sth; |
| 375 |
if (@_) { |
375 |
if (@_) { |
| 376 |
$sth = C4::Context->dbh->prepare("SELECT * FROM tags_index WHERE term = ? AND biblionumber = ?"); |
376 |
$sth = C4::Context->dbh->prepare("SELECT * FROM tags_index WHERE term = ? AND biblionumber = ?"); |
|
Lines 384-390
sub get_tag_index {
Link Here
|
| 384 |
|
384 |
|
| 385 |
sub whitelist { |
385 |
sub whitelist { |
| 386 |
my $operator = shift; |
386 |
my $operator = shift; |
| 387 |
defined $operator or return undef; # have to test defined to allow =0 (kohaadmin) |
387 |
defined $operator or return; # have to test defined to allow =0 (kohaadmin) |
| 388 |
if ($ext_dict) { |
388 |
if ($ext_dict) { |
| 389 |
foreach (@_) { |
389 |
foreach (@_) { |
| 390 |
spellcheck($_) or next; |
390 |
spellcheck($_) or next; |
|
Lines 406-412
sub whitelist {
Link Here
|
| 406 |
# a term mistakenly, you can still reverse it. But there is no going back to "neutral". |
406 |
# a term mistakenly, you can still reverse it. But there is no going back to "neutral". |
| 407 |
sub blacklist { |
407 |
sub blacklist { |
| 408 |
my $operator = shift; |
408 |
my $operator = shift; |
| 409 |
defined $operator or return undef; # have to test defined to allow =0 (kohaadmin) |
409 |
defined $operator or return; # have to test defined to allow =0 (kohaadmin) |
| 410 |
foreach (@_) { |
410 |
foreach (@_) { |
| 411 |
my $aref = get_approval_rows({term=>$_}); |
411 |
my $aref = get_approval_rows({term=>$_}); |
| 412 |
if ($aref and scalar @$aref) { |
412 |
if ($aref and scalar @$aref) { |
|
Lines 419-432
sub blacklist {
Link Here
|
| 419 |
} |
419 |
} |
| 420 |
sub add_filter { |
420 |
sub add_filter { |
| 421 |
my $operator = shift; |
421 |
my $operator = shift; |
| 422 |
defined $operator or return undef; # have to test defined to allow =0 (kohaadmin) |
422 |
defined $operator or return; # have to test defined to allow =0 (kohaadmin) |
| 423 |
my $query = "INSERT INTO tags_blacklist (regexp,y,z) VALUES (?,?,?)"; |
423 |
my $query = "INSERT INTO tags_blacklist (regexp,y,z) VALUES (?,?,?)"; |
| 424 |
# my $sth = C4::Context->dbh->prepare($query); |
424 |
# my $sth = C4::Context->dbh->prepare($query); |
| 425 |
return scalar @_; |
425 |
return scalar @_; |
| 426 |
} |
426 |
} |
| 427 |
sub remove_filter { |
427 |
sub remove_filter { |
| 428 |
my $operator = shift; |
428 |
my $operator = shift; |
| 429 |
defined $operator or return undef; # have to test defined to allow =0 (kohaadmin) |
429 |
defined $operator or return; # have to test defined to allow =0 (kohaadmin) |
| 430 |
my $query = "REMOVE FROM tags_blacklist WHERE blacklist_id = ?"; |
430 |
my $query = "REMOVE FROM tags_blacklist WHERE blacklist_id = ?"; |
| 431 |
# my $sth = C4::Context->dbh->prepare($query); |
431 |
# my $sth = C4::Context->dbh->prepare($query); |
| 432 |
# $sth->execute($term); |
432 |
# $sth->execute($term); |
|
Lines 435-441
sub remove_filter {
Link Here
|
| 435 |
|
435 |
|
| 436 |
sub add_tag_approval { # or disapproval |
436 |
sub add_tag_approval { # or disapproval |
| 437 |
$debug and warn "add_tag_approval(" . join(", ",map {defined($_) ? $_ : 'UNDEF'} @_) . ")"; |
437 |
$debug and warn "add_tag_approval(" . join(", ",map {defined($_) ? $_ : 'UNDEF'} @_) . ")"; |
| 438 |
my $term = shift or return undef; |
438 |
my $term = shift or return; |
| 439 |
my $query = "SELECT * FROM tags_approval WHERE term = ?"; |
439 |
my $query = "SELECT * FROM tags_approval WHERE term = ?"; |
| 440 |
my $sth = C4::Context->dbh->prepare($query); |
440 |
my $sth = C4::Context->dbh->prepare($query); |
| 441 |
$sth->execute($term); |
441 |
$sth->execute($term); |
|
Lines 460-467
sub add_tag_approval { # or disapproval
Link Here
|
| 460 |
|
460 |
|
| 461 |
sub mod_tag_approval { |
461 |
sub mod_tag_approval { |
| 462 |
my $operator = shift; |
462 |
my $operator = shift; |
| 463 |
defined $operator or return undef; # have to test defined to allow =0 (kohaadmin) |
463 |
defined $operator or return; # have to test defined to allow =0 (kohaadmin) |
| 464 |
my $term = shift or return undef; |
464 |
my $term = shift or return; |
| 465 |
my $approval = (scalar @_ ? shift : 1); # default is to approve |
465 |
my $approval = (scalar @_ ? shift : 1); # default is to approve |
| 466 |
my $query = "UPDATE tags_approval SET approved_by=?, approved=?, date_approved=NOW() WHERE term = ?"; |
466 |
my $query = "UPDATE tags_approval SET approved_by=?, approved=?, date_approved=NOW() WHERE term = ?"; |
| 467 |
$debug and print STDERR "mod_tag_approval query: $query\nmod_tag_approval args: ($operator,$approval,$term)\n"; |
467 |
$debug and print STDERR "mod_tag_approval query: $query\nmod_tag_approval args: ($operator,$approval,$term)\n"; |
|
Lines 470-477
sub mod_tag_approval {
Link Here
|
| 470 |
} |
470 |
} |
| 471 |
|
471 |
|
| 472 |
sub add_tag_index { |
472 |
sub add_tag_index { |
| 473 |
my $term = shift or return undef; |
473 |
my $term = shift or return; |
| 474 |
my $biblionumber = shift or return undef; |
474 |
my $biblionumber = shift or return; |
| 475 |
my $query = "SELECT * FROM tags_index WHERE term = ? AND biblionumber = ?"; |
475 |
my $query = "SELECT * FROM tags_index WHERE term = ? AND biblionumber = ?"; |
| 476 |
my $sth = C4::Context->dbh->prepare($query); |
476 |
my $sth = C4::Context->dbh->prepare($query); |
| 477 |
$sth->execute($term,$biblionumber); |
477 |
$sth->execute($term,$biblionumber); |
|
Lines 484-490
sub add_tag_index {
Link Here
|
| 484 |
} |
484 |
} |
| 485 |
|
485 |
|
| 486 |
sub get_tag { # by tag_id |
486 |
sub get_tag { # by tag_id |
| 487 |
(@_) or return undef; |
487 |
(@_) or return; |
| 488 |
my $sth = C4::Context->dbh->prepare("$select_all WHERE tag_id = ?"); |
488 |
my $sth = C4::Context->dbh->prepare("$select_all WHERE tag_id = ?"); |
| 489 |
$sth->execute(shift); |
489 |
$sth->execute(shift); |
| 490 |
return $sth->fetchrow_hashref; |
490 |
return $sth->fetchrow_hashref; |
|
Lines 505-511
sub rectify_weights {
Link Here
|
| 505 |
} else { |
505 |
} else { |
| 506 |
$sth->execute(); |
506 |
$sth->execute(); |
| 507 |
} |
507 |
} |
| 508 |
my $results = $sth->fetchall_arrayref({}) or return undef; |
508 |
my $results = $sth->fetchall_arrayref({}) or return; |
| 509 |
my %tally = (); |
509 |
my %tally = (); |
| 510 |
foreach (@$results) { |
510 |
foreach (@$results) { |
| 511 |
_set_weight($_->{count},$_->{term},$_->{biblionumber}); |
511 |
_set_weight($_->{count},$_->{term},$_->{biblionumber}); |
|
Lines 557-568
sub _set_weight {
Link Here
|
| 557 |
} |
557 |
} |
| 558 |
|
558 |
|
| 559 |
sub add_tag { # biblionumber,term,[borrowernumber,approvernumber] |
559 |
sub add_tag { # biblionumber,term,[borrowernumber,approvernumber] |
| 560 |
my $biblionumber = shift or return undef; |
560 |
my $biblionumber = shift or return; |
| 561 |
my $term = shift or return undef; |
561 |
my $term = shift or return; |
| 562 |
my $borrowernumber = (@_) ? shift : 0; # the user, default to kohaadmin |
562 |
my $borrowernumber = (@_) ? shift : 0; # the user, default to kohaadmin |
| 563 |
$term =~ s/^\s+//; |
563 |
$term =~ s/^\s+//; |
| 564 |
$term =~ s/\s+$//; |
564 |
$term =~ s/\s+$//; |
| 565 |
($term) or return undef; # must be more than whitespace |
565 |
($term) or return; # must be more than whitespace |
| 566 |
my $rows = get_tag_rows({biblionumber=>$biblionumber, borrowernumber=>$borrowernumber, term=>$term, limit=>1}); |
566 |
my $rows = get_tag_rows({biblionumber=>$biblionumber, borrowernumber=>$borrowernumber, term=>$term, limit=>1}); |
| 567 |
my $query = "INSERT INTO tags_all |
567 |
my $query = "INSERT INTO tags_all |
| 568 |
(borrowernumber,biblionumber,term,date_created) |
568 |
(borrowernumber,biblionumber,term,date_created) |
|
Lines 571-577
sub add_tag { # biblionumber,term,[borrowernumber,approvernumber]
Link Here
|
| 571 |
"add_tag query args: ($borrowernumber,$biblionumber,$term)\n"; |
571 |
"add_tag query args: ($borrowernumber,$biblionumber,$term)\n"; |
| 572 |
if (scalar @$rows) { |
572 |
if (scalar @$rows) { |
| 573 |
$debug and carp "Duplicate tag detected. Tag not added."; |
573 |
$debug and carp "Duplicate tag detected. Tag not added."; |
| 574 |
return undef; |
574 |
return; |
| 575 |
} |
575 |
} |
| 576 |
# add to tags_all regardless of approaval |
576 |
# add to tags_all regardless of approaval |
| 577 |
my $sth = C4::Context->dbh->prepare($query); |
577 |
my $sth = C4::Context->dbh->prepare($query); |
| 578 |
- |
|
|