public function statementBinds(array $conditions = array(), $ci = false)
{
if (count($conditions) == 0) {
return;
}
$binds = array();
$loopOnce = false;
foreach ($conditions as $condition) {
if (is_array($condition) && isset($condition['conditions'])) {
$subConditions = $condition['conditions'];
} else {
$subConditions = $conditions;
$loopOnce = true;
}
foreach ($subConditions as $column => $value) {
$bindValue = false;
// Handle binding depending on type
if (is_object($value)) {
if ($value instanceof \DateTime) {
// @todo Need to take into account column type for date formatting
$bindValue = (string) $value->format($this->dateTimeFormat());
} else {
$bindValue = (string) $value;
// Attempt cast of object to string (calls object's __toString method)
}
} elseif (is_bool($value)) {
$bindValue = (int) $value;
// Cast boolean to integer (false = 0, true = 1)
} elseif (!is_array($value)) {
$bindValue = $value;
}
// Bind given value
if (false !== $bindValue) {
// Column name with comparison operator
$colData = explode(' ', $column);
$operator = '=';
if (count($colData) > 2) {
$operator = array_pop($colData);
$colData = array(implode(' ', $colData), $operator);
}
$col = $colData[0];
if (false !== $ci) {
$col = $col . $ci;
}
$colParam = preg_replace('/\\W+/', '_', $col);
// Add to binds array and add to WHERE clause
$binds[$colParam] = $bindValue;
}
// Increment ensures column name distinction
// We need to do this whether it was used or not
// to maintain compatibility with statementConditions()
$ci++;
}
if ($loopOnce) {
break;
}
}
return $binds;
}