value => $id, CoffeeTable::DATE_CREATED->value => $datetime ? $datetime->format(parent::DATE_FORMAT) : date(parent::DATE_FORMAT) ])) { throw new Exception("Failed to create Work entity"); } return new Coffee($id); } final public static function all(): array { return array_map(fn(array $work): Coffee => new Coffee($work[CoffeeTable::ID->value]), new Database() ->from(CoffeeTable::TABLE) ->order([CoffeeTable::DATE_CREATED->value => Order::DESC]) ->select(CoffeeTable::ID->value) ->fetch_all(MYSQLI_ASSOC) ); } final public static function count_week(): int { return new Database() ->from(Stats::TABLE) ->limit(1) ->select(Stats::COUNT_WEEK->value) ->fetch_assoc()[Stats::COUNT_WEEK->value] ?? 0; } final public static function count_week_average(): int { return new Database() ->from(Stats::TABLE) ->limit(1) ->select(Stats::COUNT_WEEK_AVERAGE->value) ->fetch_assoc()[Stats::COUNT_WEEK_AVERAGE->value] ?? 0; } public function __construct(public readonly string $id) { parent::__construct(CoffeeTable::TABLE, CoffeeTable::values(), [ CoffeeTable::ID->value => $this->id ]); } public function delete(): bool { return $this->db->delete([CoffeeTable::ID->value => $this->id]); } final public DateTimeImmutable $date_created { get => new DateTimeImmutable($this->get(CoffeeTable::DATE_CREATED->value)); set (DateTimeImmutable $date_created) => $this->set(CoffeeTable::DATE_CREATED->value, $date_created->format(parent::DATE_FORMAT)); } }