koha-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Koha-cvs] koha authorities/detail.pl C4/AuthoritiesMarc.p... [rel_3_0]


From: Henri-Damien LAURENT
Subject: [Koha-cvs] koha authorities/detail.pl C4/AuthoritiesMarc.p... [rel_3_0]
Date: Wed, 10 Jan 2007 14:40:12 +0000

CVSROOT:        /cvsroot/koha
Module name:    koha
Branch:         rel_3_0
Changes by:     Henri-Damien LAURENT <hdl>      07/01/10 14:40:12

Modified files:
        authorities    : detail.pl 
        C4             : AuthoritiesMarc.pm 
        koha-tmpl/intranet-tmpl/prog/en/authorities: detail.tmpl 
Added files:
        koha-tmpl/intranet-tmpl/prog/en/includes: hierarchy.css 

Log message:
        Adding Authorities tree.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/authorities/detail.pl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.4.2.2&r2=1.4.2.3
http://cvs.savannah.gnu.org/viewcvs/koha/C4/AuthoritiesMarc.pm?cvsroot=koha&only_with_tag=rel_3_0&r1=1.28.2.13&r2=1.28.2.14
http://cvs.savannah.gnu.org/viewcvs/koha/koha-tmpl/intranet-tmpl/prog/en/authorities/detail.tmpl?cvsroot=koha&only_with_tag=rel_3_0&r1=1.1.2.2&r2=1.1.2.3
http://cvs.savannah.gnu.org/viewcvs/koha/koha-tmpl/intranet-tmpl/prog/en/includes/hierarchy.css?cvsroot=koha&only_with_tag=rel_3_0&rev=1.1.2.1

Patches:
Index: authorities/detail.pl
===================================================================
RCS file: /cvsroot/koha/koha/authorities/detail.pl,v
retrieving revision 1.4.2.2
retrieving revision 1.4.2.3
diff -u -b -r1.4.2.2 -r1.4.2.3
--- authorities/detail.pl       18 Dec 2006 16:35:17 -0000      1.4.2.2
+++ authorities/detail.pl       10 Jan 2007 14:40:11 -0000      1.4.2.3
@@ -56,11 +56,50 @@
 
 my $dbh=C4::Context->dbh;
 
+# open template
+my ($template, $loggedinuser, $cookie)
+               = get_template_and_user({template_name => 
"authorities/detail.tmpl",
+                            query => $query,
+                            type => "intranet",
+                            authnotrequired => 0,
+                            flagsrequired => {catalogue => 1},
+                            debug => 1,
+                            });
+
 my $authid = $query->param('authid');
+
+
+
 my $authtypecode = &AUTHfind_authtypecode($dbh,$authid);
 my $tagslib = &AUTHgettagslib($dbh,1,$authtypecode);
 
-my $record =AUTHgetauthority($dbh,$authid);
+my $record;
+if (C4::Context->preference("AuthDisplayHierarchy")){
+  my $trees=BuildUnimarcHierarchies($authid);
+  my @trees = split /;/,$trees ;
+  push @trees,$trees unless (@trees);
+  my @loophierarchies;
+  foreach my $tree (@trees){
+    my @tree=split /,/,$tree;
+    push @tree,$tree unless (@tree);
+    my $cnt=0;
+    my @loophierarchy;
+    foreach my $element (@tree){
+      my %cell;
+      my $elementdata = AUTHgetauthority($dbh,$element);
+      $record= $elementdata if ($authid==$element);
+      push @loophierarchy, BuildUnimarcHierarchy($elementdata,"child".$cnt, 
$authid);
+      $cnt++;
+    }
+    push @loophierarchies, { 'loopelement' =>address@hidden;
+  }
+  $template->param(
+    'displayhierarchy' =>C4::Context->preference("AuthDisplayHierarchy"),
+    'loophierarchies' =>address@hidden,
+  );
+} else {
+  $record=AUTHgetauthority($dbh,$authid);
+}
 my $count = AUTHcount_usage($authid);
 
 # find the marc field/subfield used in biblio by this authority
@@ -72,15 +111,6 @@
 }
 chop $biblio_fields;
 
