Bug in Previous Page Link of Exhibit Builder + possible fix

Hi all,

I believe I have found a bug with the exhibit_builder_link_to_previous_exhibit_page() function.

Currently, if you are on the first page of a section and click the previous page link, it takes you to the FIRST page of the previous section, whereas one would expect it to take you to the LAST page of the previous section (this is even described as the desired behavior in the comments of the code in ExhibitPageFunctions.php).

Looking at the existing code, it does not pass the page parameter when in this situation, so it defaults to the first page.

Below is the existing code and the changes I made to give me the desired behavior. Please let me know if I am reporting this bug in the wrong place as I am new to the Omeka community.

Thanks,
Rob

Existing Code
/**
* Returns a link to the previous exhibit page
*
* @param string $text The label for the previous page link
* @param array $props
* @param ExhibitPage $exhibitPage If null, will use the current exhibit page
* @return string
**/
function exhibit_builder_link_to_previous_exhibit_page($text = "← Previous Page", $props = array(), $exhibitPage = null)
{
if (!$exhibitPage) {
$exhibitPage = exhibit_builder_get_current_page();
}

$exhibitSection = exhibit_builder_get_exhibit_section_by_id($exhibitPage->section_id);
$exhibit = exhibit_builder_get_exhibit_by_id($exhibitSection->exhibit_id);

if(!isset($props['class'])) {
$props['class'] = 'previous-page';
}

// If page object exists, grab link to previous exhibit page if exists. If it doesn't, grab
// a link to the last page on the previous exhibit section, if it exists.
if ($previousPage = $exhibitPage->previous()) {
return exhibit_builder_link_to_exhibit($exhibit, $text, $props, $exhibitSection, $previousPage);
} elseif ($previousSection = $exhibitSection->previous()) {
return exhibit_builder_link_to_exhibit($exhibit, $text, $props, $previousSection);
}
}

Changes I made to the code to add a page parameter

/**
* Returns a link to the previous exhibit page
*
* @param string $text The label for the previous page link
* @param array $props
* @param ExhibitPage $exhibitPage If null, will use the current exhibit page
* @return string
**/
function exhibit_builder_link_to_previous_exhibit_page($text = "← Previous Page", $props = array(), $exhibitPage = null)
{
if (!$exhibitPage) {
$exhibitPage = exhibit_builder_get_current_page();
}

$exhibitSection = exhibit_builder_get_exhibit_section_by_id($exhibitPage->section_id);
$exhibit = exhibit_builder_get_exhibit_by_id($exhibitSection->exhibit_id);

if(!isset($props['class'])) {
$props['class'] = 'previous-page';
}

// If page object exists, grab link to previous exhibit page if exists. If it doesn't, grab
// a link to the last page on the previous exhibit section, if it exists.
if ($previousPage = $exhibitPage->previous()) {
return exhibit_builder_link_to_exhibit($exhibit, $text, $props, $exhibitSection, $previousPage);
} elseif ($previousSection = $exhibitSection->previous()) {
//rob added this to fix previous page bug
foreach ($previousSection->Pages as $exhibitPage) {
$previousPage=$exhibitPage;
}
//end rob add -- put in page value below
return exhibit_builder_link_to_exhibit($exhibit, $text, $props, $previousSection, $previousPage);
}
}

Hmm, that does look like a bug, and it certainly goes against the comment that's there for that code.

Thanks for reporting it.