aboutsummaryrefslogtreecommitdiff
path: root/w/class/controllerart.php
blob: 4abc572b55bbba33fec5d69214fdfb955da7eb8f (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php

class Controllerart extends Controllerdb
{
    /** @var Art2 */
    protected $art;
    protected $artmanager;
    protected $renderengine;

    public function __construct($id)
    {
        parent::__construct();


        $this->art = new Art2(['id' => $id]);
        $this->artmanager = new Modelart();
        $this->renderengine = new Modelrender();

    }

    public function importart()
    {
        $art = $this->artmanager->get($this->art);
        if ($art !== false) {
            $this->art = $art;
            //$this->art->autotaglistupdate($this->artmanager->taglist($this->artmanager->getlister(['id', 'title', 'description', 'tag']), $this->art->autotaglist()));
            return true;
        } else {
            return false;
        }
    }

    public function read()
    {
        $now = new DateTimeImmutable(null, timezone_open("Europe/Paris"));


        $artexist = $this->importart();
        $canread = $this->user->level() >= $this->art->secure();
        $cancreate = $this->user->cancreate();
        $alerts = ['alertnotexist' => 'This page does not exist yet', 'alertprivate' => 'You cannot see this page'];
        $body = '';
        $head = '';


        if ($artexist) {

            if ($this->art->daterender() < $this->art->datemodif()) {
                $body = $this->renderengine->renderbody($this->art);
                $this->art->setrender($body);
                $this->art->setdaterender($now);
                $this->artmanager->update($this->art);
            } else {
                $body = $this->art->render();
            }

            $head = $this->renderengine->renderhead($this->art);

            $this->art->addaffcount();
            $this->artmanager->update($this->art);

        }


        $data = array_merge($alerts, ['art' => $this->art, 'artexist' => $artexist, 'canread' => $canread, 'cancreate' => $cancreate, 'readernav' => true, 'body' => $body, 'head' => $head]);


        $this->showtemplate('read', $data);



    }

    public function edit()
    {
        if ($this->importart() && $this->user->canedit()) {
            $this->showtemplate('edit', ['art' => $this->art, 'artexist' => true]);
        } else {
            $this->redirect('?id=' . $this->art->id());
        }

    }

    public function log()
    {
        $this->importart();
        var_dump($this->art);
    }

    public function add()
    {
        $this->art->reset();
        $this->artmanager->add($this->art);
        $this->redirect('?id=' . $this->art->id() . '&aff=edit');
    }

    public function delete()
    {
        if ($this->user->canedit() && $this->importart()) {

            if (isset($_POST['deleteconfirm']) && $_POST['deleteconfirm'] == true) {
                $this->artmanager->delete($this->art);
                $this->redirect('?id=' . $this->art->id());
            } else {
                $this->showtemplate('delete', ['art' => $this->art, 'artexist' => true]);
            }
        } else {
            $this->redirect('?id=' . $this->art->id());
        }
    }

    public function update()
    {


        if ($this->importart() && $this->user->canedit()) {
            $this->art->hydrate($_POST);
            $this->art->updateedited();
            $this->artmanager->update($this->art);

        }

        $this->redirect('?id=' . $this->art->id() . '&aff=edit');



    }
}




?>