mirror of
https://codeberg.org/vlw/vlw.se.git
synced 2025-09-13 13:03:41 +02:00
fix: delete old, unused database class (#3)
A relic from the past which was never used. Reviewed-on: https://codeberg.org/vlw/vlw.se/pulls/3 Co-authored-by: Victor Westerlund <victor.vesterlund@gmail.com> Co-committed-by: Victor Westerlund <victor.vesterlund@gmail.com>
This commit is contained in:
parent
0483e092dd
commit
6dad22f226
2 changed files with 0 additions and 131 deletions
|
@ -1,57 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace VLW\Entities;
|
||||
|
||||
use Vegvisir\Path;
|
||||
use Reflect\Response;
|
||||
|
||||
use VLW\Client\API;
|
||||
use VLW\API\Endpoints;
|
||||
|
||||
require_once Path::root("src/client/API.php");
|
||||
require_once Path::root("api/src/Endpoints.php");
|
||||
|
||||
interface EntityInterface {}
|
||||
|
||||
abstract class Entity implements EntityInterface {
|
||||
public const ENTITY_ID = "id";
|
||||
|
||||
public readonly ?string $id;
|
||||
public readonly object $entity;
|
||||
public readonly Response $response;
|
||||
|
||||
protected readonly Api $api;
|
||||
protected readonly Endpoints $endpoint;
|
||||
|
||||
public function __construct(Endpoints $endpoint, ?string $id) {
|
||||
$this->id = $id;
|
||||
$this->api = new Api();
|
||||
$this->endpoint = $endpoint;
|
||||
|
||||
$this->resolve_entity_by_id();
|
||||
}
|
||||
|
||||
private function resolve_entity_by_id() {
|
||||
// Bail out wit a dummy Response if no id was provided
|
||||
if (!$this->id) {
|
||||
$this->response = new Response("", 404);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->response = $this->api
|
||||
->call($this->endpoint->value)
|
||||
->params([self::ENTITY_ID => $this->id])
|
||||
->get();
|
||||
|
||||
// Load response into entity object if successful
|
||||
if ($this->response->ok) {
|
||||
$this->entity = (object) $this->response->json()[0];
|
||||
}
|
||||
}
|
||||
|
||||
public function resolve(Endpoints $endpoint, array $params): array {
|
||||
$response = $this->api->call($endpoint->value)->params($params)->get();
|
||||
|
||||
return $response->ok ? $response->json() : [];
|
||||
}
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace VLW\Entities\Work;
|
||||
|
||||
use Vegvisir\Path;
|
||||
|
||||
require_once Path::root("src/entities/Entity.php");
|
||||
|
||||
class WorkEntity extends Entity {
|
||||
private array $individuals = [];
|
||||
private array $signatures = [];
|
||||
private array $documents = [];
|
||||
private array $studies = [];
|
||||
private array $notes = [];
|
||||
|
||||
public function __construct(string $id) {
|
||||
parent::__construct(Endpoints::WORK, $id);
|
||||
}
|
||||
|
||||
public function signatures(): array {
|
||||
if ($this->signatures) {
|
||||
return $this->signatures;
|
||||
}
|
||||
|
||||
foreach ($this->resolve(Endpoints::ICELDB_ANALYSES_SIGNATURES, ["ref_analysis_id" => $this->id]) as $rel) {
|
||||
$this->signatures[$rel["id"]] = $rel;
|
||||
$this->signatures[$rel["id"]]["user"] = $this->resolve(Endpoints::ICELDB_USERS, ["ref_user_id" => $rel["ref_user_id"]])[0];
|
||||
}
|
||||
|
||||
return $this->signatures;
|
||||
}
|
||||
|
||||
public function documents(): array {
|
||||
if ($this->documents) {
|
||||
return $this->documents;
|
||||
}
|
||||
|
||||
$this->documents = $this->resolve(Endpoints::ICELDB_ANALYSES_DOCUMENTS, ["ref_analysis_id" => $this->id]);
|
||||
return $this->documents;
|
||||
}
|
||||
|
||||
public function studies(): array {
|
||||
if ($this->studies) {
|
||||
return $this->studies;
|
||||
}
|
||||
|
||||
foreach ($this->resolve(Endpoints::ICELDB_STUDIES_ANALYSES, ["ref_analysis_id" => $this->id]) as $rel) {
|
||||
$this->studies[] = $this->resolve(Endpoints::ICELDB_STUDIES, ["id" => $rel["ref_study_id"]]);
|
||||
}
|
||||
|
||||
return $this->studies;
|
||||
}
|
||||
|
||||
public function notes(): array {
|
||||
if ($this->notes) {
|
||||
return $this->notes;
|
||||
}
|
||||
|
||||
$this->notes = $this->resolve(Endpoints::ICELDB_ANALYSES_NOTES, ["ref_analysis_id" => $this->id]);
|
||||
return $this->notes;
|
||||
}
|
||||
|
||||
public function individuals(): array {
|
||||
if ($this->individuals) {
|
||||
return $this->individuals;
|
||||
}
|
||||
|
||||
foreach ($this->resolve(Endpoints::ICELDB_ANALYSES_INDIVIDUALS, ["ref_analysis_id" => $this->id]) as $rel) {
|
||||
$this->individuals[] = $this->resolve(Endpoints::ICELDB_INDIVIDUALS, ["id" => $rel["ref_individual_id"]])[0];
|
||||
}
|
||||
|
||||
return $this->individuals;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue