public function filtrarPorDescricao($descricao, $fields = null)
{
$fields = $this->prepareFields($fields);
$dbst = $this->db->prepare(" SELECT $fields FROM ". static::TABLE ." WHERE descricao ILIKE :descricao ");
$dbst->bindValue(':descricao', $descricao, \PDO::PARAM_STR);
return $this->execute($dbst);
}
protected function filtrar ($where, $whereValues, $fields = null)
{
$fields = $this->prepareFields($fields);
$order = null;
if(!empty($this->order)) {
$ords = [];
foreach($this->order as $ord => $dir) {
$ords[] = "{$ord} {$dir}";
}
$order = ' ORDER BY ' . implode(',', $ords);
}
$dbst = $this->db->prepare(" SELECT {$fields} FROM ". static::TABLE ." WHERE {$where} {$order} ");
if(is_array($whereValues) && !empty($whereValues)) {
foreach ($whereValues as $param => $value) {
if(strpos($value, ',') === false) {
$typeParam = is_int($value) ? \PDO::PARAM_INT : \PDO::PARAM_STR;
$dbst->bindValue(':'. $param, $value, $typeParam);
}
}
}
return $this->execute($dbst);
}
public function getAll($limit = null)
{
if(!empty($limit)) {
$limit = ' LIMIT ' . (int)$limit;
}
$order = null;
if(!empty($this->order)) {
$ords = [];
foreach($this->order as $ord => $dir) {
$ords[] = "{$ord} {$dir}";
}
$order = ' ORDER BY ' . implode(',', $ords);
}
$fields = $this->prepareFields();
return $this->execute($this->db->prepare(" SELECT $fields FROM " . static::TABLE ." {$order} {$limit} "));
}
public function order($column, $direction = 'ASC')
{
if(!empty($column) && !empty($direction)) {
$this->order[$column] = $direction;
}
return $this;
}