Auth, Login, Home, Venta->Listados->Precios
This commit is contained in:
46
app/src/Repository/User.php
Normal file
46
app/src/Repository/User.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace Incoviba\Repository;
|
||||
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Common\Ideal;
|
||||
use Incoviba\Model;
|
||||
|
||||
class User extends Ideal\Repository
|
||||
{
|
||||
public function __construct(Define\Connection $connection)
|
||||
{
|
||||
parent::__construct($connection);
|
||||
$this->setTable('users');
|
||||
}
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
{
|
||||
$map = [
|
||||
'name' => [],
|
||||
'password' => [],
|
||||
'enabled' => [
|
||||
'function' => function($data) {
|
||||
return $data['enabled'] != 0;
|
||||
}
|
||||
]
|
||||
];
|
||||
return $this->parseData(new Model\User(), $data, $map);
|
||||
}
|
||||
|
||||
public function save(Define\Model $model): Define\Model
|
||||
{
|
||||
$model->id = $this->saveNew(['name', 'password', 'enabled'], [$model->name, $model->password, $model->enabled ? 1 : 0]);
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
{
|
||||
return $this->update($model, ['name', 'password', 'enabled'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByName(string $name): Model\User
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `name` = ?";
|
||||
return $this->fetchOne($query, [$name]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user