Custom code for sorting Items in a collection works in local but not in remote

Sorting items in a page such as my-omeka/collections/show/2 doesn’t work in the fundation theme

I tried to fixed it by these lines of code

// Getting and sorting Items
parse_str($_SERVER['QUERY_STRING'], $queryArray);
if (array_key_exists('sort_field', $queryArray) && array_key_exists('sort_dir', $queryArray)):
$itemsSortField = $queryArray['sort_field'];
$itemsSortDir = $queryArray['sort_dir'];
    else:
$itemsSortField = 'Dublin Core,Title';
$itemsSortDir = 'a';
endif;
$items = get_records('Item', array('collection' => $collection, 'sort_field' => $itemsSortField, 'sort_dir' => $itemsSortDir));
set_loop_records('items', $items);

// To high light the sorting link
 $sortParam = Omeka_Db_Table::SORT_PARAM;
 $sortDirParam = Omeka_Db_Table::SORT_DIR_PARAM;
 $req = Zend_Controller_Front::getInstance()->getRequest();
 $req->setParam($sortParam, $itemsSortField);
$req->setParam($sortDirParam, $itemsSortDir);

....

<?php foreach (get_loop_records('items', $items) as $item): ?>
        <?php get_view()->setCurrentRecord('Item', $item); ?>

 ....
 <?php endforeach; ?>

It works on local wamp (Omeka 3.0.1) but not on a remote server (Omeka 3.0.2)

Any glue ?

Need more infos ?

Thank you for your help !

When you say it doesn’t work you mean just that it doesn’t sort?

I think QUERY_STRING should generally be available but it’s not the normal way to get at the query string parameters in PHP. Have you tried using $_GET instead (it’s just the query string parameters automatically parsed into an array)? I’m not sure that would be the problem but it jumps out at me as odd.

Thank you for your answer.

Yes, it doesn’t sort !

I rewrited my code following what I could see in core Omeka

// Getting and sorting Items
$sortParam = Omeka_Db_Table::SORT_PARAM;
$sortDirParam = Omeka_Db_Table::SORT_DIR_PARAM;
$req = Zend_Controller_Front::getInstance()->getRequest();
$itemsSortField = trim($req->getParam($sortParam));
$itemsSortDir = trim($req->getParam($sortDirParam));

if (!$itemsSortField):
$itemsSortField = 'Dublin Core,Title';
// To high light the sorting link
$req->setParam($sortParam, $itemsSortField);
endif;
if (!$itemsSortDir):
$itemsSortDir = 'a';
// To high light the sorting link
$req->setParam($sortDirParam, $itemsSortDir);
endif;

$items = get_records('Item', array('collection' => $collection, $sortParam => $itemsSortField, 
$sortDirParam => $itemsSortDir));
 set_loop_records('items', $items);

Once again It’s works on my local wamp, but not on the remote server.

How to get the query generated by

   get_records('Item', array('collection' => $collection, $sortParam => $itemsSortField, 
$sortDirParam => $itemsSortDir));

?

I feel like it could be the problem…

Are either or both of these sites visible so you should share a link or links to them? Does the sorting work properly on the items browse pages of these sites?

get_records uses the Table model classes to build the query it uses, but that really shouldn’t change between servers.

The website is not public yet…
We might get ride of this functionnality as is not really relevant on this page.
I’ll let you know.
Thank you for trying to help me !

In general I’d look for other possible differences, if any. Something like the use of Item Order on one site but not the other, or some other plugin that affects sorting.

This topic was automatically closed 250 days after the last reply. New replies are no longer allowed.