public function findBy(array $columns, $order = null, $limit = null, $offset = null)
{
$this->finder = array_merge($this->finder, $columns);
// Build the SQL.
$this->sql->select();
$i = 1;
foreach ($columns as $key => $value) {
if (strpos($value, '%') !== false) {
$this->sql->select()->where()->like($key, $this->getPlaceholder($key, $i));
$i++;
} else {
if (null === $value) {
$this->sql->select()->where()->isNull($key);
} else {
$this->sql->select()->where()->equalTo($key, $this->getPlaceholder($key, $i));
$i++;
}
}
}
// Set the limit, if passed
if (null !== $limit) {
$this->sql->select()->limit($this->sql->adapter()->escape($limit));
}
// Set the offset, if passed
if (null !== $offset) {
$this->sql->select()->offset($this->sql->adapter()->escape($offset));
}
// Set the SQL query to a specific order, if given.
if (null !== $order) {
$ord = $this->getOrder($order);
$this->sql->select()->orderBy($ord['by'], $this->sql->adapter()->escape($ord['order']));
}
$params = array();
foreach ($columns as $key => $value) {
if (null !== $value) {
$params[$key] = $value;
}
}
// Prepare the statement, bind the parameters, execute the statement and set the return results.
$this->sql->adapter()->prepare($this->sql->render(true));
$this->sql->adapter()->bindParams($params);
$this->sql->adapter()->execute();
$this->setResults();
}