You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.3 KiB
49 lines
1.3 KiB
<?php |
|
|
|
namespace app\Repositories; |
|
|
|
use app\Core\Repository; |
|
use app\Models\UsuarioModel; |
|
use Exception; |
|
|
|
class UsuarioRepository extends Repository |
|
{ |
|
function config(): void |
|
{ |
|
$this->table = UsuarioModel::$table; |
|
} |
|
|
|
function list(array $params = []): array |
|
{ |
|
$table = $this->table; |
|
$query = "SELECT * FROM $table WHERE 1=1"; |
|
if ($params['matricula']) { |
|
$query .= " AND matricula = :matricula "; |
|
$dados['matricula'] = $params['matricula']; |
|
} |
|
if ($params['email']) { |
|
$query .= " AND email = :email "; |
|
$dados['email'] = $params['email']; |
|
} |
|
return $this->db->read($query, $dados)->fetchAll(); |
|
} |
|
|
|
function get(array $params = []) |
|
{ |
|
$table = $this->table; |
|
$query = "SELECT * FROM $table WHERE 1=1"; |
|
if ($params['matricula']) { |
|
$query .= " AND matricula = :matricula "; |
|
$dados['matricula'] = $params['matricula']; |
|
} |
|
|
|
if ($params['id']) { |
|
$query .= " AND id = :id "; |
|
$dados['id'] = $params['id']; |
|
} |
|
if (empty($params['matricula'])) { |
|
throw new Exception('Parâmetro matricula é obrigatório'); |
|
} |
|
return $this->db->read($query, $dados)->fetchAll(); |
|
} |
|
} |