Pop\Db\Record\Prepared::delete PHP Метод

delete() публичный Метод

Delete the database record.
public delete ( array $columnsPassed, array $columns = null ) : void
$columnsPassed array
$columns array
Результат void
    public function delete($columnsPassed, array $columns = null)
    {
        $this->columns = $columnsPassed;
        if (null === $this->primaryId) {
            if (null === $columns && count($this->finder) == 0) {
                throw new Exception('The column and value parameters were not defined to describe the row(s) to delete.');
            } else {
                if (null === $columns) {
                    $columns = $this->finder;
                }
            }
            $this->sql->delete();
            $i = 1;
            foreach ($columns as $key => $value) {
                if (null === $value) {
                    $this->sql->delete()->where()->isNull($this->sql->adapter()->escape($key));
                } else {
                    $this->sql->delete()->where()->equalTo($this->sql->adapter()->escape($key), $this->getPlaceholder($key, $i));
                    $i++;
                }
            }
            $params = array();
            foreach ($columns as $key => $value) {
                if (null !== $value) {
                    $params[$this->primaryId[$key]] = $value;
                }
            }
            $this->sql->adapter()->prepare($this->sql->render(true));
            $this->sql->adapter()->bindParams($params);
            $this->sql->adapter()->execute();
            $this->columns = array();
            $this->rows = array();
        } else {
            $this->sql->delete();
            // Specific column override.
            if (null !== $columns) {
                $i = 1;
                foreach ($columns as $key => $value) {
                    if (null === $value) {
                        $this->sql->delete()->where()->isNull($this->sql->adapter()->escape($key));
                    } else {
                        $this->sql->delete()->where()->equalTo($this->sql->adapter()->escape($key), $this->getPlaceholder($key, $i));
                        $i++;
                    }
                }
                // Else, continue with the primaryId column(s)
            } else {
                if (is_array($this->primaryId)) {
                    foreach ($this->primaryId as $key => $value) {
                        if (null === $this->columns[$value]) {
                            $this->sql->delete()->where()->isNull($this->sql->adapter()->escape($value));
                        } else {
                            $this->sql->delete()->where()->equalTo($this->sql->adapter()->escape($value), $this->getPlaceholder($value, $key + 1));
                        }
                    }
                } else {
                    $this->sql->delete()->where()->equalTo($this->sql->adapter()->escape($this->primaryId), $this->getPlaceholder($this->primaryId));
                }
            }
            $this->sql->adapter()->prepare($this->sql->render(true));
            // Specific column override.
            if (null !== $columns) {
                $params = $columns;
                // Else, continue with the primaryId column(s)
            } else {
                if (is_array($this->primaryId)) {
                    $params = array();
                    foreach ($this->primaryId as $value) {
                        if (null !== $this->columns[$value]) {
                            $params[$value] = $this->columns[$value];
                        }
                    }
                } else {
                    $params = array($this->primaryId => $this->columns[$this->primaryId]);
                }
            }
            $this->sql->adapter()->bindParams((array) $params);
            $this->sql->adapter()->execute();
            $this->columns = array();
            $this->rows = array();
        }
    }