|
Lines 21-26
use Exporter;
Link Here
|
| 21 |
|
21 |
|
| 22 |
use C4::Context; |
22 |
use C4::Context; |
| 23 |
use C4::Debug; |
23 |
use C4::Debug; |
|
|
24 |
#use Data::Dumper; |
| 24 |
|
25 |
|
| 25 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
26 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
| 26 |
use vars qw($ext_dict $select_all @fields); |
27 |
use vars qw($ext_dict $select_all @fields); |
|
Lines 63-69
INIT {
Link Here
|
| 63 |
$select_all = "SELECT " . join(',',@fields) . "\n FROM tags_all\n"; |
64 |
$select_all = "SELECT " . join(',',@fields) . "\n FROM tags_all\n"; |
| 64 |
} |
65 |
} |
| 65 |
|
66 |
|
| 66 |
sub get_filters (;$) { |
67 |
sub get_filters { |
| 67 |
my $query = "SELECT * FROM tags_filters "; |
68 |
my $query = "SELECT * FROM tags_filters "; |
| 68 |
my ($sth); |
69 |
my ($sth); |
| 69 |
if (@_) { |
70 |
if (@_) { |
|
Lines 79-85
sub get_filters (;$) {
Link Here
|
| 79 |
# (SELECT count(*) FROM tags_all ) as tags_all, |
80 |
# (SELECT count(*) FROM tags_all ) as tags_all, |
| 80 |
# (SELECT count(*) FROM tags_index ) as tags_index, |
81 |
# (SELECT count(*) FROM tags_index ) as tags_index, |
| 81 |
|
82 |
|
| 82 |
sub approval_counts () { |
83 |
sub approval_counts { |
| 83 |
my $query = "SELECT |
84 |
my $query = "SELECT |
| 84 |
(SELECT count(*) FROM tags_approval WHERE approved= 1) as approved_count, |
85 |
(SELECT count(*) FROM tags_approval WHERE approved= 1) as approved_count, |
| 85 |
(SELECT count(*) FROM tags_approval WHERE approved=-1) as rejected_count, |
86 |
(SELECT count(*) FROM tags_approval WHERE approved=-1) as rejected_count, |
|
Lines 111-117
sub get_count_by_tag_status {
Link Here
|
| 111 |
return $sth->fetchrow; |
112 |
return $sth->fetchrow; |
| 112 |
} |
113 |
} |
| 113 |
|
114 |
|
| 114 |
sub remove_tag ($;$) { |
115 |
sub remove_tag { |
| 115 |
my $tag_id = shift or return undef; |
116 |
my $tag_id = shift or return undef; |
| 116 |
my $user_id = (@_) ? shift : undef; |
117 |
my $user_id = (@_) ? shift : undef; |
| 117 |
my $rows = (defined $user_id) ? |
118 |
my $rows = (defined $user_id) ? |
|
Lines 139-163
sub remove_tag ($;$) {
Link Here
|
| 139 |
delete_tag_row_by_id($tag_id); |
140 |
delete_tag_row_by_id($tag_id); |
| 140 |
} |
141 |
} |
| 141 |
|
142 |
|
| 142 |
sub delete_tag_index ($$) { |
143 |
sub delete_tag_index { |
| 143 |
(@_) or return undef; |
144 |
(@_) or return undef; |
| 144 |
my $sth = C4::Context->dbh->prepare("DELETE FROM tags_index WHERE term = ? AND biblionumber = ? LIMIT 1"); |
145 |
my $sth = C4::Context->dbh->prepare("DELETE FROM tags_index WHERE term = ? AND biblionumber = ? LIMIT 1"); |
| 145 |
$sth->execute(@_); |
146 |
$sth->execute(@_); |
| 146 |
return $sth->rows || 0; |
147 |
return $sth->rows || 0; |
| 147 |
} |
148 |
} |
| 148 |
sub delete_tag_approval ($) { |
149 |
sub delete_tag_approval { |
| 149 |
(@_) or return undef; |
150 |
(@_) or return undef; |
| 150 |
my $sth = C4::Context->dbh->prepare("DELETE FROM tags_approval WHERE term = ? LIMIT 1"); |
151 |
my $sth = C4::Context->dbh->prepare("DELETE FROM tags_approval WHERE term = ? LIMIT 1"); |
| 151 |
$sth->execute(shift); |
152 |
$sth->execute(shift); |
| 152 |
return $sth->rows || 0; |
153 |
return $sth->rows || 0; |
| 153 |
} |
154 |
} |
| 154 |
sub delete_tag_row_by_id ($) { |
155 |
sub delete_tag_row_by_id { |
| 155 |
(@_) or return undef; |
156 |
(@_) or return undef; |
| 156 |
my $sth = C4::Context->dbh->prepare("DELETE FROM tags_all WHERE tag_id = ? LIMIT 1"); |
157 |
my $sth = C4::Context->dbh->prepare("DELETE FROM tags_all WHERE tag_id = ? LIMIT 1"); |
| 157 |
$sth->execute(shift); |
158 |
$sth->execute(shift); |
| 158 |
return $sth->rows || 0; |
159 |
return $sth->rows || 0; |
| 159 |
} |
160 |
} |
| 160 |
sub delete_tag_rows_by_ids (@) { |
161 |
sub delete_tag_rows_by_ids { |
| 161 |
(@_) or return undef; |
162 |
(@_) or return undef; |
| 162 |
my $i=0; |
163 |
my $i=0; |
| 163 |
foreach(@_) { |
164 |
foreach(@_) { |
|
Lines 168-174
sub delete_tag_rows_by_ids (@) {
Link Here
|
| 168 |
return $i; |
169 |
return $i; |
| 169 |
} |
170 |
} |
| 170 |
|
171 |
|
| 171 |
sub get_tag_rows ($) { |
172 |
sub get_tag_rows { |
| 172 |
my $hash = shift || {}; |
173 |
my $hash = shift || {}; |
| 173 |
my @ok_fields = @fields; |
174 |
my @ok_fields = @fields; |
| 174 |
push @ok_fields, 'limit'; # push the limit! :) |
175 |
push @ok_fields, 'limit'; # push the limit! :) |
|
Lines 209-215
sub get_tag_rows ($) {
Link Here
|
| 209 |
return $sth->fetchall_arrayref({}); |
210 |
return $sth->fetchall_arrayref({}); |
| 210 |
} |
211 |
} |
| 211 |
|
212 |
|
| 212 |
sub get_tags (;$) { # i.e., from tags_index |
213 |
sub get_tags { # i.e., from tags_index |
| 213 |
my $hash = shift || {}; |
214 |
my $hash = shift || {}; |
| 214 |
my @ok_fields = qw(term biblionumber weight limit sort approved); |
215 |
my @ok_fields = qw(term biblionumber weight limit sort approved); |
| 215 |
my $wheres; |
216 |
my $wheres; |
|
Lines 278-284
sub get_tags (;$) { # i.e., from tags_index
Link Here
|
| 278 |
return $sth->fetchall_arrayref({}); |
279 |
return $sth->fetchall_arrayref({}); |
| 279 |
} |
280 |
} |
| 280 |
|
281 |
|
| 281 |
sub get_approval_rows (;$) { # i.e., from tags_approval |
282 |
sub get_approval_rows { # i.e., from tags_approval |
| 282 |
my $hash = shift || {}; |
283 |
my $hash = shift || {}; |
| 283 |
my @ok_fields = qw(term approved date_approved approved_by weight_total limit sort borrowernumber); |
284 |
my @ok_fields = qw(term approved date_approved approved_by weight_total limit sort borrowernumber); |
| 284 |
my $wheres; |
285 |
my $wheres; |
|
Lines 353-359
sub get_approval_rows (;$) { # i.e., from tags_approval
Link Here
|
| 353 |
return $sth->fetchall_arrayref({}); |
354 |
return $sth->fetchall_arrayref({}); |
| 354 |
} |
355 |
} |
| 355 |
|
356 |
|
| 356 |
sub is_approved ($) { |
357 |
sub is_approved { |
| 357 |
my $term = shift or return undef; |
358 |
my $term = shift or return undef; |
| 358 |
my $sth = C4::Context->dbh->prepare("SELECT approved FROM tags_approval WHERE term = ?"); |
359 |
my $sth = C4::Context->dbh->prepare("SELECT approved FROM tags_approval WHERE term = ?"); |
| 359 |
$sth->execute($term); |
360 |
$sth->execute($term); |
|
Lines 364-370
sub is_approved ($) {
Link Here
|
| 364 |
return $sth->fetchrow; |
365 |
return $sth->fetchrow; |
| 365 |
} |
366 |
} |
| 366 |
|
367 |
|
| 367 |
sub get_tag_index ($;$) { |
368 |
sub get_tag_index { |
| 368 |
my $term = shift or return undef; |
369 |
my $term = shift or return undef; |
| 369 |
my $sth; |
370 |
my $sth; |
| 370 |
if (@_) { |
371 |
if (@_) { |
|
Lines 428-434
sub remove_filter {
Link Here
|
| 428 |
return scalar @_; |
429 |
return scalar @_; |
| 429 |
} |
430 |
} |
| 430 |
|
431 |
|
| 431 |
sub add_tag_approval ($;$$) { # or disapproval |
432 |
sub add_tag_approval { # or disapproval |
| 432 |
$debug and warn "add_tag_approval(" . join(", ",map {defined($_) ? $_ : 'UNDEF'} @_) . ")"; |
433 |
$debug and warn "add_tag_approval(" . join(", ",map {defined($_) ? $_ : 'UNDEF'} @_) . ")"; |
| 433 |
my $term = shift or return undef; |
434 |
my $term = shift or return undef; |
| 434 |
my $query = "SELECT * FROM tags_approval WHERE term = ?"; |
435 |
my $query = "SELECT * FROM tags_approval WHERE term = ?"; |
|
Lines 453-459
sub add_tag_approval ($;$$) { # or disapproval
Link Here
|
| 453 |
return $sth->rows; |
454 |
return $sth->rows; |
| 454 |
} |
455 |
} |
| 455 |
|
456 |
|
| 456 |
sub mod_tag_approval ($$$) { |
457 |
sub mod_tag_approval { |
| 457 |
my $operator = shift; |
458 |
my $operator = shift; |
| 458 |
defined $operator or return undef; # have to test defined to allow =0 (kohaadmin) |
459 |
defined $operator or return undef; # have to test defined to allow =0 (kohaadmin) |
| 459 |
my $term = shift or return undef; |
460 |
my $term = shift or return undef; |
|
Lines 464-470
sub mod_tag_approval ($$$) {
Link Here
|
| 464 |
$sth->execute($operator,$approval,$term); |
465 |
$sth->execute($operator,$approval,$term); |
| 465 |
} |
466 |
} |
| 466 |
|
467 |
|
| 467 |
sub add_tag_index ($$;$) { |
468 |
sub add_tag_index { |
| 468 |
my $term = shift or return undef; |
469 |
my $term = shift or return undef; |
| 469 |
my $biblionumber = shift or return undef; |
470 |
my $biblionumber = shift or return undef; |
| 470 |
my $query = "SELECT * FROM tags_index WHERE term = ? AND biblionumber = ?"; |
471 |
my $query = "SELECT * FROM tags_index WHERE term = ? AND biblionumber = ?"; |
|
Lines 478-491
sub add_tag_index ($$;$) {
Link Here
|
| 478 |
return $sth->rows; |
479 |
return $sth->rows; |
| 479 |
} |
480 |
} |
| 480 |
|
481 |
|
| 481 |
sub get_tag ($) { # by tag_id |
482 |
sub get_tag { # by tag_id |
| 482 |
(@_) or return undef; |
483 |
(@_) or return undef; |
| 483 |
my $sth = C4::Context->dbh->prepare("$select_all WHERE tag_id = ?"); |
484 |
my $sth = C4::Context->dbh->prepare("$select_all WHERE tag_id = ?"); |
| 484 |
$sth->execute(shift); |
485 |
$sth->execute(shift); |
| 485 |
return $sth->fetchrow_hashref; |
486 |
return $sth->fetchrow_hashref; |
| 486 |
} |
487 |
} |
| 487 |
|
488 |
|
| 488 |
sub rectify_weights (;$) { |
489 |
sub rectify_weights { |
| 489 |
my $dbh = C4::Context->dbh; |
490 |
my $dbh = C4::Context->dbh; |
| 490 |
my $sth; |
491 |
my $sth; |
| 491 |
my $query = " |
492 |
my $query = " |
|
Lines 512-538
sub rectify_weights (;$) {
Link Here
|
| 512 |
return ($results,\%tally); |
513 |
return ($results,\%tally); |
| 513 |
} |
514 |
} |
| 514 |
|
515 |
|
| 515 |
sub increment_weights ($$) { |
516 |
sub increment_weights { |
| 516 |
increment_weight(@_); |
517 |
increment_weight(@_); |
| 517 |
increment_weight_total(shift); |
518 |
increment_weight_total(shift); |
| 518 |
} |
519 |
} |
| 519 |
sub decrement_weights ($$) { |
520 |
sub decrement_weights { |
| 520 |
decrement_weight(@_); |
521 |
decrement_weight(@_); |
| 521 |
decrement_weight_total(shift); |
522 |
decrement_weight_total(shift); |
| 522 |
} |
523 |
} |
| 523 |
sub increment_weight_total ($) { |
524 |
sub increment_weight_total { |
| 524 |
_set_weight_total('weight_total+1',shift); |
525 |
_set_weight_total('weight_total+1',shift); |
| 525 |
} |
526 |
} |
| 526 |
sub increment_weight ($$) { |
527 |
sub increment_weight { |
| 527 |
_set_weight('weight+1',shift,shift); |
528 |
_set_weight('weight+1',shift,shift); |
| 528 |
} |
529 |
} |
| 529 |
sub decrement_weight_total ($) { |
530 |
sub decrement_weight_total { |
| 530 |
_set_weight_total('weight_total-1',shift); |
531 |
_set_weight_total('weight_total-1',shift); |
| 531 |
} |
532 |
} |
| 532 |
sub decrement_weight ($$) { |
533 |
sub decrement_weight { |
| 533 |
_set_weight('weight-1',shift,shift); |
534 |
_set_weight('weight-1',shift,shift); |
| 534 |
} |
535 |
} |
| 535 |
sub _set_weight_total ($$) { |
536 |
sub _set_weight_total { |
| 536 |
my $sth = C4::Context->dbh->prepare(" |
537 |
my $sth = C4::Context->dbh->prepare(" |
| 537 |
UPDATE tags_approval |
538 |
UPDATE tags_approval |
| 538 |
SET weight_total=" . (shift) . " |
539 |
SET weight_total=" . (shift) . " |
|
Lines 540-546
sub _set_weight_total ($$) {
Link Here
|
| 540 |
"); # note: CANNOT use "?" for weight_total (see the args above). |
541 |
"); # note: CANNOT use "?" for weight_total (see the args above). |
| 541 |
$sth->execute(shift); # just the term |
542 |
$sth->execute(shift); # just the term |
| 542 |
} |
543 |
} |
| 543 |
sub _set_weight ($$$) { |
544 |
sub _set_weight { |
| 544 |
my $dbh = C4::Context->dbh; |
545 |
my $dbh = C4::Context->dbh; |
| 545 |
my $sth = $dbh->prepare(" |
546 |
my $sth = $dbh->prepare(" |
| 546 |
UPDATE tags_index |
547 |
UPDATE tags_index |
|
Lines 551-557
sub _set_weight ($$$) {
Link Here
|
| 551 |
$sth->execute(@_); |
552 |
$sth->execute(@_); |
| 552 |
} |
553 |
} |
| 553 |
|
554 |
|
| 554 |
sub add_tag ($$;$$) { # biblionumber,term,[borrowernumber,approvernumber] |
555 |
sub add_tag { # biblionumber,term,[borrowernumber,approvernumber] |
| 555 |
my $biblionumber = shift or return undef; |
556 |
my $biblionumber = shift or return undef; |
| 556 |
my $term = shift or return undef; |
557 |
my $term = shift or return undef; |
| 557 |
my $borrowernumber = (@_) ? shift : 0; # the user, default to kohaadmin |
558 |
my $borrowernumber = (@_) ? shift : 0; # the user, default to kohaadmin |