Difference between revisions of "API:EPrints/MetaField"

From EPrints Documentation
Jump to: navigation, search
Line 15: Line 15:
  
  
<!-- Pod2Wiki=head_synopsis --></div>
+
<!-- Pod2Wiki=head_description --></div>
==SYNOPSIS==
+
==DESCRIPTION==
  my $field = $dataset-&gt;get_field( $fieldname );
+
Theis object represents a single metadata field, not the value of that field. A field belongs (usually) to a dataset and has a large number of properties. Optional and required properties vary between  types.
 
+
 
  # you must clone a field to modify any properties
+
"type" is the most important property, it is the type of the metadata field. For example: "text", "name" or "date".
  $newfield = $field-&gt;clone;
+
 
  $newfield-&gt;set_property( $property, $value );
+
A full description of metadata types and properties is in the eprints documentation and will not be duplicated here.
 
+
 
  $name = $field-&gt;get_name;
 
  $type = $field-&gt;get_type;
 
  $value = $field-&gt;get_property( $property );
 
  $boolean = $field-&gt;is_type( @typenames );
 
  $results = $field-&gt;call_property( $property, @args );
 
  # (results depend on what the property sub returns)
 
 
 
  $xhtml = $field-&gt;render_name( $handle );
 
  $xhtml = $field-&gt;render_help( $handle );
 
  $xhtml = $field-&gt;render_value( $handle, $value, $show_all_langs, $dont_include_links, $object );
 
  $xhtml = $field-&gt;render_single_value( $handle, $value );
 
  $xhtml = $field-&gt;get_value_label( $handle, $value );
 
 
 
  $values = $field-&gt;get_values( $handle, $dataset, %opts );
 
 
 
  $sorted_list = $field-&gt;sort_values( $handle, $unsorted_list );
 
 
 
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; 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>
 
<h4><span style='display:none'>User Comments</span></h4>
Line 45: Line 28:
  
  
<!-- Pod2Wiki=head_description --></div>
+
<!-- Pod2Wiki=item_new --></div>
==DESCRIPTION==
+
===$field = EPrints::MetaField-&gt;new( %properties )===
Theis object represents a single metadata field, not the value of that field. A field belongs (usually) to a dataset and has a large number of properties. Optional and required properties vary between  types.
 
  
"type" is the most important property, it is the type of the metadata field. For example: "text", "name" or "date".
+
Create a new metafield. %properties is a hash of the properties of the field, with the addition of "dataset", or if "dataset" is not set then "confid" and "repository" must be provided instead.
  
A full description of metadata types and properties is in the eprints documentation and will not be duplicated here.
+
Some field types require certain properties to be explicitly set. See the main documentation.
  
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
Line 58: Line 40:
  
  
<!-- Pod2Wiki=head_methods --></div>
+
<!-- Pod2Wiki=item_final --></div>
==METHODS==
+
===$field-&gt;final===
 +
 
 +
This method tells the metafield that it is now read only. Any call to set_property will produce a abort error.
 +
 
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; 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>
 
<h4><span style='display:none'>User Comments</span></h4>
Line 91: Line 76:
  
  
<!-- Pod2Wiki=item_get_dataset --></div>
+
<!-- Pod2Wiki=item_repository --></div>
===$dataset = $field-&gt;get_dataset===
+
===$repository = $field-&gt;repository===
  
Return the dataset to which this field belongs, or undef.
+
Return the [[API:EPrints/Repository|EPrints::Repository]] to which this field belongs.
 +
 
 +
<div style='background-color: #e8e8f; 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_dataset --></div>
 +
===$dataset = $field-&gt;dataset===
 +
 
 +
Return the [[API:EPrints/DataSet|EPrints::DataSet]] to which this field belongs, or undef.
  
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
Line 102: Line 97:
  
 
<!-- Pod2Wiki=item_render_name --></div>
 
<!-- Pod2Wiki=item_render_name --></div>
===$xhtml = $field-&gt;render_name( $handle )===
+
===$xhtml = $field-&gt;render_name===
  
 
Render the name of this field as an XHTML object.
 
Render the name of this field as an XHTML object.
 +
 +
<div style='background-color: #e8e8f; 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_display_name --></div>
 +
===$label = $field-&gt;display_name( $session )===
 +
 +
DEPRECATED! Can't be removed because it's used in 2.2's default ArchiveRenderConfig.pm
 +
 +
Return the UTF-8 encoded name of this field, in the language of the $session.
  
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
Line 112: Line 119:
  
 
<!-- Pod2Wiki=item_render_help --></div>
 
<!-- Pod2Wiki=item_render_help --></div>
===$xhtml = $field-&gt;render_help( $handle )===
+
===$xhtml = $field-&gt;render_help===
  
 
Return the help information for a user inputing some data for this field as an XHTML chunk.
 
Return the help information for a user inputing some data for this field as an XHTML chunk.
Line 122: Line 129:
  
 
<!-- Pod2Wiki=item_render_input_field --></div>
 
<!-- Pod2Wiki=item_render_input_field --></div>
===$xhtml = $field-&gt;render_input_field( $handle, $value, [$dataset], [$staff], [$hidden_fields], $obj, [$prefix] )===
+
===$xhtml = $field-&gt;render_input_field( $session, $value, [$dataset], [$staff], [$hidden_fields], $obj, [$basename] )===
  
 
Return the XHTML of the fields for an form which will allow a user to input metadata to this field. $value is the default value for this field.
 
Return the XHTML of the fields for an form which will allow a user to input metadata to this field. $value is the default value for this field.
  
The actual function called may be overridden from the config options.
+
The actual function called may be overridden from the config.
  
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
Line 134: Line 141:
  
 
<!-- Pod2Wiki=item_form_value --></div>
 
<!-- Pod2Wiki=item_form_value --></div>
===$value = $field-&gt;form_value( $handle, $object, [$prefix] )===
+
===$value = $field-&gt;form_value( $session, $object, [$prefix] )===
  
 
Get a value for this field from the CGI parameters, assuming that the form contained the input fields for this metadata field.
 
Get a value for this field from the CGI parameters, assuming that the form contained the input fields for this metadata field.
Line 143: Line 150:
  
  
<!-- Pod2Wiki=item_get_name --></div>
+
<!-- Pod2Wiki=item_name --></div>
===$name = $field-&gt;get_name===
+
===$name = $field-&gt;name===
  
 
Return the name of this field.
 
Return the name of this field.
Line 153: Line 160:
  
  
<!-- Pod2Wiki=item_get_type --></div>
+
<!-- Pod2Wiki=item_type --></div>
===$type = $field-&gt;get_type===
+
===$type = $field-&gt;type===
  
 
Return the type of this field.
 
Return the type of this field.
Line 163: Line 170:
  
  
<!-- Pod2Wiki=item_get_property --></div>
+
<!-- Pod2Wiki=item_property --></div>
===$value = $field-&gt;get_property( $property )===
+
===$value = $field-&gt;property( $property )===
  
 
Return the value of the given property.
 
Return the value of the given property.
  
Special note about "required" property, the workflow may in some situations return a field which is 'required' which isn't if you get it via $dataset.
+
Special note about "required" property: It only indicates if the field is always required. You must query the dataset to check if it is required for a specific type.
 
 
There's about 50 in total, with additional extras for some subtypes of MetaField! However the most useful ones are:
 
  
  if( $field-&gt;get_property( "multiple" ) ) { ... }
 
  if( $field-&gt;get_property( "required" ) ) { ... }
 
 
 
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; 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>
 
<h4><span style='display:none'>User Comments</span></h4>
Line 191: Line 193:
  
 
<!-- Pod2Wiki=item_render_value --></div>
 
<!-- Pod2Wiki=item_render_value --></div>
===$xhtml = $field-&gt;render_value( $handle, $value, [$alllangs], [$nolink], $object )===
+
===$xhtml = $field-&gt;render_value( $session, $value, [$alllangs], [$nolink], $object )===
  
 
Render the given value of this given string as XHTML DOM. If $alllangs  is true and this is a multilang field then render all language versions, not just the current language (for editorial checking). If $nolink is true then don't make this field a link, for example subject fields  might otherwise link to the subject view page.
 
Render the given value of this given string as XHTML DOM. If $alllangs  is true and this is a multilang field then render all language versions, not just the current language (for editorial checking). If $nolink is true then don't make this field a link, for example subject fields  might otherwise link to the subject view page.
  
 
If render_value or render_single_value properties are set then these control the rendering instead.
 
If render_value or render_single_value properties are set then these control the rendering instead.
 +
 +
<div style='background-color: #e8e8f; 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_no_multiple --></div>
 +
===$xhtml = $field-&gt;render_value_no_multiple( $session, $value, $alllangs, $nolink, $object )===
 +
 +
Render the XHTML for a non-multiple value. Can be either a from a non-multiple field, or a single value from a multiple field.
 +
 +
Usually just used internally.
 +
 +
<div style='background-color: #e8e8f; 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_withopts --></div>
 +
===$xhtml = $field-&gt;render_value_withopts( $session, $value, $nolink, $object )===
 +
 +
Render a single value but adding the render_opts features.
 +
 +
This uses either the field specific render_single_value or, if one is configured, the render_single_value specified in the config.
 +
 +
Usually just used internally.
  
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
Line 203: Line 231:
  
 
<!-- Pod2Wiki=item_sort_values --></div>
 
<!-- Pod2Wiki=item_sort_values --></div>
===$out_list = $field-&gt;sort_values( $handle, $in_list )===
+
===$out_list = $field-&gt;sort_values( $session, $in_list )===
  
 
Sorts the in_list into order, based on the "order values" of the  values in the in_list. Assumes that the values are not a list of multiple values. [ [], [], [] ], but rather a list of single values.
 
Sorts the in_list into order, based on the "order values" of the  values in the in_list. Assumes that the values are not a list of multiple values. [ [], [], [] ], but rather a list of single values.
 +
 +
<div style='background-color: #e8e8f; 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_list_values --></div>
 +
===@values = $field-&gt;list_values( $value )===
 +
 +
Return a list of every distinct value in this field.
 +
 +
- for simple fields: return ( $value )
 +
- for multiple fields: return @{$value}
 +
 
 +
This function is used by the item_matches method in Search.
 +
 +
<div style='background-color: #e8e8f; 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_most_local --></div>
 +
===$value = $field-&gt;most_local( $session, $value )===
 +
 +
If this field is a multilang field then return the version of the  value most useful for the language of the session. In order of preference: The language of the session, the default language for the repository, any language at all. If it is not a multilang field then just return $value.
  
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
Line 218: Line 271:
  
 
The property may contain either a code reference, or the scalar name of a method.
 
The property may contain either a code reference, or the scalar name of a method.
 +
 +
<div style='background-color: #e8e8f; 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_value_from_sql_row --></div>
 +
===$val = $field-&gt;value_from_sql_row( $session, $row )===
 +
 +
Shift and return the value of this field from the database input $row.
 +
 +
<div style='background-color: #e8e8f; 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_sql_row_from_value --></div>
 +
===@row = $field-&gt;sql_row_from_value( $session, $value )===
 +
 +
Return a list of values to insert into the database based on $value.
 +
 +
The values will normally be passed to {{API:PodLink|file=DBI|package_name=DBI|section=bind_param|text=DBI/bind_param}}:
 +
 +
  $sth-&gt;bind_param( $idx, $row[0] )
 +
 
 +
If the value is an array ref it gets expanded:
 +
 +
  $sth-&gt;bind_param( $idx, @{$row[0]} )
 +
 
 +
This is necessary to support binding LOB data under various databases.
 +
 +
<div style='background-color: #e8e8f; 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_sql_properties --></div>
 +
===%opts = $field-&gt;get_sql_properties( $session )===
 +
 +
Map the relevant SQL properties for this field to options passed to [[API:EPrints/Database|EPrints::Database]]::get_column_type().
 +
 +
<div style='background-color: #e8e8f; 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_sql_type --></div>
 +
===@types = $field-&gt;get_sql_type( $session )===
 +
 +
Return the SQL column types of this field, used for creating tables.
 +
 +
<div style='background-color: #e8e8f; 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_create_ordervalues_field --></div>
 +
===$field = $field-&gt;create_ordervalues_field( $session [, $langid ] )===
 +
 +
Return a new field object that this field can use to store order values, optionally for language $langid.
 +
 +
<div style='background-color: #e8e8f; 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_sql_index --></div>
 +
===$sql = $field-&gt;get_sql_index===
 +
 +
Return the columns that an index should be created over.
  
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
Line 225: Line 348:
  
 
<!-- Pod2Wiki=item_render_single_value --></div>
 
<!-- Pod2Wiki=item_render_single_value --></div>
===$xhtml_dom = $field-&gt;render_single_value( $handle, $value )===
+
===$xhtml_dom = $field-&gt;render_single_value( $session, $value )===
  
Returns the XHTML representation of the value. If the field is multiple then $value should be a single item from the values, not the list.
+
Returns the XHTML representation of the value. The value will be non-multiple. Just the simple value.
  
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
Line 234: Line 357:
  
  
<!-- Pod2Wiki=item_get_values --></div>
+
<!-- Pod2Wiki=item_render_input_field_actual --></div>
===$values = $field-&gt;get_values( $handle, $dataset, %opts )===
+
===$xhtml = $field-&gt;render_input_field_actual( $session, $value, [$dataset], [$staff], [$hidden_fields], [$obj], [$basename] )===
  
Return a reference to an array of all the values of this field.  
+
Return the XHTML of the fields for an form which will allow a user to input metadata to this field. $value is the default value for this field.
 +
 
 +
Unlike render_input_field, this function does not use the render_input property, even if it's set.
 +
 
 +
The $obj is the current state of the object this field is associated  with, if any.
 +
 
 +
<div style='background-color: #e8e8f; 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_sql_names --></div>
 +
===@sqlnames = $field-&gt;get_sql_names===
 +
 
 +
Return the names of this field's columns as they appear in a SQL table.
 +
 
 +
<div style='background-color: #e8e8f; 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_browsable --></div>
 +
===$boolean = $field-&gt;is_browsable===
 +
 
 +
Return true if this field can be "browsed". ie. Used as a view.
 +
 
 +
<div style='background-color: #e8e8f; 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_all_values --></div>
 +
===$values = $field-&gt;all_values( %opts )===
 +
 
 +
Return a reference to an array of all the values of this field. For fields like "subject" or "set" it returns all the variations. For fields like "text" return all  the distinct values from the database.
 +
 
 +
Results are sorted according to the ordervalues of the current session.
 +
 
 +
<div style='background-color: #e8e8f; 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_id_from_value --></div>
 +
===$id = $field-&gt;get_id_from_value( $session, $value )===
 +
 
 +
Returns a unique id for $value or "NULL" if $value is undefined.
 +
 
 +
<div style='background-color: #e8e8f; 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 -->
  
For fields like "subject" or "set" it returns all the variations.
 
  
For fields like "text" return all the distinct values from the database.
+
<!-- Pod2Wiki=item_get_value_from_id --></div>
 +
===$value = $field-&gt;get_value_from_id( $session, $id )===
  
Results are sorted according to the ordervalues of the $handle.
+
Returns the value from $id or undef if $id is "NULL".
  
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
Line 250: Line 423:
  
  
<!-- Pod2Wiki=item_get_value_label --></div>
+
<!-- Pod2Wiki=item_render_value_label --></div>
===$xhtml = $field-&gt;get_value_label( $handle, $value )===
+
===$xhtml = $field-&gt;render_value_label( $value )===
  
 
Return an XHTML DOM object describing the given value. Normally this is just the value, but in the case of something like a "set" field  this returns the name of the option in the current language.
 
Return an XHTML DOM object describing the given value. Normally this is just the value, but in the case of something like a "set" field  this returns the name of the option in the current language.
 +
 +
<div style='background-color: #e8e8f; 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_ordervalue --></div>
 +
===$ov = $field-&gt;ordervalue( $value, $session, $langid, $dataset )===
 +
 +
Return a string representing this value which can be used to sort it into order by comparing it alphabetically.
 +
 +
<div style='background-color: #e8e8f; 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_xml_to_epdata --></div>
 +
===$epdata = $field-&gt;xml_to_epdata( $session, $xml, %opts )===
 +
 +
Populates $epdata based on $xml.
 +
 +
<div style='background-color: #e8e8f; 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_default_value --></div>
 +
===$value = $field-&gt;get_default_value( $session )===
 +
 +
Return the default value for this field. This is only applicable to very simple cases such as timestamps, auto-incremented values etc.
 +
 +
Any complex initialisation should be done in the "set_eprint_automatic_fields" callback (or the equivalent for the given object).
 +
 +
<div style='background-color: #e8e8f; 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_index_codes --></div>
 +
===( $terms, $grep_terms, $ignored ) = $field-&gt;get_index_codes( $session, $value )===
 +
 +
Get indexable terms from $value. $terms is a reference to an array of strings to index. $grep_terms is a reference to an array of terms to add to the grep index. $ignored is a reference to an array of terms that should be ignored (e.g. stop words in a free-text field).
 +
 +
<div style='background-color: #e8e8f; 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_split_search_value --></div>
 +
===@terms = $field-&gt;split_search_value( $session, $value )===
 +
 +
