aboutsummaryrefslogtreecommitdiff
path: root/models/archivelist.php
blob: 779365e226aff647e88646afcbec59a6472c0add (plain) (blame)
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
33
34
35
36
37
38
39
40
41
42
43
44
<?php
namespace Database;
use PDO;

class ArchiveList extends Table {
    public $LID;
    public $AuthorUID;
    public $Name;
    public $Description;

    static function create(int $AuthorUID, string $Name, string $Description) : int {
        return Table::_create(
            'ArchiveLists',
            '(AuthorUID, Name, Description)',
            "(\"$AuthorUID\", \"$Name\", \"$Description\")"
        );
    }

    static function fromDB(int $LID) : ArchiveList {
        return Table::_fromDB(
            "SELECT * FROM ArchiveLists WHERE LID = \"$LID\"",
            'Database\ArchiveList'
        );
    }

    function addItem(int $WID) {
        Table::_create(
            'ArchiveListsWebpages',
            '(WID, LID, Position)',
            "(\"$WID\", \"$this->LID\", \"0\")"
        );
    }

    function allItems() : array {
        return Table::_get_all(
            'Webpages',
            'Database\Webpage',
            "INNER JOIN ArchiveListsWebpages ON Webpages.WID = ArchiveListsWebpages.WID
             WHERE ArchiveListsWebpages.LID = $this->LID
             ORDER BY ArchiveListsWebpages.Position ASC",
            'Webpages.*'
        );
    }
}