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

@ISA = qw (dictyBase_Table);

# Class Globals

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

%allowedConstructors = (phrase_no=>undef);

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

####################################################################
sub delete {
####################################################################
    my ($self) = @_;

    # remove associated rows from REFLINK table
    my $reflinkRef = $self->reflinkRef;
    foreach my $rowRef (@$reflinkRef) {
	(my $reflink_no, undef) = @$rowRef;
	my $reflink = Reflink->new(dbh=>$self->dbh,
				   reflink_no=>$reflink_no);
	$reflink->delete();
    }
    $self->SUPER::delete();
}

####################################################################
sub phraseCategoryRef {
####################################################################
    my ($self) = @_;
    my $schema = $self->schema;
    my $sth = $self->dbh->prepare("
        SELECT phrase_category
        FROM   $schema.phrase_category
        WHERE  phrase_no = ?
    ");
    $sth->execute($self->phrase_no);
    my $arrayRef = $sth->fetchall_arrayref();
}

####################################################################
sub phraseLinkRef {
####################################################################
    my ($self) = @_;
    my $schema = $self->schema;
    my $sth = $self->dbh->prepare("
        SELECT phrase_link_no, tab_name, primary_key, primary_key_col,
               date_created, created_by
        FROM   $schema.phrase_link
        WHERE  phrase_no = ?
    ");
    $sth->execute($self->phrase_no);
    my $arrayRef = $sth->fetchall_arrayref();
}

####################################################################
sub reflinkRef{
####################################################################
    my ($self) = @_;

    my $tabNm = "PHRASE";
    my $prikey = $self->phrase_no;
    my $priKeyCol = "PHRASE_NO";

    my $schema = $self->schema;
    my $sth = $self->dbh->prepare("
        SELECT reflink_no, reference_no, date_created, created_by
        FROM   $schema.reflink
        WHERE  tab_name = ?
        AND    primary_key = ?
        AND    primary_key_col = ?
    ");
    $sth->execute($tabNm, $prikey, $priKeyCol);
    my $arrayRef = $sth->fetchall_arrayref();
}

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

=pod

=head1 Name

Phrase.pm


=head1 Description

This perl object (Phrase.pm) acts as container for phrase info associated with a phrase_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 Phrase Object

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

my $phraseObj = Phrase->new(dbh=>$dbh, phrase_no=>$value); 

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


Syntax example :

my $phraseObj = Phrase->new(dbh=>$dbh, phrase_no=>$phraseNo); 

=head1 Accessor Methods


All accessor methods take the form of : 


column_name, eg: 


my $phraseText = $phraseObj->phrase_text; 


my $phraseOrder = $phraseObj->phrase_order; 


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


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


=head2 phraseCategoryRef

This accessor returns Phrase Categories assigned to the current Phrase

Usage:

my $phraseCategoryRef = $phraseObj->phraseCategoryRef;

foreach my $rowRef (@$phraseCategoryRef) {


    my ($phraseCategory) = @$rowRef;

    #####
   
}

=head2 phraseLinkRef

This accessor returns Phrase Links assigned to the current Phrase

Usage:

my $phraseLinkRef = $phraseObj->phraseLinkRef;

foreach my $rowRef (@$phraseLinkRef) {


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

    #####
   
}

=head2 refLinkRef

This accessor returns Ref Links associated with the current Phrase

Usage:

my $refLinkRef = $phraseObj->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




