Facturacion
This commit is contained in:
@ -31,18 +31,25 @@ abstract class Repository implements Define\Repository
|
||||
|
||||
public function remove(Define\Model $model): void
|
||||
{
|
||||
$query = "DELETE FROM `{$this->getTable()}` WHERE `{$this->getKey()}` = ?";
|
||||
$this->connection->execute($query, [$model->getId()]);
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->delete()->from($this->getTable())
|
||||
->where("{$this->getKey()} = ?");
|
||||
$this->connection->execute($query, [$model->id]);
|
||||
}
|
||||
|
||||
public function fetchById(int $id): Define\Model
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `{$this->getKey()}` = ?";
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where("{$this->getKey()} = ?");
|
||||
return $this->fetchOne($query, [$id]);
|
||||
}
|
||||
public function fetchAll(): array
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}`";
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable());
|
||||
return $this->fetchMany($query);
|
||||
}
|
||||
|
||||
@ -96,9 +103,11 @@ abstract class Repository implements Define\Repository
|
||||
}
|
||||
protected function saveNew(array $columns, array $values): int
|
||||
{
|
||||
$columns_string = implode(', ', array_map(function($column) {return "`{$column}`";}, $columns));
|
||||
$columns_questions = implode(', ', array_fill(0, count($columns), '?'));
|
||||
$query = "INSERT INTO `{$this->getTable()}` ({$columns_string}) VALUES ($columns_questions)";
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->insert()
|
||||
->into($this->getTable())
|
||||
->columns($columns)
|
||||
->values(array_fill(0, count($columns), '?'));
|
||||
$this->connection->execute($query, $values);
|
||||
return $this->connection->getPDO()->lastInsertId();
|
||||
}
|
||||
@ -117,7 +126,10 @@ abstract class Repository implements Define\Repository
|
||||
return $model;
|
||||
}
|
||||
$columns_string = implode(', ', array_map(function($property) {return "`{$property}` = ?";}, $changes));
|
||||
$query = "UPDATE `{$this->getTable()}` SET {$columns_string} WHERE `{$this->getKey()}` = ?";
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->update($this->getTable())
|
||||
->set($columns_string)
|
||||
->where("{$this->getKey()} = ?");
|
||||
$values []= $model->{$this->getKey()};
|
||||
$this->connection->execute($query, $values);
|
||||
return $this->fetchById($model->{$this->getKey()});
|
||||
|
Reference in New Issue
Block a user