VENOM: Entity fixed JSON
EntityManger added return value EntityManager added getFirst Fixed Some Admin shit :)
This commit is contained in:
parent
eb6770204a
commit
6523e77742
7 changed files with 61 additions and 116 deletions
|
|
@ -20,6 +20,15 @@ abstract class Entity implements JsonSerializable
|
|||
|
||||
// Override this if you want special fields :)
|
||||
|
||||
public function getLoadedFieldValues(): array
|
||||
{
|
||||
$keyValue = [];
|
||||
foreach ($this->loadedFields as $var) {
|
||||
$keyValue[$var] = $this->$var;
|
||||
}
|
||||
return $keyValue;
|
||||
}
|
||||
|
||||
public function getFieldsToWrite(): array
|
||||
{
|
||||
if ($this->fields !== null) {
|
||||
|
|
@ -33,9 +42,10 @@ abstract class Entity implements JsonSerializable
|
|||
unset($vars[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$allLoaded) {
|
||||
foreach ($vars as $key => $var) {
|
||||
if (!in_array($var, $this->loadedFields)) {
|
||||
if (!in_array($key, $this->loadedFields)) {
|
||||
unset($vars[$key]);
|
||||
}
|
||||
}
|
||||
|
|
@ -104,7 +114,7 @@ abstract class Entity implements JsonSerializable
|
|||
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
return $this->getFieldsToWrite();
|
||||
return $this->getLoadedFieldValues();
|
||||
}
|
||||
|
||||
public function preSave()
|
||||
|
|
|
|||
|
|
@ -50,10 +50,10 @@ class EntityManager
|
|||
return null;
|
||||
}
|
||||
|
||||
public function saveAll()
|
||||
public function saveAll(): bool
|
||||
{
|
||||
if (count($this->entities) === 0) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
$this->db->start();
|
||||
|
|
@ -64,10 +64,12 @@ class EntityManager
|
|||
} catch (Exception $ex) {
|
||||
trigger_error($ex->getMessage());
|
||||
$this->db->rollBack();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function deleteEntities()
|
||||
public function deleteEntities(): bool
|
||||
{
|
||||
try {
|
||||
$this->db->start();
|
||||
|
|
@ -78,7 +80,9 @@ class EntityManager
|
|||
} catch (Exception $ex) {
|
||||
trigger_error($ex->getMessage());
|
||||
$this->db->rollBack();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function clearAll()
|
||||
|
|
@ -118,6 +122,11 @@ class EntityManager
|
|||
return $this->entities;
|
||||
}
|
||||
|
||||
public function getFirst(): ?Entity
|
||||
{
|
||||
return $this->entities[0] ?? null;
|
||||
}
|
||||
|
||||
private function addEntities(array $entities)
|
||||
{
|
||||
foreach ($entities as $entity) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue