Sample Page - Field Highlighting - Pre/Post Custom HTML - Pedigree
This sample demonstrates field-level highlighting where you supply HTML snippets that Pedserve will use to enclose the HTML of specific field values.
To get the effect shown here you need to reimplement the hookHighlighting_GetForField hook. This shows how to enclose the HTML for all date of birth field values in a <font> tag. It sets a pre-HTML string of <font face="Arial" color="blue">, and a post-HTML string of </font>. The result is that a different font is always used for this field (irrespective of field value).
To see how the same code can highlight a search results page, click here.
To see how you can use a similar highlighting method at the record level, rather than the field level, click here.
To see how you can use a similar highlighting method at the record level, rather than the field level, click here.
Show/Hide Sample Code
# Hook function to determine highlighting for a specific
# field within a record - storing the required highlighting
# decorations in a supplied map.
#
# Arg 1 - table suffix
# Arg 2 - reference to map holding decoded highlight definition
# Arg 3 - context
# Arg 4 - reference to map into which highlight effects are to be stored
# Arg 5 - reference to map of field values
# Arg 6 - primary key
# Arg 7 - field name prefix
# Arg 8 - full field name
# Arg 9 - reference to map into which highlighting state can be stored
# for the current panel
# OPTIONAL
# Arg 10 - reference to map for future additional arguments; possibly undefined
sub hookHighlighting_GetForField {
my ($strTableSuffix, $rmHighlightingDef, $strContext, $rmEffects,
$rmFieldValues, $nPrimaryKey, $strFldPrefix, $strFullFldName,
$rmState, $rmArgsEx) = @_;
# You probably dont want to interfere with the correct working of
# pedserve's internally defined highlighting methods. So what you
# should do is make your highlighting definition identifiable
# - by including terms that you can test for here. Then you can
# defer to the default implementation when necessary.
my $fUseStdImpl = 1;
# Example that checks for the term 'myhighlighting=yes'
# in the highlighting definition, and if present handles it here.
# To use this, you would have to define a highlighting during the
# script startup with a call to &pdsSetHighlightingDef() e.g.
# &pdsSetHighlightingDef('A_myhighlighting',
# 'label=Highlight DOB;myhighlighting=yes;');
# Note also the check against $strTableSuffix to ensure this is only
# used with animal records, and the check that this is not a
# pedserve-private definition:
if (!defined($$rmHighlightingDef{'pdsprivate'}) &&
$strTableSuffix eq 'A' &&
defined($$rmHighlightingDef{'myhighlighting'}) &&
$$rmHighlightingDef{'myhighlighting'} eq 'yes') {
# Dont defer to standard implementation below:
$fUseStdImpl = 0;
# This demonstrates highlighting by setting HTML text that
# is to be inserted before+after all occurrences of a specific field,
# irrespective of the value of that field:
if ($strFullFldName eq $strFldPrefix.'A_DOB') {
# Use the font tag to change the font face to Arial, blue:
$$rmEffects{'customhtml_pre'} = '<font face="Arial" color="blue">';
$$rmEffects{'customhtml_post'} = '</font>';
# Set up an entry for the highlighting legend.
# Note that setting this to the empty string will cause it
# to be added to the legend with the field name but nothing else.
$$rmEffects{'customhtml_legend'} = '';
}
}
# If the above code has not handled this highlighting definition
# itself, defer to the standard implementation:
if ($fUseStdImpl) {
&pdsHookStdImpl_Highlighting_GetForField(
$strTableSuffix, $rmHighlightingDef, $strContext, $rmEffects,
$rmFieldValues, $nPrimaryKey, $strFldPrefix, $strFullFldName,
$rmState, $rmArgsEx);
}
}
This custom highlighting method uses the date of birth field ('A_DOB'). When Pedserve fetches data from the database, it does not automatically fetch all the fields - it only fetches those it needs. For this reason, when your custom highlighting method is selected, you need to take steps to ensure that Pedserve will pull any fields you need. You do this by reimplementing the hookHighlighting_GetExtraFlds hook:
Show/Hide Sample Code
# Hook function to return extra fields that are required by a given
# highlighting method.
#
# Arg 1 - table suffix
# Arg 2 - reference to map holding decoded highlight definition
# Arg 3 - context
# Arg 4 - field name prefix
# OPTIONAL
# Arg 4 - reference to map for future additional arguments; possibly undefined
sub hookHighlighting_GetExtraFlds {
my ($strTableSuffix, $rmHighlightingDef,
$strContext, $strFldPrefix, $rmArgsEx) = @_;
# You probably dont want to interfere with the correct working
# of pedserve's internally defined highlighting methods.
# So what you should do is make your highlighting definition
# identifiable - by including terms that you can test
# for here. Then you can defer to the default implementation
# when necessary.
my $fUseStdImpl = 1;
my $strReturn = '';
# Trivial example that checks for the term 'myhighlighting=yes'
# in the highlighting definition, and if present returns a specific
# field name. To use this, you would have to define a highlighting
# method during the script startup with a call to
# &pdsSetHighlightingDef() e.g.
# &pdsSetHighlightingDef('A_myhighlighting',
# 'label=Highlight DOB;myhighlighting=yes;');
# Note also the check against $strTableSuffix to ensure this is only
# used with animal records, and
# the check that this is not a pedserve-private definition:
if (!defined($$rmHighlightingDef{'pdsprivate'}) &&
$strTableSuffix eq 'A' &&
defined($$rmHighlightingDef{'myhighlighting'}) &&
$$rmHighlightingDef{'myhighlighting'} eq 'yes') {
# Dont defer to standard implementation below:
$fUseStdImpl = 0;
# Set the fields to return:
# (this example will use the date of birth field to apply specific
# highlights for given dates etc)
$strReturn = $strFldPrefix.'A_DOB';
}
# If the above code has not handled this highlighting definition itself,
# defer to the standard implementation:
if ($fUseStdImpl) {
$strReturn = &pdsHookStdImpl_Highlighting_GetExtraFlds($strTableSuffix,
$rmHighlightingDef, $strContext, $strFldPrefix, $rmArgsEx);
}
return $strReturn;
}