&searchauthority
&delauthority
&modauthority
+ &SearchDeeper
);
=item newauthority
sub newauthority {
my ($dbh,$category,$stdlib,$freelib,$father,$level,$hierarchy)=@_;
exit unless ($stdlib);
+ $level=1 unless $level;
$freelib = $stdlib unless ($freelib);
my $dbh = C4::Context->dbh;
my $sth1b=$dbh->prepare("select id from bibliothesaurus where freelib=? and hierarchy=? and category=?");
my $id;
if ($#Thierarchy >=0) {
# free form
+ $hierarchy='' unless $hierarchy;
$sth1b->execute($freelib,$hierarchy,$category);
($id) = $sth1b->fetchrow;
unless ($id) {
$Fhierarchy[$#Fhierarchy] =~ s/\s+$// if ($#Fhierarchy>=0);
$freelib =~ s/\s+$//;
$sth2->execute($category,$Thierarchy[$#Thierarchy],$#Fhierarchy==$#Thierarchy?$Fhierarchy[$#Fhierarchy]:$freelib,$father,$level,$hierarchy);
+ } else {
}
# authority form
$sth1b->execute($Thierarchy[$#Thierarchy],$hierarchy,$category);
unless ($id) {
$Thierarchy[$#Thierarchy] =~ s/^\s+//;
$Thierarchy[$#Thierarchy] =~ s/\s+$//;
- $sth2->execute($category,$Thierarchy[$#Thierarchy],$Thierarchy[$#Thierarchy],$father,$level,$hierarchy);
$sth1b->execute($stdlib,$hierarchy,$category);
($id) = $sth1b->fetchrow;
+ unless ($id) {
+ $sth2->execute($category,$Thierarchy[$#Thierarchy],$Thierarchy[$#Thierarchy],$father,$level,$hierarchy);
+ }
}
}
return $id;
=item SearchAuthority
- $id = &SearchAuthority($dbh,$category,$branch,$searchstring,$type,$offset,$pagesize);
+ ($count, \@array) = &SearchAuthority($dbh,$category,$branch,$searchstring,$type,$offset,$pagesize);
searches for an authority
C<$searchstring> contains a string. Only entries beginning by C<$searchstring> are returned
+return :
+C<$count> : the number of authorities found
+C<\@array> : the authorities found. The array contains stdlib,freelib,father,id,hierarchy and level
=cut
sub searchauthority {
$offset=0 unless ($offset);
# warn "==> ($env,$category,$branch,$searchstring,$offset,$pagesize)";
my $dbh = C4::Context->dbh;
- $searchstring=~ s/\'/\\\'/g;
- my $query="Select stdlib,freelib,father,id,hierarchy,level from bibliothesaurus where (category =\"$category\")";
- $query .= " and hierarchy='$branch'" if ($branch);
- $query .= " and match (category,freelib) AGAINST ('$searchstring')" if ($searchstring);
+ my $query="Select stdlib,freelib,father,id,hierarchy,level from bibliothesaurus where category=?";
+ my @bind=($category);
+ if ($branch) {
+ $query .= " and hierarchy=?";
+ push(@bind,$branch);
+ }
+ if ($searchstring) {
+ $query .= " and match (category,freelib) AGAINST (?)";
+ push(@bind,$searchstring);
+ }
# $query .= " and freelib like \"$searchstring%\"" if ($searchstring);
- $query .= " order by category,freelib limit $offset,".($pagesize*4);
- warn "q : $query";
+ $query .= " limit ?,?";
+ push(@bind,$offset,($pagesize*4));
+ warn "q : $query".@bind;
my $sth=$dbh->prepare($query);
- $sth->execute;
+ $sth->execute(@bind);
my @results;
my $old_stdlib="";
while (my $data=$sth->fetchrow_hashref){
push(@results,$data);
}
$sth->finish;
- $query="Select count(*) from bibliothesaurus where (category =\"$category\")";
- $query .= " and hierarchy='$branch'" if ($branch);
- $query .= " and stdlib like \"$searchstring%\"" if ($searchstring);
- $query .= "";
+ $query="Select count(*) from bibliothesaurus where category =?";
+ @bind=($category);
+ if ($branch) {
+ $query .= " and hierarchy=?";
+ push(@bind,$branch);
+ }
+ if ($searchstring) {
+ $query .= " and stdlib like ?";
+ push(@bind,"$searchstring%");
+ }
$sth=$dbh->prepare($query);
- $sth->execute;
+ $sth->execute(@bind);
my ($cnt) = $sth->fetchrow;
$cnt = $pagesize+1 if ($cnt>$pagesize);
- return ($cnt,\@results);
+ $sth->finish();
+ return ($#results,\@results);
+}
+
+=item SearchDeeper
+
+ @array = &SearchAuthority($dbh,$category,$father);
+
+ Finds everything depending on the parameter.
+
+C<$dbh> is a DBI::db handle for the Koha database.
+
+C<$category> is the category of the authority
+
+C<$father> Is the string "father".
+
+return :
+@array : the authorities found. The array contains stdlib,freelib,father,id,hierarchy and level
+
+For example :
+Geography -- Europe is the father and the result is : France and Germany if there is
+Geography -- Europe -- France and Geography -- Europe -- Germany in the thesaurus
+
+
+=cut
+sub SearchDeeper {
+ my ($category,$father)=@_;
+ my $dbh = C4::Context->dbh;
+ my $sth=$dbh->prepare("Select distinct level,stdlib,father from bibliothesaurus where category =? and father =? order by category,stdlib");
+ $sth->execute($category,"$father --");
+ my @results;
+ while (my ($level,$stdlib,$father)=$sth->fetchrow){
+ my %line;
+ $line{level} = $level;
+ $line{stdlib}= $stdlib;
+ $line{father} = $father;
+ push(@results,\%line);
+ }
+ $sth->finish;
+ return (@results);
}