Skip to content
Snippets Groups Projects

add delete by with where string

Merged Patrick Barroca requested to merge delete_by_where_string into master
All threads resolved!
Compare and
4 files
+ 125
75
Preferences
Compare changes
Files
4
@@ -61,10 +61,8 @@ class Storm_Model_PersistenceStrategy_Db extends Storm_Model_PersistenceStrategy
return null;
}
public function update($data,$id) {
return $this->getTable()
->update($data, $this->_loader->getIdField(). "='" . $id . "'");
public function update($data, $id) {
return $this->getTable()->update($data, $this->_loader->getIdField(). "='" . $id . "'");
}
@@ -73,24 +71,33 @@ class Storm_Model_PersistenceStrategy_Db extends Storm_Model_PersistenceStrategy
}
public function deleteBy($clauses) {
public function deleteBy($where_or_clauses) {
if (!is_array($where_or_clauses))
return $this->getTable()->delete($where_or_clauses);
$where = [];
foreach($clauses as $key => $value) {
foreach($where_or_clauses as $key => $value)
$where []= $this->_generateWhereClauseForKeyAndValue($key, $value);
}
return $this->getTable()->delete(implode(' and ', $where));
}
protected function _generateWhereClauseForKeyAndValue($key, $value_or_array) {
if (!is_array($value_or_array))
return $key ."='" . $value_or_array . "'";
if ('where' == $key)
return '(' . $value_or_array . ')';
$operator = is_array($value_or_array)
? ' in (?)'
: '=?';
return $this->quoteInto($key . $operator, $value_or_array);
}
foreach ($value_or_array as &$value)
$value = '\'' . addslashes($value) . '\'';
return $key . ' in (' . implode(',', $value_or_array) . ')';
/** @see Zend_Db_Adapter_Abstract::quoteInto() */
public function quoteInto($text, $value, $type = null, $count = null) {
return $this->getTable()->getAdapter()->quoteInto($text, $value, $type, $count);
}
@@ -207,4 +214,3 @@ class Storm_Model_PersistenceStrategy_Db extends Storm_Model_PersistenceStrategy
$select->where($scope_field . '=?', $scope_value);
}
}
?>