Skip to content

Instantly share code, notes, and snippets.

@jeremyboggs
Last active January 3, 2017 08:09
Show Gist options
  • Save jeremyboggs/3319ce091a751912101943dc1f73c8c6 to your computer and use it in GitHub Desktop.
Save jeremyboggs/3319ce091a751912101943dc1f73c8c6 to your computer and use it in GitHub Desktop.
<?php
class CustomItemsBrowsePlugin extends Omeka_Plugin_AbstractPlugin
{
protected $_hooks = array(
'items_browse_sql'
);
public function hookItemsBrowseSql($args) {
$select = $args['select'];
$sort_string = "CASE WHEN et_sort.text REGEXP '<[^>]*>' = 1 THEN TRIM(SUBSTR(et_sort.text, INSTR(et_sort.text ,' '))) ELSE et_sort.text END ASC";
$select->reset(Zend_Db_Select::ORDER);
$sort_order = new Zend_Db_Expr($sort_string);
$select->order($sort_order);
get_db()->getTable('Item')->applySorting($select, 'Dublin Core,Title', 'ASC');
}
}
@jeremyboggs
Copy link
Author

@luku Thanks! For the correction, and for the suggestion on $sortDir. Yeah, as written this would fail on nested HTML, which is entirely possible to have. And agreed about the usefulness of a sort_key field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment