RegionRestriction::wildcard_sort PHP Method

wildcard_sort() public static method

Useful because we are only interested in the wildcard, and not sorting of other values.
public static wildcard_sort ( $field, $direction = "ASC" )
    public static function wildcard_sort($field, $direction = "ASC")
    {
        return "CASE \"{$field}\" WHEN '*' THEN 1 ELSE 0 END {$direction}";
    }

Usage Example

 function getRate($address = null)
 {
     if (!$address) {
         $address = singleton('Address');
     }
     $where = array("\"TaxRate\".\"TaxClassID\" = {$this->ID}", RegionRestriction::address_filter($address));
     $sort = implode(', ', array(RegionRestriction::wildcard_sort("PostalCode"), RegionRestriction::wildcard_sort("City"), RegionRestriction::wildcard_sort("State"), RegionRestriction::wildcard_sort("Country"), "\"Rate\" ASC"));
     if ($rate = DataObject::get_one("TaxRate", "(" . implode(") AND (", $where) . ")", true, $sort)) {
         return $rate->Rate;
     }
     return 0;
 }