-# open template
-my ($template, $loggedinuser, $cookie)
-               = get_template_and_user({template_name => 
"authorities/detail.tmpl",
-                            query => $query,
-                            type => "intranet",
-                            authnotrequired => 0,
-                            flagsrequired => {catalogue => 1},
-                            debug => 1,
-                            });
 
 # fill arrays
 my @loop_data =();

Index: C4/AuthoritiesMarc.pm
===================================================================
RCS file: /cvsroot/koha/koha/C4/AuthoritiesMarc.pm,v
retrieving revision 1.28.2.13
retrieving revision 1.28.2.14
diff -u -b -r1.28.2.13 -r1.28.2.14
--- C4/AuthoritiesMarc.pm       9 Jan 2007 15:18:09 -0000       1.28.2.13
+++ C4/AuthoritiesMarc.pm       10 Jan 2007 14:40:11 -0000      1.28.2.14
@@ -47,7 +47,8 @@
     &XMLgetauthority
     
     &AUTHhtml2marc
-    
+    &BuildUnimarcHierarchies
+    &BuildUnimarcHierarchy
     &merge
     &FindDuplicate
  );
@@ -764,6 +765,98 @@
         }
 return $summary;
 }
+sub BuildUnimarcHierarchies{
+  my $authid = shift @_;
+#   warn "authid : $authid";
+  my $force = shift @_;
+  my @globalresult;
+  my $dbh=C4::Context->dbh;
+  my $hierarchies;
+  my $data = AUTHgetheader($dbh,$authid);
+  
+  if ($data->{'authtrees'} and not $force){
+    return $data->{'authtrees'};
+  } elsif ($data->{'authtrees'}){
+    $hierarchies=$data->{'authtrees'};
+  } else {
+    my $record = AUTHgetauthority($dbh,$authid);
+    my $found;
+    foreach my $field ($record->field('550')){
+      if ($field->subfield('5') && $field->subfield('5') eq 'g'){
+        my $parentrecord = AUTHgetauthority($dbh,$field->subfield('3'));
+        my $localresult=$hierarchies;
+        my $trees;
+        $trees = BuildUnimarcHierarchies($field->subfield('3'));
+        my @trees;
+        if ($trees=~/;/){
+           @trees = split(/;/,$trees);
+        } else {
+           push @trees, $trees;
+        }
+        foreach (@trees){
+          $_.= ",$authid";
+        }
+        @globalresult = (@globalresult,@trees);
+        $found=1;
+      }
+      $hierarchies=join(";",@globalresult);
+    }
+    #Unless there is no ancestor, I am alone.
+    $hierarchies="$authid" unless ($hierarchies);
+  }
+  AUTHsavetrees($authid,$hierarchies);
+  return $hierarchies;
+}
+
+sub BuildUnimarcHierarchy{
+       my $record = shift @_;
+    my $class = shift @_;
+    my $authid_constructed = shift @_;
+       my $authid=$record->subfield('250','3');
+    my %cell;
+       my $parents=""; my $children="";
+    my (@loopparents,@loopchildren);
+       foreach my $field ($record->field('550')){
+               if ($field->subfield('5') && $field->subfield('a')){
+                 if ($field->subfield('5') eq 'h'){
+            push @loopchildren, { 
"childauthid"=>$field->subfield('3'),"childvalue"=>$field->subfield('a')};
+                 }elsif ($field->subfield('5') eq 'g'){
+            push @loopparents, { 
"parentauthid"=>$field->subfield('3'),"parentvalue"=>$field->subfield('a')};
+                 }
+               # brothers could get in there with an else
+               }
+       }
+    $cell{"ifparents"}=1 if (scalar(@loopparents)>0);
+    $cell{"ifchildren"}=1 if (scalar(@loopchildren)>0);
+    $cell{"loopparents"address@hidden if (scalar(@loopparents)>0);
+    $cell{"loopchildren"address@hidden if (scalar(@loopchildren)>0);
+    $cell{"class"}=$class;
+    $cell{"loopauthid"}=$authid;
+    $cell{"current_value"} =1 if $authid eq $authid_constructed;
+    $cell{"value"}=$record->subfield('250',"a");
+       return \%cell;
+}
+
+sub AUTHgetheader{
+       my $authid = shift @_;
+       my $sql= "SELECT * from auth_header WHERE authid = ?";
+       my $dbh=C4::Context->dbh;
+       my $rq= $dbh->prepare($sql);
+    $rq->execute($authid);
+       my $data= $rq->fetchrow_hashref;
+       return $data;
+}
+
+sub AUTHsavetrees{
+       my $authid = shift @_;
+       my $trees = shift @_;
+       my $sql= "UPDATE IGNORE auth_header set authtrees=? WHERE authid = ?";
+       my $dbh=C4::Context->dbh;
+       my $rq= $dbh->prepare($sql);
+    $rq->execute($trees,$authid);
+}
+
+
 sub merge {
     my ($dbh,$mergefrom,$MARCfrom,$mergeto,$MARCto) = @_;
     my $authtypecodefrom = AUTHfind_authtypecode($dbh,$mergefrom);
@@ -854,8 +947,11 @@
 
 =cut
 
-# $Id: AuthoritiesMarc.pm,v 1.28.2.13 2007/01/09 15:18:09 hdl Exp $
+# $Id: AuthoritiesMarc.pm,v 1.28.2.14 2007/01/10 14:40:11 hdl Exp $
 # $Log: AuthoritiesMarc.pm,v $
+# Revision 1.28.2.14  2007/01/10 14:40:11  hdl
+# Adding Authorities tree.
+#
 # Revision 1.28.2.13  2007/01/09 15:18:09  hdl
 # Adding an to ccl.properties to allow ccl search for authority-numbers.
 # Fixing Some problems with the previous modification to allow pqf search to 
work for more than one page.

Index: koha-tmpl/intranet-tmpl/prog/en/authorities/detail.tmpl
===================================================================
RCS file: 
/cvsroot/koha/koha/koha-tmpl/intranet-tmpl/prog/en/authorities/detail.tmpl,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -b -r1.1.2.2 -r1.1.2.3
--- koha-tmpl/intranet-tmpl/prog/en/authorities/detail.tmpl     13 Oct 2006 
10:25:55 -0000      1.1.2.2
+++ koha-tmpl/intranet-tmpl/prog/en/authorities/detail.tmpl     10 Jan 2007 
14:40:11 -0000      1.1.2.3
@@ -5,6 +5,60 @@
 <!-- TMPL_INCLUDE NAME="menus.inc" -->
 <!-- TMPL_INCLUDE NAME="menu-authorities.inc" -->
 
+<!-- TMPL_IF Name="displayhierarchy"-->
+<link rel="stylesheet" type="text/css" href="<!-- TMPL_VAR NAME="themelang" 
-->/includes/hierarchy.css">
+<script language="JavaScript" type="text/javascript">
+function showParents(mynumber) {
+  var parents=document.getElementsByName(mynumber+'p')
+  for(i=0;i<parents.length;i++){
+    if (parents[i].style.display == "none") {
+      parents[i].style.display ="block";
+    } else {
+      parents[i].style.display ="none";
+    }
+  } 
+}
+function showChildren(mynumber) {
+  var children=document.getElementsByName(mynumber+'c')
+  for(i=0;i<children.length;i++){
+    if (children[i].style.display == "none") {
+      children[i].style.display = "block";
+    } else {
+      children[i].style.display = "none";
+    }
+  }
+}
+</script>
+
+<div class="hierarchies">
+<!--TMPL_LOOP Name="loophierarchies" -->
+  <div class="hierarchy">
+  <!--TMPL_LOOP Name="loopelement" -->
+    <div id="<!--TMPL_VAR Name="loopauthid" -->" class="<!--TMPL_VAR 
Name="class" -->">
+    <!--TMPL_IF Name="ifparents" -->
+      <!--TMPL_LOOP Name="loopparents" -->
+        <div name="<!--TMPL_VAR Name="loopauthid" -->p" class="parent"> <a 
href="detail.pl?authid=<!--TMPL_VAR Name="parentauthid" -->"><!--TMPL_VAR 
Name="parentvalue" --></a></div>
+      <!--/TMPL_LOOP-->
+    <!--/TMPL_IF -->
+    <!-- TMPL_IF name="current_value" -->
+        <!--TMPL_VAR Name="value" -->
+    <!-- TMPL_ELSE -->
+        <a href="detail.pl?authid=<!--TMPL_VAR Name="loopauthid" -->" 
title="Term"><!--TMPL_VAR Name="value" --></a>
+    <!-- /TMPL_IF -->
+    <!--TMPL_IF Name="ifchildren" -->
+      <sub><a class="parents" title="Narrower terms" 
href="JavaScript:showChildren('<!--TMPL_VAR Name="loopauthid" 
-->');">+</a></sub><br/>
+      <!--TMPL_LOOP Name="loopchildren" -->
+        <div name="<!--TMPL_VAR Name="loopauthid" -->c" class="child"> <a 
href="detail.pl?authid=<!--TMPL_VAR Name="childauthid" -->"><!--TMPL_VAR 
Name="childvalue" --></a></div>
+      <!--/TMPL_LOOP-->
+    <!-- /TMPL_IF -->
+    </div>
+  <!--/TMPL_LOOP-->
+    
+  </div>
+<!--/TMPL_LOOP-->
+</div>
+<!-- /TMPL_IF -->
+
 <h1 class="authority">Authority #<!-- TMPL_VAR NAME="authid" --> (<!-- 
TMPL_VAR name="authtypetext" -->)</h1>
 
 <div id="authorities_detail_actions">

Index: koha-tmpl/intranet-tmpl/prog/en/includes/hierarchy.css
===================================================================
RCS file: koha-tmpl/intranet-tmpl/prog/en/includes/hierarchy.css
diff -N koha-tmpl/intranet-tmpl/prog/en/includes/hierarchy.css
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ koha-tmpl/intranet-tmpl/prog/en/includes/hierarchy.css      10 Jan 2007 
14:40:12 -0000      1.1.2.1
@@ -0,0 +1,105 @@
+.hierarchies {
+       background-color:#fff;
+       color:#000000;
+       padding:5px;
+       margin-left:50px;
+       -moz-border-radius:6px;
+       display:block;
+       font-size:10px;
+}
+.hierarchy {
+       padding:5px;
+       width:90%;
+       -moz-border-radius:6px;
+       display:block;
+}
+.child {
+       display:none;
+    margin-left : 50px;
+    width:150%;
+}
+.child a:hover{
+  background-color:#BFCFFF;
+}
+.parent {
+       display:none;
+    margin-left : -50px;
+}
+.parent a:hover{
+  background-color:#BFCFFF;
+}
+.child0{
+  width : 20%;
+  text-align : left;
+}
+.child0 a:hover{
+  background-color:#BFCFFF;
+}
+.child1{
+  width : 20%;
+  text-align : left;
+  margin-left : 50px;
+}
+.child1 a:hover{
+  background-color:#BFCFFF;
+}
+.child2{
+  width : 20%;
+  text-align : left;
+  margin-left : 100px;
+}
+.child2 a:hover{
+  background-color:#BFCFFF;
+}
+.child3{
+  width : 20%;
+  text-align : left;
+  margin-left : 150px;
+}
+.child3 a:hover{
+  background-color:#BFCFFF;
+}
+.child4{
+  width : 20%;
+  text-align : left;
+  margin-left : 200px;
+}
+.child4 a:hover{
+  background-color:#BFCFFF;
+}
+.child5{
+  width : 20%;
+  text-align : left;
+  margin-left : 250px;
+}
+.child5 a:hover{
+  background-color:#BFCFFF;
+}
+.child6{
+  width : 20%;
+  text-align : left;
+  margin-left : 300px;
+}
+.child6 a:hover{
+  background-color:#BFCFFF;
+}
+.child7{
+  width : 20%;
+  text-align : left;
+  margin-left : 350px;
+}
+.child7 a:hover{
+  background-color:#BFCFFF;
+}
+.child8{
+  width : 10%;
+  text-align : left;
+  margin-left : 400px;
+}
+.child8 a:hover{
+  background-color:#BFCFFF;
+}
+.parents{
+  display:inline;
+  cursor:crosshair;
+}
\ No newline at end of file




reply via email to

[Prev in Thread] Current Thread [Next in Thread]