Split $value into terms that can be used to search against this field.
 +
 +
<div style='background-color: #e8e8f; 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_search_conditions --></div>
 +
===$cond = $field-&gt;get_search_conditions( $session, $dataset, $value, $match, $merge, $mode )===
 +
 +
Return a {{API:PodLink|file=Search/Condition|package_name=Search::Condition|section=|text=Search::Condition}} for $value based on this field.
 +
 +
<div style='background-color: #e8e8f; 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_search_conditions_not_ex --></div>
 +
===$cond = $field-&gt;get_search_conditions_not_ex( $session, $dataset, $value, $match, $merge, $mode )===
 +
 +
Return the search condition for a search which is not-exact ($match ne "EX").
  
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>

Revision as of 16:33, 12 February 2010


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::MetaField - A single metadata field.

User Comments


DESCRIPTION

Theis object represents a single metadata field, not the value of that field. A field belongs (usually) to a dataset and has a large number of properties. Optional and required properties vary between types.

"type" is the most important property, it is the type of the metadata field. For example: "text", "name" or "date".

A full description of metadata types and properties is in the eprints documentation and will not be duplicated here.

User Comments


$field = EPrints::MetaField->new( %properties )

Create a new metafield. %properties is a hash of the properties of the field, with the addition of "dataset", or if "dataset" is not set then "confid" and "repository" must be provided instead.

Some field types require certain properties to be explicitly set. See the main documentation.

User Comments


$field->final

This method tells the metafield that it is now read only. Any call to set_property will produce a abort error.

User Comments


$field->set_property( $property, $value )

Set the named property to the given value.

This should not be called on metafields unless they've been cloned first.

This method will cause an abort error if the metafield is read only.

In these cases a cloned version of the field should be used.

User Comments


$newfield = $field->clone

Clone the field, so the clone can be edited without affecting the original. Does not deep copy properties which are references - these should be set to new values, rather than the contents altered. Eg. don't push to a cloned options list, replace it.

User Comments


$repository = $field->repository

Return the EPrints::Repository to which this field belongs.

User Comments


$dataset = $field->dataset

Return the EPrints::DataSet to which this field belongs, or undef.

User Comments


$xhtml = $field->render_name

Render the name of this field as an XHTML object.

User Comments


$label = $field->display_name( $session )

DEPRECATED! Can't be removed because it's used in 2.2's default ArchiveRenderConfig.pm

Return the UTF-8 encoded name of this field, in the language of the $session.

User Comments


$xhtml = $field->render_help

Return the help information for a user inputing some data for this field as an XHTML chunk.

User Comments


$xhtml = $field->render_input_field( $session, $value, [$dataset], [$staff], [$hidden_fields], $obj, [$basename] )

Return the XHTML of the fields for an form which will allow a user to input metadata to this field. $value is the default value for this field.

The actual function called may be overridden from the config.

User Comments


$value = $field->form_value( $session, $object, [$prefix] )

Get a value for this field from the CGI parameters, assuming that the form contained the input fields for this metadata field.

User Comments


$name = $field->name

Return the name of this field.

User Comments


$type = $field->type

Return the type of this field.

User Comments


$value = $field->property( $property )

Return the value of the given property.

Special note about "required" property: It only indicates if the field is always required. You must query the dataset to check if it is required for a specific type.

User Comments


$boolean = $field->is_type( @typenames )

Return true if the type of this field is one of @typenames.

User Comments


$xhtml = $field->render_value( $session, $value, [$alllangs], [$nolink], $object )

Render the given value of this given string as XHTML DOM. If $alllangs is true and this is a multilang field then render all language versions, not just the current language (for editorial checking). If $nolink is true then don't make this field a link, for example subject fields might otherwise link to the subject view page.

If render_value or render_single_value properties are set then these control the rendering instead.

User Comments


$xhtml = $field->render_value_no_multiple( $session, $value, $alllangs, $nolink, $object )

Render the XHTML for a non-multiple value. Can be either a from a non-multiple field, or a single value from a multiple field.

Usually just used internally.

User Comments


$xhtml = $field->render_value_withopts( $session, $value, $nolink, $object )

Render a single value but adding the render_opts features.

This uses either the field specific render_single_value or, if one is configured, the render_single_value specified in the config.

Usually just used internally.

User Comments


$out_list = $field->sort_values( $session, $in_list )

Sorts the in_list into order, based on the "order values" of the values in the in_list. Assumes that the values are not a list of multiple values. [ [], [], [] ], but rather a list of single values.

User Comments


@values = $field->list_values( $value )

Return a list of every distinct value in this field.

- for simple fields: return ( $value )
- for multiple fields: return @{$value}
 

This function is used by the item_matches method in Search.

User Comments


$value = $field->most_local( $session, $value )

If this field is a multilang field then return the version of the value most useful for the language of the session. In order of preference: The language of the session, the default language for the repository, any language at all. If it is not a multilang field then just return $value.

User Comments


$value2 = $field->call_property( $property, @args )

Call the method described by $property. Pass it the arguments and return the result.

The property may contain either a code reference, or the scalar name of a method.

User Comments


$val = $field->value_from_sql_row( $session, $row )

Shift and return the value of this field from the database input $row.

User Comments


@row = $field->sql_row_from_value( $session, $value )

Return a list of values to insert into the database based on $value.

The values will normally be passed to DBI/bind_param:

 $sth->bind_param( $idx, $row[0] )
 

If the value is an array ref it gets expanded:

 $sth->bind_param( $idx, @{$row[0]} )
 

This is necessary to support binding LOB data under various databases.

User Comments


%opts = $field->get_sql_properties( $session )

Map the relevant SQL properties for this field to options passed to EPrints::Database::get_column_type().

User Comments


@types = $field->get_sql_type( $session )

Return the SQL column types of this field, used for creating tables.

User Comments


$field = $field->create_ordervalues_field( $session [, $langid ] )

Return a new field object that this field can use to store order values, optionally for language $langid.

User Comments


$sql = $field->get_sql_index

Return the columns that an index should be created over.

User Comments


$xhtml_dom = $field->render_single_value( $session, $value )

Returns the XHTML representation of the value. The value will be non-multiple. Just the simple value.

User Comments


$xhtml = $field->render_input_field_actual( $session, $value, [$dataset], [$staff], [$hidden_fields], [$obj], [$basename] )

Return the XHTML of the fields for an form which will allow a user to input metadata to this field. $value is the default value for this field.

Unlike render_input_field, this function does not use the render_input property, even if it's set.

The $obj is the current state of the object this field is associated with, if any.

User Comments


@sqlnames = $field->get_sql_names

Return the names of this field's columns as they appear in a SQL table.

User Comments


$boolean = $field->is_browsable

Return true if this field can be "browsed". ie. Used as a view.

User Comments


$values = $field->all_values( %opts )

Return a reference to an array of all the values of this field. For fields like "subject" or "set" it returns all the variations. For fields like "text" return all the distinct values from the database.

Results are sorted according to the ordervalues of the current session.

User Comments


$id = $field->get_id_from_value( $session, $value )

Returns a unique id for $value or "NULL" if $value is undefined.

User Comments


$value = $field->get_value_from_id( $session, $id )

Returns the value from $id or undef if $id is "NULL".

User Comments


$xhtml = $field->render_value_label( $value )

Return an XHTML DOM object describing the given value. Normally this is just the value, but in the case of something like a "set" field this returns the name of the option in the current language.

User Comments


$ov = $field->ordervalue( $value, $session, $langid, $dataset )

Return a string representing this value which can be used to sort it into order by comparing it alphabetically.

User Comments


$epdata = $field->xml_to_epdata( $session, $xml, %opts )

Populates $epdata based on $xml.

User Comments


$value = $field->get_default_value( $session )

Return the default value for this field. This is only applicable to very simple cases such as timestamps, auto-incremented values etc.

Any complex initialisation should be done in the "set_eprint_automatic_fields" callback (or the equivalent for the given object).

User Comments


( $terms, $grep_terms, $ignored ) = $field->get_index_codes( $session, $value )

Get indexable terms from $value. $terms is a reference to an array of strings to index. $grep_terms is a reference to an array of terms to add to the grep index. $ignored is a reference to an array of terms that should be ignored (e.g. stop words in a free-text field).

User Comments


@terms = $field->split_search_value( $session, $value )

Split $value into terms that can be used to search against this field.

User Comments


$cond = $field->get_search_conditions( $session, $dataset, $value, $match, $merge, $mode )

Return a Search::Condition for $value based on this field.

User Comments


$cond = $field->get_search_conditions_not_ex( $session, $dataset, $value, $match, $merge, $mode )

Return the search condition for a search which is not-exact ($match ne "EX").

User Comments