ajout model de type readonly pour une requête de select uniquement
This commit is contained in:
@@ -12,22 +12,32 @@ class Model implements JsonSerializable
|
|||||||
protected string $connection = "";
|
protected string $connection = "";
|
||||||
protected string $pk;
|
protected string $pk;
|
||||||
private bool $new;
|
private bool $new;
|
||||||
|
private bool $ro;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct($ro = false)
|
||||||
{
|
{
|
||||||
$this->new = true;
|
$this->new = true;
|
||||||
$this->values = array();
|
$this->values = array();
|
||||||
$this->updated = array();
|
$this->updated = array();
|
||||||
$this->pk = "id";
|
$this->pk = "id";
|
||||||
|
$this->ro = $ro;
|
||||||
$this->initTable();
|
$this->initTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function initTable(): void
|
private function initTable(): void
|
||||||
|
{
|
||||||
|
if(!$this->ro)
|
||||||
{
|
{
|
||||||
if ($this->table == "") {
|
if ($this->table == "") {
|
||||||
$this->table = $this->getDefaultTableName();
|
$this->table = $this->getDefaultTableName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->table = "ReadOnlyModel";
|
||||||
|
$this->pk = "__idpk";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function getTable(): string
|
public function getTable(): string
|
||||||
{
|
{
|
||||||
@@ -89,6 +99,8 @@ class Model implements JsonSerializable
|
|||||||
public function save(): bool
|
public function save(): bool
|
||||||
{
|
{
|
||||||
$ret = false;
|
$ret = false;
|
||||||
|
if(!$this->ro)
|
||||||
|
{
|
||||||
$qb = $this->newQueryBuilder();
|
$qb = $this->newQueryBuilder();
|
||||||
if ($this->new) {
|
if ($this->new) {
|
||||||
$query = $qb->getPreparedQuery($this->values);
|
$query = $qb->getPreparedQuery($this->values);
|
||||||
@@ -114,6 +126,7 @@ class Model implements JsonSerializable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user