App-Dochazka-REST

 view release on metacpan or  search on metacpan

lib/App/Dochazka/REST/Model/Privhistory.pm  view on Meta::CPAN

    my $self = shift;
    my ( $conn, $phid ) = validate_pos( @_, 
        { isa => 'DBIx::Connector' },
        { type => SCALAR }, 
    );

    return load(
        conn => $conn,
        class => __PACKAGE__,
        sql => $site->SQL_PRIVHISTORY_SELECT_BY_PHID,
        keys => [ $phid ],
    );
}


=head2 load_by_phid

Wrapper for load_by_id

=cut

sub load_by_phid {
    my $self = shift;
    my ( $conn, $phid ) = validate_pos( @_, 
        { isa => 'DBIx::Connector' },
        { type => SCALAR }, 
    );
    return $self->load_by_id( $conn, $phid );
}


=head2 insert

Instance method. Attempts to INSERT a record into the 'privhistory' table.
Field values are taken from the object. Returns a status object.

=cut

sub insert {
    my $self = shift;
    my ( $context ) = validate_pos( @_, { type => HASHREF } );

    my $status = cud(
        conn => $context->{'dbix_conn'},
        eid => $context->{'current'}->{'eid'},
        object => $self,
        sql => $site->SQL_PRIVHISTORY_INSERT,
        attrs => [ 'eid', 'priv', 'effective', 'remark' ],
    );

    return $status;
}


=head2 update

Instance method. Updates the record. Returns status object.

=cut

sub update {
    my $self = shift;
    my ( $context ) = validate_pos( @_, { type => HASHREF } );

    my $status = cud(
        conn => $context->{'dbix_conn'},
        eid => $context->{'current'}->{'eid'},
        object => $self,
        sql => $site->SQL_PRIVHISTORY_UPDATE,
        attrs => [ 'priv', 'effective', 'remark', 'phid' ],
    );

    return $status;
}


=head2 delete

Instance method. Deletes the record. Returns status object.

=cut

sub delete {
    my $self = shift;
    my ( $context ) = validate_pos( @_, { type => HASHREF } );

    my $status = cud(
        conn => $context->{'dbix_conn'},
        eid => $context->{'current'}->{'eid'},
        object => $self,
        sql => $site->SQL_PRIVHISTORY_DELETE,
        attrs => [ 'phid' ],
    );
    $self->reset( 'phid' => $self->{phid} ) if $status->ok;

    return $status;
}



=head1 FUNCTIONS


=head2 phid_exists

Boolean function

=cut

BEGIN {
    no strict 'refs';
    *{'phid_exists'} = App::Dochazka::REST::Model::Shared::make_test_exists( 'phid' );
}


=head2 get_privhistory

Takes a PARAMHASH which can have one or more of the properties 'eid', 'nick',
and 'tsrange'.

At least one of { 'eid', 'nick' } must be specified. If both are specified,



( run in 0.947 second using v1.01-cache-2.11-cpan-39bf76dae61 )