Code: Select all
public function search($type = null, $query = null)
{
// you can't sort by "all" so sort by name if that is the type
$order = ($type != 'all') ? $type : 'name';
if (is_null($query)) $query = '';
$where = array(); // when this is empty, the fetchAll below will fetch "ALL"
$searchtypes = array(
'name' => array(
'where' => 'name LIKE ?',
'values' => "%" . $query . "%"
),
'city' => array(
'where' => 'city LIKE ?',
'values' => $query
),
'state' => array(
'where' => 'state LIKE ?',
'values' => $query . "%"
),
'zip_code' => array(
'where' => 'zip_code LIKE ?',
'values' => $query . "%"
)
);
foreach ($searchtypes as $searchtype => $search)
{
if (in_array($searchtype, array('all', $type)))
{
$where[] = $this->getAdapter()->quoteInto($search['where'], $search['values']);
}
}
$return = $this->fetchAll($where, $order);
return $return->toArray();
}