⧼vector-jumptocontent⧽

Miscellaneous Config Options/get users owned eprints: Difference between revisions

From EPrints Documentation
Added example
 
Alex-ball (talk | contribs)
No edit summary
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
This example should work with v3.4.6+.
Prior to v3.4.6 defining this method resulted in unexpected behaviour when eprint_status checkboxes were used on the ''Manage deposits'' page.
== Example ==
== Example ==
  $c->{get_users_owned_eprints} = sub  
  $c->{get_users_owned_eprints} = sub  
Line 13: Line 17:
     my $searchexp = $opts{dataset}->prepare_search( %opts );
     my $searchexp = $opts{dataset}->prepare_search( %opts );
     $searchexp->add_field( $opts{dataset}->field( "userid" ), $user->id . " $extra_userid", "IN", "ANY" );
     $searchexp->add_field( $opts{dataset}->field( "userid" ), $user->id . " $extra_userid", "IN", "ANY" );
    return $searchexp->perform_search;
};
Prior to v3.4.6, this function was passed a different set of parameters, thus search options had to be hard-coded:
# v3.4.5 and earlier
$c->{get_users_owned_eprints} = sub
{
    my( $session, $user, $dataset ) = @_;
    my $searchexp = $dataset->prepare_search(
        # options go here
    );
    # Add fields to $searchexp here
     return $searchexp->perform_search;
     return $searchexp->perform_search;
  };
  };

Latest revision as of 12:36, 1 October 2024

This example should work with v3.4.6+.

Prior to v3.4.6 defining this method resulted in unexpected behaviour when eprint_status checkboxes were used on the Manage deposits page.

Example

$c->{get_users_owned_eprints} = sub 
{
    my( $session, $user, %opts ) = @_;
    # for non-editorial accounts, return the normal list
    if( $user->get_type ne "editor" )
    {
        return $user->owned_eprints_list_actual( %opts );
    }
    # only interested in editor accounts now
    # allow editors to see their items, and items from a specific userid e.g. 99999
    my $extra_userid = 99999;
    my $searchexp = $opts{dataset}->prepare_search( %opts );
    $searchexp->add_field( $opts{dataset}->field( "userid" ), $user->id . " $extra_userid", "IN", "ANY" );
    return $searchexp->perform_search;
};

Prior to v3.4.6, this function was passed a different set of parameters, thus search options had to be hard-coded:

# v3.4.5 and earlier
$c->{get_users_owned_eprints} = sub 
{
    my( $session, $user, $dataset ) = @_;
    my $searchexp = $dataset->prepare_search(
        # options go here
    );
    # Add fields to $searchexp here
    return $searchexp->perform_search;
};