aboutsummaryrefslogtreecommitdiff
path: root/models/webpage.php
blob: 35bb3ceb52ce86c26c7152c5f254c1f5a5d3cdf7 (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
<?php
namespace Database;
use PDO;

class Webpage extends Table {
    public $WID;
    public $Path;
    public $URL;
    public $Date;
    public $Visits;
    public $RequesterUID;

    static function create(string $Path, string $URL, int $RequesterUID) : int {
        return Table::_create(
            'Webpages',
            '(Path, URL, Date, Visits, RequesterUID)',
            "(\"$Path\", \"$URL\", NOW(), 0, \"$RequesterUID\")"
        );
    }

    static function fromDB(string $URL) : Webpage {
        return Table::_fromDB(
            "SELECT * FROM Webpages WHERE URL = \"$URL\"",
            "Database\Webpage"
        );
    }

    static function mostVisited(int $count) : array {
        return Table::_get_all(
            'Webpages',
            'Database\Webpage',
            "GROUP BY URL ORDER BY Visits DESC, Date DESC LIMIT $count"
        );
    }
}