/** * {@inheritdoc} */ public function deleteSelection(Selection $selection) { $sqlString = 'DELETE FROM ' . $this->owner->quoteModel($this->name); if ($selection->getPredicate() !== null) { $sqlString .= ' WHERE ' . $selection->getPredicate()->toString($this->owner); } $ordering = $selection->getOrdering(); if (count($ordering)) { $columns = array(); foreach ($ordering as $orderBy) { $columns[] = $this->escapeQuery($orderBy[0]) . ($orderBy[1] ? ' DESC' : ' ASC'); } $sqlString .= ' ORDER BY ' . implode(', ', $columns); } $limit = $selection->getLimit(); if (isset($limit)) { $sqlString .= ' ' . $this->owner->sqlLimitOffset($limit); } return $this->owner->execute($sqlString); }
/** * {@inheritdoc} */ public function delete(Selection $selection) { $data = $this->getData(); $data = self::sortAll($data, $selection->getOrdering()); $limit = $selection->getLimit(); $predicate = $selection->getPredicate(); $count = 0; foreach ($data as $key => $record) { if ($predicate($record)) { $this->deleteKey($key); $count++; if (isset($limit) and $count >= $limit) { break; } } } return $count; }