Solstice::AuthZ::Action - Models a specfic action within an application.


Solstice documentation Contained in the Solstice distribution.

Index


Code Index:

NAME

Top

Solstice::AuthZ::Action - Models a specfic action within an application.

SYNOPSIS

Top

  use Action;

  my $model = Action->new();
  # The following accessors were created auto-magically by majere...

  my $obj = $model->getName();
  $model->setName($obj);

  my $obj = $model->getDescription();
  $model->setDescription($obj);

  my $obj = $model->getAppID();
  $model->setAppID($obj);

DESCRIPTION

Top

Represents an Authz Action record.

Superclass

Solstice::Model (Solstice::Model)

Export

No symbols exported.

Methods

new()

Constructor.

getName()

An accessor for _name.

setName($obj)

An accessor for _name.

getDescription()

An accessor for _description.

setDescription($obj)

An accessor for _description.

getAppID()

An accessor for _app_i_d.

setAppID($obj)

An accessor for _app_i_d.

Private Methods

_init($id)

Sets up the object

Modules Used

Solstice::Database, Solstice::Model (Solstice::Model).

AUTHOR

Top

Catalyst Group, <catalyst@u.washington.edu>

VERSION

Top

$Revision: 3384 $

COPYRIGHT

Top


Solstice documentation Contained in the Solstice distribution.
package Solstice::AuthZ::Action;

# $Id: Action.pm 3384 2006-05-17 21:57:05Z mcrawfor $

use 5.006_000;
use strict;
use warnings;

use Solstice::Database;
use Solstice::Configure;
use Solstice::Model;

our @ISA = qw(Solstice::Model);
our ($VERSION) = ('$Revision: 3384 $' =~ /^\$Revision:\s*([\d.]*)/);

sub new {
    my $obj = shift;
    my $id = shift;

    my $self = $obj->SUPER::new(@_);

    my $ref = ref $id;
    if($ref eq 'HASH'){
        $self->_initByHash($id);
    }elsif($id){
        $self->_init($id);
    }

    return $self;
}


sub getID {
    my $self = shift;
    return $self->{_id};
}

sub setID {
    my $self = shift;
    $self->{_id} = shift;
}

sub getName {
    my $self = shift;
    return $self->{_name};
}

sub setName {
    my $self = shift;
    $self->{_name} = shift;
}


sub getDescription {
    my $self = shift;
    return $self->{_description};
}

sub setDescription {
    my $self = shift;
    $self->{_description} = shift;
}


sub getAppID {
    my $self = shift;
    return $self->{_app_i_d};
}

sub setAppID {
    my $self = shift;
    $self->{_app_i_d} = shift;
}


sub _init {
    my $self = shift;
    my $original_id = shift;

    my $db = new Solstice::Database();
    my $config = Solstice::Configure->new();
    my $db_name = $config->getDBName();

    $db->readQuery("SELECT action_id, name, description, application_id FROM ".$db_name.".Actions where action_id = ?",$original_id);

    my $data_ref = $db->fetchRow();
    $self->_initByHash($data_ref);
}


sub _initByHash {
    my $self = shift;
    my $data_ref = shift;

    $self->setID($data_ref->{'action_id'});
    $self->setAppID($data_ref->{'application_id'});
    $self->setName($data_ref->{'name'});
    $self->setDescription($data_ref->{'description'});
}

sub store {
    my $self = shift;

    my $db = new Solstice::Database();
    my $config = Solstice::Configure->new();
    my $db_name = $config->getDBName();

    my $id            = $self->getID();
    my $name        = $self->getName();
    my $app_id        = $self->getAppID();
    my $description    = $self->getDescription();


    my $testid;
    if (defined $id) {
        $db->readQuery("SELECT action_id from ".$db_name.".Actions WHERE action_id = ?",$id);
        $testid = $db->fetchRow()->{'action_id'};
    }

    if($testid){

        $db->writeQuery(
            "UPDATE ".$db_name.".Actions SET
                        name = ?,
                        description = ?,
                        application_id = ?
                        WHERE
                        action_id = ?",$name,$description,$app_id,$id);

    }else{

        $db->writeQuery("INSERT INTO ".$db_name.".Actions
                        (name, description, application_id)
                        values
                        (?, ?, ?)",$name,$description,$app_id);
        my $id = $db->getLastInsertID($db_name.".Actions");

        $self->setID($id);
    }
}


sub delete {
    my $self = shift;

    my $db = new Solstice::Database();
    my $config = Solstice::Configure->new();
    my $db_name = $config->getDBName();

    my $id = $self->getID();

    $db->writeQuery("DELETE FROM ".$db_name.".Actions WHERE action_id = ?",$id);
}


1;
__END__