[siesta-commit] siesta/lib/Siesta/Storage DBI.pm,NONE,1.1

[prev] [thread] [next] [lurker] [Date index for 2002/08/26]

From: clampr
Subject: [siesta-commit] siesta/lib/Siesta/Storage DBI.pm,NONE,1.1
Date: 22:46 on 26 Aug 2002
Update of /cvsroot/siesta/siesta/lib/Siesta/Storage
In directory usw-pr-cvs1:/tmp/cvs-serv1990/lib/Siesta/Storage

Added Files:
	DBI.pm 
Log Message:
refactor into Storage::DBI

--- NEW FILE: DBI.pm ---
# $Id: DBI.pm,v 1.1 2002/08/26 21:46:19 clampr Exp $
package Siesta::Storage::DBI;
use strict;
use Siesta::Storage;
use base 'Siesta::Storage';

use Siesta::Storage::Table::Lists;
use Siesta::Storage::Table::List_Users;
use Siesta::Storage::Table::List_Plugins;


sub load_list {
    my $self = shift;
    my $id = shift;

    my $t_lists = Siesta::Storage::Table::Lists->new();
    my @results = $t_lists->search(id => $id);
    return unless @results == 1;

    delete $results[0]->{__Changed} ;
    return %{ $results[0] };
}


sub member_of_list {
    my $self = shift;
    my $list = shift;
    my $user = shift;

    my $t_list_users = Siesta::Storage::Table::List_Users->new();
    my @results = $t_list_users->search2(list_id => $list, user_id => $user);
    return scalar @results;
}


sub add_member_to_list {
    my $self = shift;
    my $list = shift;
    my $user = shift;

    # this is hacky, but I'm too lazy to learn Class::DBI today -- richardc
    my $table = Siesta::Storage::Table::List_Users->new();
    $table->dbh->do(qq{INSERT INTO list_users (list_id, user_id)
                       VALUES ('$list', '$user')})
      or die $table->dbh->errstr;
    return 1;
}


sub remove_member_from_list {
    my $self = shift;
    my $list = shift;
    my $user = shift;

    my $t_list_users = Siesta::Storage::Table::List_Users->new();
    my @results = $t_list_users->search2(list_id => $list, user_id => $user);
    return $results[0]->delete();
}


sub list_members {
    my $self = shift;
    my $list = shift;

    my $t_list_users = Siesta::Storage::Table::List_Users->new();
    return $t_list_users->search(list_id => $list);
}


sub list_plugins {
    my $self = shift;
    my $list = shift;

    my $t_list_plugins = Siesta::Storage::Table::List_Plugins->new();
    my @results = $t_list_plugins->search(list_id => $list);
    return map { $_->plugin_id } @results;
}

1;



Generated at 13:57 on 01 Jul 2004 by mariachi 0.52