Lines 25-30
use Exporter;
Link Here
|
25 |
|
25 |
|
26 |
use C4::Context; |
26 |
use C4::Context; |
27 |
use C4::Debug; |
27 |
use C4::Debug; |
|
|
28 |
#use Data::Dumper; |
28 |
|
29 |
|
29 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
30 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
30 |
use vars qw($ext_dict $select_all @fields); |
31 |
use vars qw($ext_dict $select_all @fields); |
Lines 67-73
INIT {
Link Here
|
67 |
$select_all = "SELECT " . join(',',@fields) . "\n FROM tags_all\n"; |
68 |
$select_all = "SELECT " . join(',',@fields) . "\n FROM tags_all\n"; |
68 |
} |
69 |
} |
69 |
|
70 |
|
70 |
sub get_filters (;$) { |
71 |
sub get_filters { |
71 |
my $query = "SELECT * FROM tags_filters "; |
72 |
my $query = "SELECT * FROM tags_filters "; |
72 |
my ($sth); |
73 |
my ($sth); |
73 |
if (@_) { |
74 |
if (@_) { |
Lines 83-89
sub get_filters (;$) {
Link Here
|
83 |
# (SELECT count(*) FROM tags_all ) as tags_all, |
84 |
# (SELECT count(*) FROM tags_all ) as tags_all, |
84 |
# (SELECT count(*) FROM tags_index ) as tags_index, |
85 |
# (SELECT count(*) FROM tags_index ) as tags_index, |
85 |
|
86 |
|
86 |
sub approval_counts () { |
87 |
sub approval_counts { |
87 |
my $query = "SELECT |
88 |
my $query = "SELECT |
88 |
(SELECT count(*) FROM tags_approval WHERE approved= 1) as approved_count, |
89 |
(SELECT count(*) FROM tags_approval WHERE approved= 1) as approved_count, |
89 |
(SELECT count(*) FROM tags_approval WHERE approved=-1) as rejected_count, |
90 |
(SELECT count(*) FROM tags_approval WHERE approved=-1) as rejected_count, |
Lines 115-121
sub get_count_by_tag_status {
Link Here
|
115 |
return $sth->fetchrow; |
116 |
return $sth->fetchrow; |
116 |
} |
117 |
} |
117 |
|
118 |
|
118 |
sub remove_tag ($;$) { |
119 |
sub remove_tag { |
119 |
my $tag_id = shift or return undef; |
120 |
my $tag_id = shift or return undef; |
120 |
my $user_id = (@_) ? shift : undef; |
121 |
my $user_id = (@_) ? shift : undef; |
121 |
my $rows = (defined $user_id) ? |
122 |
my $rows = (defined $user_id) ? |
Lines 143-167
sub remove_tag ($;$) {
Link Here
|
143 |
delete_tag_row_by_id($tag_id); |
144 |
delete_tag_row_by_id($tag_id); |
144 |
} |
145 |
} |
145 |
|
146 |
|
146 |
sub delete_tag_index ($$) { |
147 |
sub delete_tag_index { |
147 |
(@_) or return undef; |
148 |
(@_) or return undef; |
148 |
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"); |
149 |
$sth->execute(@_); |
150 |
$sth->execute(@_); |
150 |
return $sth->rows || 0; |
151 |
return $sth->rows || 0; |
151 |
} |
152 |
} |
152 |
sub delete_tag_approval ($) { |
153 |
sub delete_tag_approval { |
153 |
(@_) or return undef; |
154 |
(@_) or return undef; |
154 |
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"); |
155 |
$sth->execute(shift); |
156 |
$sth->execute(shift); |
156 |
return $sth->rows || 0; |
157 |
return $sth->rows || 0; |
157 |
} |
158 |
} |
158 |
sub delete_tag_row_by_id ($) { |
159 |
sub delete_tag_row_by_id { |
159 |
(@_) or return undef; |
160 |
(@_) or return undef; |
160 |
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"); |
161 |
$sth->execute(shift); |
162 |
$sth->execute(shift); |
162 |
return $sth->rows || 0; |
163 |
return $sth->rows || 0; |
163 |
} |
164 |
} |
164 |
sub delete_tag_rows_by_ids (@) { |
165 |
sub delete_tag_rows_by_ids { |
165 |
(@_) or return undef; |
166 |
(@_) or return undef; |
166 |
my $i=0; |
167 |
my $i=0; |
167 |
foreach(@_) { |
168 |
foreach(@_) { |
Lines 172-178
sub delete_tag_rows_by_ids (@) {
Link Here
|
172 |
return $i; |
173 |
return $i; |
173 |
} |
174 |
} |
174 |
|
175 |
|
175 |
sub get_tag_rows ($) { |
176 |
sub get_tag_rows { |
176 |
my $hash = shift || {}; |
177 |
my $hash = shift || {}; |
177 |
my @ok_fields = @fields; |
178 |
my @ok_fields = @fields; |
178 |
push @ok_fields, 'limit'; # push the limit! :) |
179 |
push @ok_fields, 'limit'; # push the limit! :) |
Lines 213-219
sub get_tag_rows ($) {
Link Here
|
213 |
return $sth->fetchall_arrayref({}); |
214 |
return $sth->fetchall_arrayref({}); |
214 |
} |
215 |
} |
215 |
|
216 |
|
216 |
sub get_tags (;$) { # i.e., from tags_index |
217 |
sub get_tags { # i.e., from tags_index |
217 |
my $hash = shift || {}; |
218 |
my $hash = shift || {}; |
218 |
my @ok_fields = qw(term biblionumber weight limit sort approved); |
219 |
my @ok_fields = qw(term biblionumber weight limit sort approved); |
219 |
my $wheres; |
220 |
my $wheres; |
Lines 282-288
sub get_tags (;$) { # i.e., from tags_index
Link Here
|
282 |
return $sth->fetchall_arrayref({}); |
283 |
return $sth->fetchall_arrayref({}); |
283 |
} |
284 |
} |
284 |
|
285 |
|
285 |
sub get_approval_rows (;$) { # i.e., from tags_approval |
286 |
sub get_approval_rows { # i.e., from tags_approval |
286 |
my $hash = shift || {}; |
287 |
my $hash = shift || {}; |
287 |
my @ok_fields = qw(term approved date_approved approved_by weight_total limit sort borrowernumber); |
288 |
my @ok_fields = qw(term approved date_approved approved_by weight_total limit sort borrowernumber); |
288 |
my $wheres; |
289 |
my $wheres; |
Lines 357-363
sub get_approval_rows (;$) { # i.e., from tags_approval
Link Here
|
357 |
return $sth->fetchall_arrayref({}); |
358 |
return $sth->fetchall_arrayref({}); |
358 |
} |
359 |
} |
359 |
|
360 |
|
360 |
sub is_approved ($) { |
361 |
sub is_approved { |
361 |
my $term = shift or return undef; |
362 |
my $term = shift or return undef; |
362 |
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 = ?"); |
363 |
$sth->execute($term); |
364 |
$sth->execute($term); |
Lines 368-374
sub is_approved ($) {
Link Here
|
368 |
return $sth->fetchrow; |
369 |
return $sth->fetchrow; |
369 |
} |
370 |
} |
370 |
|
371 |
|
371 |
sub get_tag_index ($;$) { |
372 |
sub get_tag_index { |
372 |
my $term = shift or return undef; |
373 |
my $term = shift or return undef; |
373 |
my $sth; |
374 |
my $sth; |
374 |
if (@_) { |
375 |
if (@_) { |
Lines 432-438
sub remove_filter {
Link Here
|
432 |
return scalar @_; |
433 |
return scalar @_; |
433 |
} |
434 |
} |
434 |
|
435 |
|
435 |
sub add_tag_approval ($;$$) { # or disapproval |
436 |
sub add_tag_approval { # or disapproval |
436 |
$debug and warn "add_tag_approval(" . join(", ",map {defined($_) ? $_ : 'UNDEF'} @_) . ")"; |
437 |
$debug and warn "add_tag_approval(" . join(", ",map {defined($_) ? $_ : 'UNDEF'} @_) . ")"; |
437 |
my $term = shift or return undef; |
438 |
my $term = shift or return undef; |
438 |
my $query = "SELECT * FROM tags_approval WHERE term = ?"; |
439 |
my $query = "SELECT * FROM tags_approval WHERE term = ?"; |
Lines 457-463
sub add_tag_approval ($;$$) { # or disapproval
Link Here
|
457 |
return $sth->rows; |
458 |
return $sth->rows; |
458 |
} |
459 |
} |
459 |
|
460 |
|
460 |
sub mod_tag_approval ($$$) { |
461 |
sub mod_tag_approval { |
461 |
my $operator = shift; |
462 |
my $operator = shift; |
462 |
defined $operator or return undef; # have to test defined to allow =0 (kohaadmin) |
463 |
defined $operator or return undef; # have to test defined to allow =0 (kohaadmin) |
463 |
my $term = shift or return undef; |
464 |
my $term = shift or return undef; |
Lines 468-474
sub mod_tag_approval ($$$) {
Link Here
|
468 |
$sth->execute($operator,$approval,$term); |
469 |
$sth->execute($operator,$approval,$term); |
469 |
} |
470 |
} |
470 |
|
471 |
|
471 |
sub add_tag_index ($$;$) { |
472 |
sub add_tag_index { |
472 |
my $term = shift or return undef; |
473 |
my $term = shift or return undef; |
473 |
my $biblionumber = shift or return undef; |
474 |
my $biblionumber = shift or return undef; |
474 |
my $query = "SELECT * FROM tags_index WHERE term = ? AND biblionumber = ?"; |
475 |
my $query = "SELECT * FROM tags_index WHERE term = ? AND biblionumber = ?"; |
Lines 482-495
sub add_tag_index ($$;$) {
Link Here
|
482 |
return $sth->rows; |
483 |
return $sth->rows; |
483 |
} |
484 |
} |
484 |
|
485 |
|
485 |
sub get_tag ($) { # by tag_id |
486 |
sub get_tag { # by tag_id |
486 |
(@_) or return undef; |
487 |
(@_) or return undef; |
487 |
my $sth = C4::Context->dbh->prepare("$select_all WHERE tag_id = ?"); |
488 |
my $sth = C4::Context->dbh->prepare("$select_all WHERE tag_id = ?"); |
488 |
$sth->execute(shift); |
489 |
$sth->execute(shift); |
489 |
return $sth->fetchrow_hashref; |
490 |
return $sth->fetchrow_hashref; |
490 |
} |
491 |
} |
491 |
|
492 |
|
492 |
sub rectify_weights (;$) { |
493 |
sub rectify_weights { |
493 |
my $dbh = C4::Context->dbh; |
494 |
my $dbh = C4::Context->dbh; |
494 |
my $sth; |
495 |
my $sth; |
495 |
my $query = " |
496 |
my $query = " |
Lines 516-542
sub rectify_weights (;$) {
Link Here
|
516 |
return ($results,\%tally); |
517 |
return ($results,\%tally); |
517 |
} |
518 |
} |
518 |
|
519 |
|
519 |
sub increment_weights ($$) { |
520 |
sub increment_weights { |
520 |
increment_weight(@_); |
521 |
increment_weight(@_); |
521 |
increment_weight_total(shift); |
522 |
increment_weight_total(shift); |
522 |
} |
523 |
} |
523 |
sub decrement_weights ($$) { |
524 |
sub decrement_weights { |
524 |
decrement_weight(@_); |
525 |
decrement_weight(@_); |
525 |
decrement_weight_total(shift); |
526 |
decrement_weight_total(shift); |
526 |
} |
527 |
} |
527 |
sub increment_weight_total ($) { |
528 |
sub increment_weight_total { |
528 |
_set_weight_total('weight_total+1',shift); |
529 |
_set_weight_total('weight_total+1',shift); |
529 |
} |
530 |
} |
530 |
sub increment_weight ($$) { |
531 |
sub increment_weight { |
531 |
_set_weight('weight+1',shift,shift); |
532 |
_set_weight('weight+1',shift,shift); |
532 |
} |
533 |
} |
533 |
sub decrement_weight_total ($) { |
534 |
sub decrement_weight_total { |
534 |
_set_weight_total('weight_total-1',shift); |
535 |
_set_weight_total('weight_total-1',shift); |
535 |
} |
536 |
} |
536 |
sub decrement_weight ($$) { |
537 |
sub decrement_weight { |
537 |
_set_weight('weight-1',shift,shift); |
538 |
_set_weight('weight-1',shift,shift); |
538 |
} |
539 |
} |
539 |
sub _set_weight_total ($$) { |
540 |
sub _set_weight_total { |
540 |
my $sth = C4::Context->dbh->prepare(" |
541 |
my $sth = C4::Context->dbh->prepare(" |
541 |
UPDATE tags_approval |
542 |
UPDATE tags_approval |
542 |
SET weight_total=" . (shift) . " |
543 |
SET weight_total=" . (shift) . " |
Lines 544-550
sub _set_weight_total ($$) {
Link Here
|
544 |
"); # note: CANNOT use "?" for weight_total (see the args above). |
545 |
"); # note: CANNOT use "?" for weight_total (see the args above). |
545 |
$sth->execute(shift); # just the term |
546 |
$sth->execute(shift); # just the term |
546 |
} |
547 |
} |
547 |
sub _set_weight ($$$) { |
548 |
sub _set_weight { |
548 |
my $dbh = C4::Context->dbh; |
549 |
my $dbh = C4::Context->dbh; |
549 |
my $sth = $dbh->prepare(" |
550 |
my $sth = $dbh->prepare(" |
550 |
UPDATE tags_index |
551 |
UPDATE tags_index |
Lines 555-561
sub _set_weight ($$$) {
Link Here
|
555 |
$sth->execute(@_); |
556 |
$sth->execute(@_); |
556 |
} |
557 |
} |
557 |
|
558 |
|
558 |
sub add_tag ($$;$$) { # biblionumber,term,[borrowernumber,approvernumber] |
559 |
sub add_tag { # biblionumber,term,[borrowernumber,approvernumber] |
559 |
my $biblionumber = shift or return undef; |
560 |
my $biblionumber = shift or return undef; |
560 |
my $term = shift or return undef; |
561 |
my $term = shift or return undef; |
561 |
my $borrowernumber = (@_) ? shift : 0; # the user, default to kohaadmin |
562 |
my $borrowernumber = (@_) ? shift : 0; # the user, default to kohaadmin |
562 |
- |
|
|