#!/usr/bin/perl
package Paragraph;
#####################################################################
# Author : Shuai Weng / Kane Tse
# Date   : July 2001
#
# Usage: 
#     
#   use Paragraph
#
#   ### You may use one of the following syntaxes to 
#   ### instantiate a new Paragraph object.
#
#   my $paragraphObj = Paragraph->new(dbh=>$dbh,
#                                     paragraph_no=>$paragraphName);
#
#   ### You can use an accessor for any valid column 
#   ### in the Paragraph table. For example: 
#   my $paragraph_text = $paragraphObj->paragraph_text;
#   my $paragraph_no = $paragraphObj->paragraph_no;
#   my $paragraph_order = $paragraphObj->paragraph_order;
#   .....
#
#   See documentation for detail.
#   
#   URL of help page (not yet available)
#
#####################################################################
use strict;
use DBI;
use Carp;
use vars qw (@ISA %allowedConstructors);
use Phrase;
use Locus;
use dictyBase_Table;
@ISA = qw (dictyBase_Table); # base class

# Class Globals

# put column names in the hash below, that are able to uniquely
# specify a row in the table

%allowedConstructors = (paragraph_no=>undef,
			paragraph_text=>undef,
			locus_no=>undef,
			locus_name=>undef
		       );

####################################################################
sub new {
####################################################################
    my ($class, %args) = @_;

    if ($args{'locus_no'}) {
	my $locus_row = Locus->new(dbh=>$args{'dbh'},
				   locus_no=>$args{'locus_no'});
	$args{'paragraph_no'} = $locus_row->paragraph_no;
	delete($args{'locus_no'});

    }
    elsif ($args{'locus_name'}) {
	my $locus_row = Locus->new(dbh=>$args{'dbh'},
				   locus_name=>$args{'locus_name'});
	$args{'paragraph_no'} = $locus_row->paragraph_no;
	delete($args{'locus_name'});

    }

    $class->SUPER::new(%args);

}

#######################################################################
sub hasUncommittedUpdates { }
#######################################################################

####################################################################
sub phraseRef{
####################################################################
    my ($self) = @_;
    my $schema = $self->schema;
    my $sth = $self->dbh->prepare("
        SELECT phrase_no, phrase_text
        FROM   $schema.phrase
        WHERE  paragraph_no = ?
    ");

    $sth->execute($self->paragraph_no);
    my $arrayRef = $sth->fetchall_arrayref();
}



####################################################################
sub locusRef{
####################################################################
    my ($self) = @_;
    my $schema = $self->schema;
    my $sth = $self->dbh->prepare("
        SELECT locus_no, locus_name
        FROM   $schema.locus
        WHERE  paragraph_no = ?
    ");
    $sth->execute($self->paragraph_no);
    my $arrayRef = $sth->fetchall_arrayref();
}

####################################################################
sub colleagueRef{
####################################################################
    my ($self) = @_;
    my $schema = $self->schema;
    my $sth = $self->dbh->prepare("
        SELECT c.colleague_no, c.last_name, c.first_name
        FROM   $schema.coll_para cp, $schema.colleague c
        WHERE  cp.paragraph_no = ?
        AND    cp.colleague_no = c.colleague_no
    ");
    $sth->execute($self->paragraph_no);
    my $arrayRef = $sth->fetchall_arrayref();
}

####################################################################
sub updatesRef {
####################################################################
    my ($self) = @_;
    my $schema = $self->schema;
    my $sth = $self->dbh->prepare("
       SELECT   ul.modified_by, ul.date_modified
       FROM     $schema.update_log ul
       WHERE    tab_name = 'PARAGRAPH'
       AND      primary_key = ?
       ORDER BY ul.date_modified
    ");
    $sth->execute($self->paragraph_no);
    my $arrayRef = $sth->fetchall_arrayref();
}


####################################################################
1; #################################################################
####################################################################

=pod

=head1 Name

Paragraph.pm


=head1 Description

This perl object (Paragraph.pm) acts as container for paragraph info associated with a paragraph_no in the Oracle database. Once an object has been instantiated, several methods are available to retrieve the attributes of the object. 


=head1 Instantiating a New Paragraph Object

To instantiate a new Paragraph object, you may use following syntax: 

my $paragraphObj = Paragraph->new(dbh=>$dbh, paragraph_no=>$value); 

where $dbh is a valid database handle to either dictyBase or SDEV. $value must be a valid value for the paragraph_no that was provided, otherwise the script will die, with an appropriate error message.


Syntax example :

my $paragraphObj = Paragraph->new(dbh=>$dbh, paragraph_no=>$paragraphNo); 

=head1 Accessor Methods


All accessor methods take the form of : 


column_name, eg: 


my $paragraphText = $paragraphObj->paragraph_text; 


my $paragraphOrder = $paragraphObj->paragraph_order; 


etc. You can use an accessor for any valid column in the Paragraph table. 


In addition, the following accessor methods are provided to access no Paragraph columns in database.


=head2 paragraphCategoryRef

This accessor returns Paragraph Categories assigned to the current Paragraph

Usage:

my $paragraphCategoryRef = $paragraphObj->paragraphCategoryRef;

foreach my $rowRef (@$paragraphCategoryRef) {


    my ($paragraphCategory) = @$rowRef;

    #####
   
}

=head2 paragraphLinkRef

This accessor returns Paragraph Links assigned to the current Paragraph

Usage:

my $paragraphLinkRef = $paragraphObj->paragraphLinkRef;

foreach my $rowRef (@$paragraphLinkRef) {


    my ($paragraphLinkNo, $tabNm, $primary_key, primary_key_col, 
	date_created, created_by) = @$rowRef;

    #####
   
}

=head2 refLinkRef

This accessor returns Ref Links associated with the current Paragraph

Usage:

my $refLinkRef = $paragraphObj->refLinkRef;

foreach my $rowRef (@$refLinkRef) {


    my ($refLinkNo, $tabNm, $primary_key, primary_key_col, 
	date_created, created_by) = @$rowRef;

    #####
   
}

=head1 Author

Kane Tse

ktse@genome.stanford.edu

=cut




