Solstice::Controller::FormInput::FileUpload::Single - A controller for uploading a file


Solstice documentation Contained in the Solstice distribution.

Index


Code Index:

NAME

Top

Solstice::Controller::FormInput::FileUpload::Single - A controller for uploading a file

SYNOPSIS

Top

DESCRIPTION

Top

Export

None by default.

Methods

new()
new($model)

Constructor.

getView()

Creates the view object for the home page.

update()

AUTHOR

Top

Educational Technology Development Group, <catalyst@u.washington.edu>

VERSION

Top

$Revision: 25 $

SEE ALSO

Top

COPYRIGHT

Top


Solstice documentation Contained in the Solstice distribution.
package Solstice::Controller::FormInput::FileUpload::Single;

# $Id: Single.pm 25 2006-01-14 00:50:12Z jlaney $

use strict;
use warnings;
use 5.006_000;

use base qw(Solstice::Controller::FormInput);

use Solstice::View::FormInput::FileUpload::Multiple;
use Solstice::Factory::Resource::File::BlackBox;
use Solstice::Resource::File::BlackBox;
use Solstice::CGI;

use constant TRUE  => 1;
use constant FALSE => 0;

use constant PARAM => 'file_upload';

sub new {
    my $class = shift;
    my $self = $class->SUPER::new(@_);

    $self->setModel(Solstice::Resource::File::BlackBox->new());
    
    return $self;
}

sub getView {
    my $self = shift;

    my $view = Solstice::View::FormInput::FileUpload::Multiple->new();
    $view->setName($self->getName() || PARAM);
    $view->setStartCount(1);
    $view->setMaxCount(1);
    
    return $view;
}

sub update { 
    my $self = shift;

    my $param = $self->getName() || PARAM;
    
    my @enc_ids = param($param);
    my $enc_id  = pop @enc_ids; # Use the last one in single uploads

    return TRUE unless $enc_id;
    
    my $ff = Solstice::Factory::Resource::File::BlackBox->new();
    
    my $file = $ff->createByEncryptedID($enc_id); 
    $self->setModel($file) if defined $file;
    
    return TRUE unless @enc_ids; 
    
    # Remove any others
    my $iterator = $ff->createByEncryptedIDs(\@enc_ids)->iterator();
    while (my $file = $iterator->next()) {
        $file->delete();
        $file->store();
    }
    
    return TRUE;
}


1;
__END__