koha-cvs
[Top][All Lists]
Advanced

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

[Koha-cvs] CVS: koha/C4 Shelf.pm,1.1,1.2


From: Steve Tonnesen
Subject: [Koha-cvs] CVS: koha/C4 Shelf.pm,1.1,1.2
Date: Wed, 23 Oct 2002 16:32:49 -0700

Update of /cvsroot/koha/koha/C4
In directory usw-pr-cvs1:/tmp/cvs-serv21739/C4

Modified Files:
        Shelf.pm 
Log Message:
Added some more functionality to Shelf.pm (including the ability to actually
create a new shelf) and started a test script (Shelf.t)


Index: Shelf.pm
===================================================================
RCS file: /cvsroot/koha/koha/C4/Shelf.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** Shelf.pm    23 Oct 2002 22:21:09 -0000      1.1
--- Shelf.pm    23 Oct 2002 23:32:47 -0000      1.2
***************
*** 79,82 ****
--- 79,85 ----
    my $shelf=Shelf->new(-name => 'Favourite Books', -owner => 'sjohnson');
        will load sjohnson's "Favourite Books" bookshelf
+   
+   Any of the last four invocations will create a new shelf with the name and
+   owner given if one doesn't already exist.
  
  
***************
*** 95,103 ****
  
      if (@_) {
        shift;
        if ($#_ == 0) {
            $self->{ID}=shift;
            # load attributes of shelf #ID
-           my $dbh=C4::Context->dbh();
            my $sth;
            $sth=$dbh->prepare("select bookshelfname,bookshelfowner from 
bookshelves where bookshelfid=?");
--- 98,106 ----
  
      if (@_) {
+       my $dbh=C4::Context->dbh();
        shift;
        if ($#_ == 0) {
            $self->{ID}=shift;
            # load attributes of shelf #ID
            my $sth;
            $sth=$dbh->prepare("select bookshelfname,bookshelfowner from 
bookshelves where bookshelfid=?");
***************
*** 109,113 ****
                $self->{ATTRIBUTES}->{$attribute}=$value;
            }
!       } else {
            my ($name,$owner,$attributes);
            if ($_[0] =~/^-/) {
--- 112,116 ----
                $self->{ATTRIBUTES}->{$attribute}=$value;
            }
!       } elsif ($#_) {
            my ($name,$owner,$attributes);
            if ($_[0] =~/^-/) {
***************
*** 121,124 ****
--- 124,147 ----
                $attributes=shift;
            }
+           my $sth=$dbh->prepare("select bookshelfid from bookshelves where 
bookshelfname=? and bookshelfowner=?");
+           $sth->execute($name, $owner);
+           if ($sth->rows) {
+               ($self->{ID})=$sth->fetchrow;
+               $sth=$dbh->prepare("select attribute,value from 
bookshelfattributes where bookshelfid=?");
+               $sth->execute($self->{ID});
+               while (my ($attribute,$value) = $sth->fetchrow) {
+                   $self->{ATTRIBUTES}->{$attribute}=$value;
+               }
+           } else {
+               $sth=$dbh->prepare("insert into bookshelves (bookshelfname, 
bookshelfowner) values (?, ?)");
+               $sth->execute($name,$owner);
+               $sth=$dbh->prepare("select bookshelfid from bookshelves where 
bookshelfname=? and bookshelfowner=?");
+               $sth->execute($name,$owner);
+               ($self->{ID})=$sth->fetchrow();
+               foreach my $attribute (keys %$attributes) {
+                   my $value=$attributes->{$attribute};
+                   $self->attribute($attribute,$value);
+               }
+           }
        }
      }
***************
*** 229,233 ****
  }
  
! sub clearshelf {
  }
  
--- 252,275 ----
  }
  
! 
! =head2 C<clearcontents()>
! 
! Removes all contents from the shelf.
! 
!     $shelf->clearcontents();
! 
! =cut
! 
! sub clearcontents {
!     my $self=shift;
!     my $dbh=C4::Context->dbh();
!     my $sth=$dbh->prepare("delete from bookshelfcontents where 
bookshelfid=?");
!     $sth->execute($self->{ID});
!     foreach my $level ('ITEM', 'BIBLIOITEM', 'BIBLIO') {
!       delete $self->{$level."CONTENTS"};
!       $self->{$level."CONTENTS"}={};
!     }
!     $self->clearcache();
! 
  }
  
***************
*** 278,284 ****
  =head2 C<attribute()>
  
! Returns the value of a given attribute for the shelf.
  
    my $loanlength=$shelf->attribute('loanlength');
  
  =cut
--- 320,328 ----
  =head2 C<attribute()>
  
! Returns or sets the value of a given attribute for the shelf.
  
    my $loanlength=$shelf->attribute('loanlength');
+   $shelf->attribute('loanlength', '21 days');
+ 
  
  =cut
***************
*** 286,290 ****
  sub attribute {
      my $self=shift;
!     my $attribute=shift;
      return $self->{ATTRIBUTES}->{$attribute};
  }
--- 330,349 ----
  sub attribute {
      my $self=shift;
!     my ($attribute, $value);
!     $attribute=shift;
!     $value=shift;
!     if ($value) {
!       $self->{ATTRIBUTES}->{$attribute}=$value;
!       my $dbh=C4::Context->dbh();
!       my $sth=$dbh->prepare("select value from bookshelfattributes where 
bookshelfid=? and attribute=?");
!       $sth->execute($self->{ID}, $attribute);
!       if ($sth->rows) {
!           my $sti=$dbh->prepare("update bookshelfattributes set value=? where 
bookshelfid=? and attribute=?");
!           $sti->execute($value, $self->{ID}, $attribute);
!       } else {
!           my $sti=$dbh->prepare("inesrt into bookshelfattributes 
(bookshelfid, attribute, value) values (?, ?, ?)");
!           $sti->execute($self->{ID}, $attribute, $value);
!       }
!     }
      return $self->{ATTRIBUTES}->{$attribute};
  }




reply via email to

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