Audio-DB

 view release on metacpan or  search on metacpan

DB/Web.pm  view on Meta::CPAN

  my $url = '<a href="' . $full_url .
    "?action=$action" . "&class=$class" . 
      "&$primary=$target"
	  .'">' . $link_text . "</A>";
}

# Build up some generic URL for navigation
sub build_nav_link {
  my ($self,@p) = @_;
  my ($class,$action,$text) = rearrange([qw/CLASS ACTION TEXT/],@p);
  my $url = url();
  my $link = a({-href=>$url . '?' . $class . '=' . $action},$text);
  return $link;
}


sub table_navigation {
  my ($self,@p) = @_;
  my ($type,$span) = rearrange([qw/TYPE SPAN/],@p);

  my @values = qw/# A B C D E F G H I J K L M N O P Q R S T U V W X Y Z/;
  print start_div({-class=>"navigation"});
  print start_table();
  my $count = 0;
  foreach (@values) {
    # End the previous row if necessary...
    if ($count == $span) {
      print end_TR;
      $count = 0;
    }
    
    if ($count == 0) {
      print start_TR({-class=>'navigation'});
    }
    
    print td({-class=>'navcell'},
	     a({-href=>"/music/music.cgi?action=browse&class=$type&$type=$_"},$_));
    $count++;
  }
  print end_table;
  print end_div;
}

# Display buttons for the bottom of the page
sub buttons {
  my $self = shift;
  my $playlists = Audio::DB::Util::Playlists->fetch_playlists(-type=>'by_user');
#  my $playlists = $self->fetch_playlists(-type=>'by_user');
  my $playlists = [];
  my (@ids,%labels);
  foreach (@$playlists) {
    push (@ids,$_->{playlist_id});
    $labels{$_->{playlist_id}} = $_->{playlist};
  }
  print start_table({-width=>'100%'});
  print TR({-class=>'colheaders'},td('action'),td('tracks'),td('Available Playlists'),td(''));
  print TR(
	   td(radio_group({-name=>'todo',
			   -values=>['stream','fetch','add to playlist'],
			   -linebreak=>1})),
	   #  td(popup_menu({-values=>['stream','fetch','to playlist...']})),
	   td(radio_group({-name=>'the_chosen',
			   -values=>[qw/All Selected/],
			   -linebreak=>1})),
	   td(popup_menu({-name=>'playlist',
			  -values=>\@ids,
			  -labels=>\%labels})),
	   td(submit()));

  print a({-href=>"javascript:OpenPlaylists(" . $self->{user_id} . ")"},
	  "Add to playlist...");

#  print a({-onclick=>"window.open('music.cgi?action=add_to_playlist&user
#-href=>"javascript:OpenPlaylists(" . $self->{user_id} . ")"},
#	  "Add to playlist...");
}


# NEED TO FIGURE OUT HOW TO LINK IN...
# THIS BELONGS IN THE MODULE
sub print_checkboxes {
  my ($self,$obj,$count) = @_;
  my $class = $obj->class;
  my $id_coderef = $class . '_id';
  print
    td({-align=>'center'},
       checkbox({-name  =>'checkbox' . $count,
		 -value =>$class . 's_' . $obj->$id_coderef,
		 -label => ''})
      );
  print td('stream');
}


#######################################
# Basic browsing and searching methods
#######################################
# This is for generic letter based browsing...
sub browse_by_letter {
  my ($self,$field) = @_;

  my $query  = "^" . url_param($field) . '.*';
  my $adaptor = $self->adaptor;

  # This creates a container object in which to store everything
  my $this = bless { class=>ucfirst $field . 'List'},"Audio::DB::DataTypes::" . ucfirst $field . 'List';
  my $sth = $adaptor->fetch_by_letter($query,$field);
  my $dbh = $self->dbh;

  # This should all probably be moved to dbi::mysql since it has the fetchrow query
  while (my $h = $sth->fetchrow_hashref) {
    # Create brief summary objects of each of the albums or artists that are
    # returned.
    if ($field eq 'album') {
      my $obj = Audio::DB::DataTypes::Album->new(-data=>$h);
      push (@{$this->{albums}},$obj);
    } else {
      my $obj = Audio::DB::DataTypes::Artist->new(-data=>$h);
      push (@{$this->{artists}},$obj);
    }
  }
  return $this;
}




( run in 1.248 second using v1.01-cache-2.11-cpan-364913b4093 )