aboutsummaryrefslogtreecommitdiffhomepage
path: root/Digitigrade/Model/NoteAttachment.php
blob: 1ca00649bbd660b0448dd5d05a8e3339c7ef790c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
namespace Digitigrade\Model;

use Digitigrade\Model;

class NoteAttachment extends Model {
    public ?int $noteId;
    public int $index;
    public string $type;
    public string $href;
    public ?string $description;

    public static function fromStorageObject(StorageObject $obj, int $index, ?string $description = null) {
        $a = new self();
        $a->index = $index;
        $a->type = $obj->mimetype;
        $a->href = $obj->getUrl();
        $a->description = $description;
        return $a;
    }

    public function setOwnerId(int $id) {
        $this->noteId = $id;
    }

    protected function getUpdateWhereClause($db): ?string {
        if (self::findWhere('note_id = ? AND index = ?', [$this->noteId, $this->index]) != null) {
            return "note_id = $this->noteId AND index = $this->index";
        }
        return null;
    }
}