aboutsummaryrefslogtreecommitdiff
path: root/app/class/Bookmark.php
blob: 8b4d2f7db64502a50353b48c20c3e4fce93652aa (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php

namespace Wcms;

use DateTime;
use DateTimeImmutable;
use DateTimeZone;
use Exception;
use RuntimeException;

class Bookmark extends Item
{
    /** @var string $id Bookmark ID */
    protected $id;
    /** @var string $query */
    protected $query = '';
    /** @var string $route Can be `page|media` */
    protected $route;
    /** @var array $params*/
    protected $params = [];
    /** @var string $icon associated emoji */
    protected $icon = '⭐';

    /**
     * @throws RuntimeException
     */
    public function __construct(array $datas = [])
    {
        $this->hydrateexception($datas);
    }

    public function init(string $id, string $route, string $query, array $params = [], string $icon = '⭐')
    {
        $this->setid($id);
        $this->setroute($route);
        $this->setquery($query);
        $this->setparams($params);
        $this->seticon($icon);
    }



    
    // _____________________________ G E T __________________________________


    public function id()
    {
        return $this->id;
    }

    public function query()
    {
        return $this->query;
    }

    public function route()
    {
        return $this->route;
    }

    public function params()
    {
        return $this->params;
    }

    public function icon()
    {
        return $this->icon;
    }

    // _____________________________ S E T __________________________________

    public function setid($id): bool
    {
        if (is_string($id)) {
            $id = idclean($id);
            if (!empty($id)) {
                $this->id = $id;
                return true;
            }
        }
        return false;
    }
 
    public function setquery($query)
    {
        if (is_string($query)) {
            $this->query = substr($query, 0, Model::MAX_QUERY_LENGH);
        }
    }

    public function setroute($route)
    {
        if ($route === 'home' || $route === 'media') {
            $this->route = $route;
            return true;
        } else {
            return false;
        }
    }

    public function setparams($params)
    {
        if (is_array($params)) {
            $this->params = $params;
        }
    }

    public function seticon($icon)
    {
        if (is_string($icon)) {
            $this->icon = substr(strip_tags($icon), 0, 16);
        }
    }
}