Created
April 23, 2013 13:48
-
-
Save jeremyboggs/5443693 to your computer and use it in GitHub Desktop.
Converts Omeka's advanced search output into acceptable input for findBy().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Converts the advanced search output into acceptable input for findBy(). | |
* | |
* @see Omeka_Db_Table::findBy() | |
* @param array $query HTTP query string array | |
* @return array Array of findBy() parameters | |
*/ | |
function neatlinetime_convert_search_filters($query) { | |
$params = array(); | |
foreach($query as $paramName => $paramValue) { | |
if (is_string($paramValue) && trim($paramValue) == '') { | |
continue; | |
} | |
switch($paramName) { | |
case 'user': | |
if (is_numeric($paramValue)) { | |
$params['user'] = $paramValue; | |
} | |
break; | |
case 'public': | |
case 'featured': | |
case 'random': | |
case 'hasImage': | |
$params[$paramName] = is_true($paramValue); | |
break; | |
case 'recent': | |
if (!is_true($paramValue)) { | |
$params['recent'] = false; | |
} | |
break; | |
case 'tag': | |
case 'tags': | |
$params['tags'] = $paramValue; | |
break; | |
case 'search': | |
$params['search'] = $paramValue; | |
//Don't order by recent-ness if we're doing a search | |
unset($params['recent']); | |
break; | |
case 'advanced': | |
//We need to filter out the empty entries if any were provided | |
foreach ($paramValue as $k => $entry) { | |
if (empty($entry['element_id']) || empty($entry['type'])) { | |
unset($paramValue[$k]); | |
} | |
} | |
if (count($paramValue) > 0) { | |
$params['advanced_search'] = $paramValue; | |
} | |
break; | |
default: | |
$params[$paramName] = $paramValue; | |
break; | |
} | |
} | |
return $params; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment