FaZeBookSocialNetwork / www / src / FaZeBook / Data / Message.php
Message.php
Raw
<?php

namespace FaZeBook\Data;

use DateTimeImmutable;

class Message extends DataObject
{
    /* ----- Sender ----- */

    public function getSender(): User {
        return new User($this->dbo->fetchAs('user')->sender);
    }

    /* ----- Recipient ----- */

    public function getRecipient(): User {
        return new User($this->dbo->fetchAs('user')->recipient);
    }

    /* ----- Time ----- */

    public function getTime(): DateTimeImmutable {
        return new DateTimeImmutable('@' . $this->dbo->time);
    }

    /* ----- Content ----- */

    public function getContent(): string {
        return $this->dbo->content;
    }

    public function setContent(string $content) {
        $this->dbo->content = $content;
        $this->update();
    }

    /* ----- Read ----- */

    public function markRead() {
        $this->dbo->read = true;
        $this->update();
    }

    public function isRead(): bool {
        return $this->dbo->read;
    }
}