Difference between revisions of "Building a DataSet"

From EPrints Documentation
Jump to: navigation, search
Line 116: Line 116:
  
 
</pre>
 
</pre>
 +
 +
 +
==Modify my first bazaar package to show the contents of dark_archive==

Revision as of 23:23, 29 March 2011

Modify EPrint Status Field

We must start my modifying the eprint_status field so that it can have the new value dark_archive.

push( @{$c->{fields}->{eprint}}, {
  name=>"eprint_status", type=>"set", required=>1,
  options=>[qw/ inbox buffer archive deletion dark_archive /],
  replace_core=>1 #this flag must be used with EXTREME caution, it makes is very easy to break things
});

Add the dark archive dataset definition

dark_archive => {
     sqlname => "eprint",
     virtual => 1,
     class => "EPrints::DataObj::EPrint",
     confid => "eprint",
     import => 1,
     index => 1,
     filters => [ { meta_fields => [ 'eprint_status' ], value => 'dark_archive', describe=>0 } ],
     dataset_id_field => "eprint_status",
     datestamp => "lastmod",
},
epadmin update_database_structure <repoid>


Build a screen to move an object to the archive

package EPrints::Plugin::Screen::EPrint::MoveToDarkArchive;

@ISA = ( 'EPrints::Plugin::Screen::EPrint' );

use strict;

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

	my $self = $class->SUPER::new(%params);

	#	$self->{priv} = # no specific priv - one per action

	$self->{actions} = [qw/ move_dark_archive /];

	$self->{appears} = [
{ place => "eprint_editor_actions", 	action => "move_dark_archive", 	position => 400, },
{ place => "eprint_item_actions", 	action => "move_dark_archive", 	position => 400, },
	];
	#$self->{action_icon} = { move_archive => "action_approve.png" };

	return $self;
}

sub obtain_lock
{
	my( $self ) = @_;

	return $self->could_obtain_eprint_lock;
}

sub about_to_render 
{
	my( $self ) = @_;

	$self->EPrints::Plugin::Screen::EPrint::View::about_to_render;
}

sub allow_move_dark_archive
{
	my( $self ) = @_;

	return 0 unless $self->could_obtain_eprint_lock;
	return 1;
}

sub action_move_dark_archive
{
	my( $self ) = @_;

	$self->{processor}->{eprint}->remove_static;
	$self->{processor}->{eprint}->set_value("eprint_status", "dark_archive");
	$self->{processor}->{eprint}->commit;

	$self->add_result_message( 1 );
}



sub add_result_message
{
	my( $self, $ok ) = @_;

	if( $ok )
	{
		$self->{processor}->add_message( "message",
			$self->html_phrase( "status_changed",
				status=>$self->{processor}->{eprint}->render_value( "eprint_status" ) ) );
	}
	else
	{
		$self->{processor}->add_message( "error",
			$self->html_phrase( 
				"cant_move",
				id => $self->{session}->make_text( 
					$self->{processor}->{eprintid} ) ) );
	}

	$self->{processor}->{screenid} = "EPrint::View";
}

1;


Modify my first bazaar package to show the contents of dark_archive