aboutsummaryrefslogtreecommitdiff
path: root/app/class/Session.php
blob: 64b6b2643bc17abe3a6563599f187f60f797cb34 (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
<?php

namespace Wcms;

use RuntimeException;

class Session extends Item
{
    public $visitor = false;
    public $user = '';
    public $showleftpanel = true;
    public $showrightpanel = false;
    public $homedisplay = 'list';
    public $mediadisplay = 'list';

    public function __construct($datas = [])
    {
        $this->hydrate($datas);
    }

    public function writesession()
    {
        $_SESSION['user' . Config::basepath()] = $this->dry();
    }

    /**
     * Ajust a session variable
     * @param string $var
     * @param mixed $value
     * @return bool if var exist
     */
    public function addtosession(string $var, $value): bool
    {
        $method = 'set' . $var;
        if (method_exists($this, $method)) {
            $this->$method($value);
            $_SESSION['user' . Config::basepath()][$var] = $this->$var;
            return true;
        } else {
            return false;
        }
    }

    // _________________________ S E T ________________________

    public function setvisitor($visitor)
    {
        $this->visitor = boolval($visitor);
    }

    public function setuser($id)
    {
        if (is_string($id)) {
            $this->user = strip_tags($id);
        }
    }

    public function setshowleftpanel($showleftpanel)
    {
        $this->showleftpanel = boolval($showleftpanel);
    }

    public function setshowrightpanel($showrightpanel)
    {
        $this->showrightpanel = boolval($showrightpanel);
    }

    public function sethomedisplay($homedisplay)
    {
        if (in_array($homedisplay, ['list', 'map'])) {
            $this->homedisplay = $homedisplay;
        }
    }

    public function setmediadisplay($mediadisplay)
    {
        if (in_array($mediadisplay, ['list', 'gallery'])) {
            $this->mediadisplay = $mediadisplay;
        }
    }
}