Difference between revisions of "API:EPrints/DataObj"

From EPrints Documentation
Jump to: navigation, search
(13 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
<!-- Pod2Wiki=_preamble_  
 
<!-- Pod2Wiki=_preamble_  
 
This page has been automatically generated from the EPrints 3.2 source. Any wiki changes made between the 'Pod2Wiki=*' and 'Edit below this comment' comments will be lost.
 
This page has been automatically generated from the EPrints 3.2 source. Any wiki changes made between the 'Pod2Wiki=*' and 'Edit below this comment' comments will be lost.
  -->
+
  -->{{API}}{{Pod2Wiki}}{{API:Source|file=perl_lib/EPrints/DataObj.pm|package_name=EPrints::DataObj}}[[Category:API|DATAOBJ]][[Category:API:EPrints/DataObj|DATAOBJ]]<div><!-- Edit below this comment -->
__NOTOC__
 
{{API}}{{Pod2Wiki}}{{API:Source|file=EPrints/DataObj.pm|package_name=EPrints::DataObj}}[[Category:API|DataObj]]<div><!-- Edit below this comment -->
 
  
  
<!-- Pod2Wiki=head_name --></div>
+
<!-- Pod2Wiki=_private_ --><!-- Pod2Wiki=head_name -->
 
==NAME==
 
==NAME==
 
'''EPrints::DataObj''' - Base class for records in EPrints.
 
'''EPrints::DataObj''' - Base class for records in EPrints.
  
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
 
<!-- Edit below this comment -->
 
<!-- Edit below this comment -->
  
  
<!-- Pod2Wiki=head_synopsis --></div>
+
<!-- Pod2Wiki= -->
 +
<!-- Pod2Wiki=head_synopsis -->
 
==SYNOPSIS==
 
==SYNOPSIS==
  $dataobj = EPrints::DataObj-&gt;new( $handle, $id [, $dataset] )
+
$dataobj = $dataset-&gt;dataobj( $id );
 
 
  $handle = $dataobj-&gt;get_handle
 
  $dataset = $dataobj-&gt;get_dataset
 
 
 
  $id = $dataobj-&gt;get_id
 
  $uri = $dataobj-&gt;uri
 
  $url = $dataobj-&gt;get_url
 
  $url = $dataobj-&gt;get_control_url
 
 
 
  $value = $dataobj-&gt;get_value( $fieldname )
 
  $bool = $dataobj-&gt;is_set( $fieldname )
 
  $bool = $dataobj-&gt;exists_and_set( $fieldname )
 
 
 
  $success = $dataobj-&gt;remove
 
 
 
  $dataobj-&gt;set_value( $fieldname, $value )
 
  $success = $dataobj-&gt;commit( [$force] )
 
 
 
  $xhtml = $dataobj-&gt;render_value( $fieldname, [$showall] )
 
  $xhtml = $dataobj-&gt;render_citation( [$style], [%params] )
 
  $xhtml = $dataobj-&gt;render_citation_link( [$style], %params )
 
  $xhtml = $dataobj-&gt;render_citation_link_staff( [$style], %params )
 
  $xhtml = $dataobj-&gt;render_description
 
  ($xhtml, $title ) = $dataobj-&gt;render
 
  ($xhtml, $title ) = $dataobj-&gt;render_full
 
 
 
  $plugin_output = $dataobj-&gt;export( $plugin_id [,%params] )
 
 
 
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
<!-- Edit below this comment -->
 
  
 +
$dataobj-&gt;delete;
  
<!-- Pod2Wiki=head_description --></div>
+
$dataobj-&gt;commit( $force );
==DESCRIPTION==
 
This module is a base class which is inherited by [[API:EPrints/DataObj/EPrint|EPrints::DataObj::EPrint]], [[API:EPrints/User|EPrints::User]], [[API:EPrints/DataObj/Subject|EPrints::DataObj::Subject]] and [[API:EPrints/DataObj/Document|EPrints::DataObj::Document]] and several other classes.
 
  
It is ABSTRACT - these methods should not be called directly.
+
$dataset = $dataobj-&gt;dataset;
  
To create a new object in the database use:
+
$repo = $dataobj-&gt;repository;
$obj = $ds-&gt;create_object( $handle, $data ); =cut
 
  
###################################################################### #
+
$id = $dataobj-&gt;id;
# INSTANCE VARIABLES: #
 
$self-&gt;{data} #    A reference to a hash containing the metadata of this #    record. #
 
$self-&gt;{handle} #    The current EPrints::Handle #
 
#  $self-&gt;{dataset} #    The EPrints::DataSet to which this record belongs. #
 
######################################################################
 
  
package EPrints::DataObj;
+
$dataobj-&gt;set_value( $fieldname, $value );
  
use MIME::Base64 ();
+
$value = $dataobj-&gt;value( $fieldname );
  
use strict;
+
\@value = $dataobj-&gt;value( $fieldname ); # multiple
  
 +
$boolean = $dataobj-&gt;is_set( $fieldname );
  
###################################################################### # $sys_fields = EPrints::DataObj-&gt;get_system_field_info #  # Return an array describing the system metadata of the this  # dataset. ######################################################################
+
$xhtml = $dataobj-&gt;render_value( $fieldname );
  
sub get_system_field_info {
+
$xhtml = $dataobj-&gt;render_citation( $style, %opts );
my( $class ) = @_;
 
  
  return (); }
+
$uri = $dataobj-&gt;uri;
 
 
###################################################################### =pod
 
  
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
+
$url = $dataobj-&gt;url;
<h4><span style='display:none'>User Comments</span></h4>
 
<!-- Edit below this comment -->
 
  
 +
$string = $dataobj-&gt;export( $plugin_id, %opts );
  
<!-- Pod2Wiki=item_new --></div>
+
$dataobj = $dataobj-&gt;create_subobject( $fieldname, $epdata );
===$dataobj = EPrints::DataObj-&gt;new( $handle, $id [, $dataset] )===
 
  
Return new data object, created by loading it from the database.
 
 
If $dataset is not defined uses the default dataset for this object.
 
 
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
 
<!-- Edit below this comment -->
 
<!-- Edit below this comment -->
  
  
<!-- Pod2Wiki=item_get_handle --></div>
+
<!-- Pod2Wiki= -->
===$handle = $dataobj-&gt;get_handle===
+
<!-- Pod2Wiki=head_description -->
 +
==DESCRIPTION==
 +
This module is a base class which is inherited by [[API:EPrints/DataObj/EPrint|EPrints::DataObj::EPrint]], [[API:EPrints/DataObj/User|EPrints::DataObj::User]], [[API:EPrints/DataObj/Subject|EPrints::DataObj::Subject]] and [[API:EPrints/DataObj/Document|EPrints::DataObj::Document]] and several other classes.
  
Returns the EPrints::Handle object to which this record belongs.
+
It is ABSTRACT - its methods should not be called directly.
  
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
 
<!-- Edit below this comment -->
 
<!-- Edit below this comment -->
  
  
<!-- Pod2Wiki=item_remove --></div>
+
<!-- Pod2Wiki= -->
===$success = $dataobj-&gt;remove===
+
* $success = $dataobj-&gt;delete
 +
: Delete this data object from the database and any sub-objects or related files.
  
Remove this data object from the database and any sub-objects or related files.  
+
: Return true if successful.
  
Return true if successful.
+
* $dataobj-&gt;empty()
 +
: Remove all of this object's values that may be imported.
  
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
+
* $dataobj-&gt;update( $epdata [, %opts ] )
<h4><span style='display:none'>User Comments</span></h4>
+
: Update this object's values from $epdata. Ignores any values that do not exist in the dataset or do not have the 'import' property set.
<!-- Edit below this comment -->
 
  
 +
<pre>  include_subdataobjs - replace sub-dataobjs if given
 +
 
 +
  # replaces all documents in $dataobj
 +
  $dataobj->update( {
 +
    title => "Wombats on Fire",
 +
    documents => [{
 +
      main => "wombat.pdf",
 +
      ...
 +
    }],
 +
  }, include_subdataobjs => 1 );</pre>
  
<!-- Pod2Wiki=item_commit --></div>
+
* $success = $dataobj-&gt;commit( [$force] )
===$success = $dataobj-&gt;commit( [$force] )===
+
: Write this object to the database and reset the changed fields.
 
 
Write this object to the database and reset the changed fields.
 
 
 
If $force isn't true then it only actually modifies the database if one or more fields have been changed.
 
 
 
Commit may also queue indexer jobs or log changes, depending on the object.
 
 
 
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
<!-- Edit below this comment -->
 
 
 
 
 
<!-- Pod2Wiki=item_get_value --></div>
 
===$value = $dataobj-&gt;get_value( $fieldname )===
 
 
 
Get a the value of a metadata field. If the field is not set then it returns undef unless the field has the property multiple set, in which case it returns  [] (a reference to an empty array).
 
 
 
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
<!-- Edit below this comment -->
 
 
 
 
 
<!-- Pod2Wiki=item_set_value --></div>
 
===$dataobj-&gt;set_value( $fieldname, $value )===
 
 
 
Set the value of the named metadata field in this record.
 
 
 
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
<!-- Edit below this comment -->
 
 
 
 
 
<!-- Pod2Wiki=item_get_values --></div>
 
===@values = $dataobj-&gt;get_values( $fieldnames )===
 
 
 
Returns a list of all the values in this record of all the fields specified by $fieldnames. $fieldnames should be in the format used by browse views - slash seperated fieldnames with an optional .id suffix to indicate the id part rather than the main part.
 
 
 
For example "author.id/editor.id" would return a list of all author and editor ids from this record.
 
 
 
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
<!-- Edit below this comment -->
 
 
 
 
 
<!-- Pod2Wiki=item_get_data --></div>
 
===$data = $dataobj-&gt;get_data===
 
 
 
Returns a reference to the hash table of all the metadata for this record keyed  by fieldname.
 
 
 
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
<!-- Edit below this comment -->
 
 
 
 
 
<!-- Pod2Wiki=item_is_set --></div>
 
===$bool = $dataobj-&gt;is_set( $fieldname )===
 
 
 
Returns true if the named field is set in this record, otherwise false.
 
 
 
Warns if the field does not exist.
 
 
 
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
<!-- Edit below this comment -->
 
 
 
 
 
<!-- Pod2Wiki=item_exists_and_set --></div>
 
===$bool = $dataobj-&gt;exists_and_set( $fieldname )===
 
 
 
Returns true if the named field is set in this record, otherwise false.
 
 
 
If the field does not exist, just return false.
 
 
 
This method is useful for plugins which may operate on multiple  repositories, and the fact a field does not exist is not an issue.
 
 
 
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
<!-- Edit below this comment -->
 
 
 
  
<!-- Pod2Wiki=item_render_value --></div>
+
: If $force isn't true then it only actually modifies the database if one or more fields have been changed.
===$xhtml = $dataobj-&gt;render_value( $fieldname, [$showall] )===
 
  
Returns the rendered version of the value of the given field, as appropriate for the current session. If $showall is true then all values are rendered -  this is usually used for staff viewing data.
+
: Commit may also queue indexer jobs or log changes, depending on the object.
  
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '>
+
* $value = $dataobj-&gt;value( $fieldname )
<h4><span style='display:none'>User Comments</span></h4>
+
: Get a the value of a metadata field. If the field is not set then it returns undef unless the field has the property multiple set, in which case it returns [] (a reference to an empty array).
<!-- Edit below this comment -->
 
  
 +
* $dataobj-&gt;set_value( $fieldname, $value )
 +
: Set the value of the named metadata field in this record.
  
<!-- Pod2Wiki=item_render_citation --></div>
+
* @values = $dataobj-&gt;get_values( $fieldnames )
===$xhtml = $dataobj-&gt;render_citation( [$style], [%params] )===
+
: Returns a list of all the values in this record of all the fields specified by $fieldnames. $fieldnames should be in the format used by browse views - slash seperated fieldnames with an optional .id suffix to indicate the id part rather than the main part.
  
Renders the record as a citation. If $style is set then it uses that citation style from the citations config file. Otherwise $style defaults to the type of this record. If $params{url} is set then the citiation will link to the specified URL.
+
: For example "author.id/editor.id" would return a list of all author and editor ids from this record.
  
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
+
* $bool = $dataobj-&gt;is_set( $fieldname )
<h4><span style='display:none'>User Comments</span></h4>
+
: Returns true if the named field is set in this record, otherwise false.
<!-- Edit below this comment -->
 
  
 +
: Warns if the field does not exist.
  
<!-- Pod2Wiki=item_render_citation_link --></div>
+
* $bool = $dataobj-&gt;exists_and_set( $fieldname )
===$xhtml = $dataobj-&gt;render_citation_link( [$style], %params )===
+
: Returns true if the named field is set in this record, otherwise false.
  
Renders a citation (as above) but as a link to the URL for this item. For example - the abstract page of an eprint.  
+
: If the field does not exist, just return false.
  
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
+
: This method is useful for plugins which may operate on multiple  repositories, and the fact a field does not exist is not an issue.
<h4><span style='display:none'>User Comments</span></h4>
 
<!-- Edit below this comment -->
 
  
 +
* $id = $dataobj-&gt;id
 +
: Returns the value of the primary key of this record.
  
<!-- Pod2Wiki=item_render_citation_link_staff --></div>
+
* $uuid = $dataobj-&gt;uuid( [ $fragment ] )
===$xhtml = $dataobj-&gt;render_citation_link_staff( [$style], %params )===
+
: Generates a version 5 UUID for this object e.g.
  
As for render_citation_link but the link goes to the edit URL for the item.
+
<pre>  f70ef731-be66-50f4-8e72-8b8de36778b5</pre>
  
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
+
: The UUID is generated from the SHA1 hash of the concantenation of <code>uuid_namespace</code>, the {{API:PodLink|file=|package_name=|section=internal_uri|text=object's uri}} and, if defined, '''$fragment'''.
<h4><span style='display:none'>User Comments</span></h4>
 
<!-- Edit below this comment -->
 
  
 +
: <code>uuid_namespace</code> is a configuration variable. If <code>uuid_namespace</code> is undefined uses <code>base_url</code>:
  
<!-- Pod2Wiki=item_render_description --></div>
+
<pre>  # Note: deliberate typo to prevent copy-and-paste
===$xhtml = $dataobj-&gt;render_description===
+
  $c-&gt;{uuid_namespace} = "http://your-repository's url"";</pre>
  
Returns a short description of this object using the "brief" citation style for this dataset.
+
: Returns the formatted UUID.
  
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '>
+
* $xhtml = $dataobj-&gt;render_value( $fieldname, [$showall] )
<h4><span style='display:none'>User Comments</span></h4>
+
: Returns the rendered version of the value of the given field, as appropriate for the current session. If $showall is true then all values are rendered - this is usually used for staff viewing data.
<!-- Edit below this comment -->
 
  
 +
* $xhtml = $dataobj-&gt;render_citation( [$style], [%params] )
 +
: Renders the record as a citation. If $style is set then it uses that citation style from the citations config file. Otherwise $style defaults to the type of this record. If $params{url} is set then the citiation will link to the specified URL.
  
<!-- Pod2Wiki=item_render --></div>
+
* $xhtml = $dataobj-&gt;render_citation_link( [$style], %params )
===($xhtml, $title ) = $dataobj-&gt;render===
+
: Renders a citation (as above) but as a link to the URL for this item. For example - the abstract page of an eprint.
  
Return a chunk of XHTML DOM describing this object in the normal way. This is the public view of the record, not the staff view.
+
* $xhtml = $dataobj-&gt;render_export_bar( [ $staff ] )
 +
: Render a drop-down list of exports.
  
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '>
+
* $url = $dataobj-&gt;uri
<h4><span style='display:none'>User Comments</span></h4>
+
: Returns a unique URI for this object. Not certain to resolve as a URL.
<!-- Edit below this comment -->
 
  
 +
: If $c-&gt;{dataobj_uri}-&gt;{eprint} is a function, call that to work it out.
  
<!-- Pod2Wiki=item_render_full --></div>
+
* $path = $dataobj-&gt;path
===($xhtml, $title ) = $dataobj-&gt;render_full===
+
: Returns the relative path to this object from the repository's base URL, if the object has a URL.
  
Return an XHTML table in DOM describing this record. All values of all fields are listed. This is the staff view.
+
: Does not include any leading slash.
  
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
+
* $url = $dataobj-&gt;url
<h4><span style='display:none'>User Comments</span></h4>
+
: Returns the URL for this record, for example the URL of the abstract page of an eprint.
<!-- Edit below this comment -->
 
  
 +
* $plugin_output = $dataobj-&gt;export( $plugin_id, %params )
 +
: Apply an output plugin to this items. Return the results.
  
<!-- Pod2Wiki=item_get_id --></div>
+
* $rc = $dataobj-&gt;permit( $priv [, $user ] )
===$id = $dataobj-&gt;get_id===
+
<pre> # current user can edit via editorial role
 +
  if( $dataobj-&gt;permit( "xxx/edit", $user ) &amp; 8 )
 +
  {
 +
    ...
 +
  }
 +
  # anyone can view this object
 +
  if( $dataobj-&gt;permit( "xxx/view" ) )
 +
  {
 +
  }</pre>
  
Returns the value of the primary key of this record.
+
: Returns true if the current user (or 'anybody') can perform this action.
  
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
+
: Returns a bit mask where:
<h4><span style='display:none'>User Comments</span></h4>
 
<!-- Edit below this comment -->
 
  
 +
<pre>  0 - not permitted
 +
  1 - anybody
 +
  2 - logged in user
 +
  4 - user as owner
 +
  8 - user as editor</pre>
  
<!-- Pod2Wiki=item_get_dataset --></div>
+
: See also [[API:EPrints/Repository#allow_anybody|EPrints::Repository/allow_anybody]] and [[API:EPrints/DataObj/User#allow|EPrints::DataObj::User/allow]].
===$dataset = $dataobj-&gt;get_dataset===
 
  
Returns the [[API:EPrints/DataSet|EPrints::DataSet]] object to which this record belongs.
+
* $list = $dataobj-&gt;duplicates()
 +
: Return a conservative list of other objects that look like this one.
  
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
+
<!-- Pod2Wiki=head_copyright -->
<h4><span style='display:none'>User Comments</span></h4>
+
==COPYRIGHT==
<!-- Edit below this comment -->
+
Copyright 2000-2011 University of Southampton.
  
 +
This file is part of EPrints http://www.eprints.org/.
  
<!-- Pod2Wiki=item_uri --></div>
+
EPrints is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
===$uri = $dataobj-&gt;uri===
 
  
Returns a unique URI for this object. Not certain to resolve as a URL.
+
EPrints is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
  
The URI is generally of the form <em>repository_url</em>/id/<em>datasetid</em>/<em>dataobj_id</em>
+
You should have received a copy of the GNU Lesser General Public License along with EPrints.  If not, see http://www.gnu.org/licenses/.
  
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
 
<!-- Edit below this comment -->
 
<!-- Edit below this comment -->
  
  
<!-- Pod2Wiki=item_get_url --></div>
+
<!-- Pod2Wiki= -->
===$url = $dataobj-&gt;get_url===
+
<!-- Pod2Wiki=_postamble_ -->
 
 
Returns the URL for this record, for example the URL of the abstract page of an eprint.
 
 
 
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
 
<!-- Edit below this comment -->
 
<!-- Edit below this comment -->
 
 
<!-- Pod2Wiki=item_get_control_url --></div>
 
===$url = $dataobj-&gt;get_control_url===
 
 
Returns the URL for the control page for this object.
 
 
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
<!-- Edit below this comment -->
 
 
 
<!-- Pod2Wiki=item_export --></div>
 
===$plugin_output = $dataobj-&gt;export( $plugin_id [,%params] )===
 
 
Apply an output plugin to this items. Return the results. No additional parameters are required for most export plugins.
 
 
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
<!-- Edit below this comment -->
 
 
 
<!-- Pod2Wiki=item_has_owner --></div>
 
===$boolean = $dataobj-&gt;has_owner( $user )===
 
 
Return true if $user owns this record. Normally this means they  created it, but a group of users could count as owners of the same record if you wanted.
 
 
It's false on most dataobjs, except those which override this method.
 
 
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
<!-- Edit below this comment -->
 
 
 
<!-- Pod2Wiki=item_in_editorial_scope_of --></div>
 
===$boolean = $dataobj-&gt;in_editorial_scope_of( $user )===
 
 
As for has_owner, but if the user is identified as someone with an editorial scope which includes this record.
 
 
Defaults to true. Which doesn't mean that they have the right to  edit it, just that their scope matches. You also need editor rights to use this. It's currently used just to filter eprint editors so that only ones with a scope AND a priv can edit.
 
 
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
<!-- Edit below this comment -->
 
 
 
<!-- Pod2Wiki=item_validate --></div>
 
===$problems = $dataobj-&gt;validate( [ $for_archive ], $workflow_id )===
 
 
Return a reference to an array of XHTML DOM objects describing validation problems with the entire $dataobj based on $workflow_id.
 
 
If $workflow_id is undefined defaults to "default".
 
 
A reference to an empty array indicates no problems.
 
 
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
<!-- Edit below this comment -->
 
 
 
<!-- Pod2Wiki=item_get_warnings --></div>
 
===$warnings = $dataobj-&gt;get_warnings( )===
 
 
Return a reference to an array of XHTML DOM objects describing problems with the entire $dataobj.
 
 
A reference to an empty array indicates no problems.
 
 
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
<!-- Edit below this comment -->
 
 
 
<!-- Pod2Wiki=item_add_stored_file --></div>
 
===$file = $dataobj-&gt;add_stored_file( $filename, $filehandle [, $filesize ] )===
 
 
Convenience method to add the file record for $filename to this object. Reads data from $filehandle. If $filesize is defined it may used to determine where the file should be stored.
 
 
Returns the file object or undef if the storage failed.
 
 
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
<!-- Edit below this comment -->
 
 
 
<!-- Pod2Wiki=item_get_stored_file --></div>
 
===$file = $dataobj-&gt;get_stored_file( $filename )===
 
 
Get the file object for $filename.
 
 
Returns the file object or undef if the file doesn't exist.
 
 
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
<!-- Edit below this comment -->
 
 
 
<!-- Pod2Wiki=head_related_objects --></div>
 
===Related Objects===
 
These methods have been introduced in ep3.2 to describe the relationships between objects in the system.
 
 
See the wiki for more detailed discussion of how to use these.
 
 
  $dataobj-&gt;add_object_relations( $target, $has =&gt; $is [, $has =&gt; $is ] )
 
  $bool = $dataobj-&gt;has_object_relations( $target, @types )
 
  $bool = $dataobj-&gt;has_related_objects( @types )
 
  $dataobjs = $dataobj-&gt;get_related_objects( @types )
 
  $dataobj-&gt;remove_object_relations( $target [, $has =&gt; $is [, $has =&gt; $is ] )
 
 
 
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
<!-- Edit below this comment -->
 
 
 
<!-- Pod2Wiki=item_add_object_relations --></div>
 
====$dataobj-&gt;add_object_relations( $target, $has =&gt; $is [, $has =&gt; $is ] )====
 
 
Add a relation between this object and $target of type $has. If $is is defined will also add the reciprocal relationship $is from $target to this object. May be repeated to add multiple relationships.
 
 
You must commit $target after calling this method.
 
 
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
<!-- Edit below this comment -->
 
 
 
<!-- Pod2Wiki=item_has_object_relations --></div>
 
====$bool = $dataobj-&gt;has_object_relations( $target, @types )====
 
 
Returns true if this object is related to $target by all @types.
 
 
If @types is empty will return true if any relationships exist.
 
 
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
<!-- Edit below this comment -->
 
 
 
<!-- Pod2Wiki=item_has_related_objects --></div>
 
====$bool = $dataobj-&gt;has_related_objects( @types )====
 
 
Returns true if get_related_objects() would return some objects, but without actually retrieving the related objects from the database.
 
 
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
<!-- Edit below this comment -->
 
 
 
<!-- Pod2Wiki=item_get_related_objects --></div>
 
====$dataobjs = $dataobj-&gt;get_related_objects( @types )====
 
 
Returns a list of objects related to this object by @types.
 
 
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
<!-- Edit below this comment -->
 
 
 
<!-- Pod2Wiki=item_remove_object_relations --></div>
 
====$dataobj-&gt;remove_object_relations( $target [, $has =&gt; $is [, $has =&gt; $is ] )====
 
 
Remove relations between this object and $target. If $has =&gt; $is pairs are defined will only remove those relationships given.
 
 
You must commit $target after calling this method.
 
 
<div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<h4><span style='display:none'>User Comments</span></h4>
 
<!-- Edit below this comment -->
 
 
 
<!-- Pod2Wiki=_postamble_ --><!-- Edit below this comment -->
 

Revision as of 09:56, 22 January 2013

EPrints 3 Reference: Directory Structure - Metadata Fields - Repository Configuration - XML Config Files - XML Export Format - EPrints data structure - Core API - Data Objects


API: Core API

Latest Source Code (3.4, 3.3) | Revision Log | Before editing this page please read Pod2Wiki


NAME

EPrints::DataObj - Base class for records in EPrints.


SYNOPSIS

$dataobj = $dataset->dataobj( $id );

$dataobj->delete;

$dataobj->commit( $force );

$dataset = $dataobj->dataset;

$repo = $dataobj->repository;

$id = $dataobj->id;

$dataobj->set_value( $fieldname, $value );

$value = $dataobj->value( $fieldname );

\@value = $dataobj->value( $fieldname ); # multiple

$boolean = $dataobj->is_set( $fieldname );

$xhtml = $dataobj->render_value( $fieldname );

$xhtml = $dataobj->render_citation( $style, %opts );

$uri = $dataobj->uri;

$url = $dataobj->url;

$string = $dataobj->export( $plugin_id, %opts );

$dataobj = $dataobj->create_subobject( $fieldname, $epdata );


DESCRIPTION

This module is a base class which is inherited by EPrints::DataObj::EPrint, EPrints::DataObj::User, EPrints::DataObj::Subject and EPrints::DataObj::Document and several other classes.

It is ABSTRACT - its methods should not be called directly.


  • $success = $dataobj->delete
Delete this data object from the database and any sub-objects or related files.
Return true if successful.
  • $dataobj->empty()
Remove all of this object's values that may be imported.
  • $dataobj->update( $epdata [, %opts ] )
Update this object's values from $epdata. Ignores any values that do not exist in the dataset or do not have the 'import' property set.
  include_subdataobjs - replace sub-dataobjs if given
  
  # replaces all documents in $dataobj
  $dataobj->update( {
    title => "Wombats on Fire",
    documents => [{
      main => "wombat.pdf",
      ...
    }],
  }, include_subdataobjs => 1 );
  • $success = $dataobj->commit( [$force] )
Write this object to the database and reset the changed fields.
If $force isn't true then it only actually modifies the database if one or more fields have been changed.
Commit may also queue indexer jobs or log changes, depending on the object.
  • $value = $dataobj->value( $fieldname )
Get a the value of a metadata field. If the field is not set then it returns undef unless the field has the property multiple set, in which case it returns [] (a reference to an empty array).
  • $dataobj->set_value( $fieldname, $value )
Set the value of the named metadata field in this record.
  • @values = $dataobj->get_values( $fieldnames )
Returns a list of all the values in this record of all the fields specified by $fieldnames. $fieldnames should be in the format used by browse views - slash seperated fieldnames with an optional .id suffix to indicate the id part rather than the main part.
For example "author.id/editor.id" would return a list of all author and editor ids from this record.
  • $bool = $dataobj->is_set( $fieldname )
Returns true if the named field is set in this record, otherwise false.
Warns if the field does not exist.
  • $bool = $dataobj->exists_and_set( $fieldname )
Returns true if the named field is set in this record, otherwise false.
If the field does not exist, just return false.
This method is useful for plugins which may operate on multiple repositories, and the fact a field does not exist is not an issue.
  • $id = $dataobj->id
Returns the value of the primary key of this record.
  • $uuid = $dataobj->uuid( [ $fragment ] )
Generates a version 5 UUID for this object e.g.
  f70ef731-be66-50f4-8e72-8b8de36778b5
The UUID is generated from the SHA1 hash of the concantenation of uuid_namespace, the object's uri and, if defined, $fragment.
uuid_namespace is a configuration variable. If uuid_namespace is undefined uses base_url:
  # Note: deliberate typo to prevent copy-and-paste
  $c->{uuid_namespace} = "http://your-repository's url"";
Returns the formatted UUID.
  • $xhtml = $dataobj->render_value( $fieldname, [$showall] )
Returns the rendered version of the value of the given field, as appropriate for the current session. If $showall is true then all values are rendered - this is usually used for staff viewing data.
  • $xhtml = $dataobj->render_citation( [$style], [%params] )
Renders the record as a citation. If $style is set then it uses that citation style from the citations config file. Otherwise $style defaults to the type of this record. If $params{url} is set then the citiation will link to the specified URL.
  • $xhtml = $dataobj->render_citation_link( [$style], %params )
Renders a citation (as above) but as a link to the URL for this item. For example - the abstract page of an eprint.
  • $xhtml = $dataobj->render_export_bar( [ $staff ] )
Render a drop-down list of exports.
  • $url = $dataobj->uri
Returns a unique URI for this object. Not certain to resolve as a URL.
If $c->{dataobj_uri}->{eprint} is a function, call that to work it out.
  • $path = $dataobj->path
Returns the relative path to this object from the repository's base URL, if the object has a URL.
Does not include any leading slash.
  • $url = $dataobj->url
Returns the URL for this record, for example the URL of the abstract page of an eprint.
  • $plugin_output = $dataobj->export( $plugin_id, %params )
Apply an output plugin to this items. Return the results.
  • $rc = $dataobj->permit( $priv [, $user ] )
  # current user can edit via editorial role
  if( $dataobj->permit( "xxx/edit", $user ) & 8 )
  {
    ...
  }
  # anyone can view this object
  if( $dataobj->permit( "xxx/view" ) )
  {
  }
Returns true if the current user (or 'anybody') can perform this action.
Returns a bit mask where:
  0 - not permitted
  1 - anybody
  2 - logged in user
  4 - user as owner
  8 - user as editor
See also EPrints::Repository/allow_anybody and EPrints::DataObj::User/allow.
  • $list = $dataobj->duplicates()
Return a conservative list of other objects that look like this one.

COPYRIGHT

Copyright 2000-2011 University of Southampton.

This file is part of EPrints http://www.eprints.org/.

EPrints is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

EPrints is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with EPrints. If not, see http://www.gnu.org/licenses/.