|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace KW\Inlagg; |
|
4
|
|
|
|
|
5
|
|
|
use Anax\Commons\ContainerInjectableInterface; |
|
6
|
|
|
use Anax\Commons\ContainerInjectableTrait; |
|
7
|
|
|
|
|
8
|
|
|
class InlaggController implements ContainerInjectableInterface |
|
9
|
|
|
{ |
|
10
|
|
|
use ContainerInjectableTrait; |
|
11
|
|
|
|
|
12
|
|
|
private $textFilter; |
|
13
|
|
|
private $slugify; |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
public function __construct() |
|
17
|
|
|
{ |
|
18
|
|
|
$this->textFilter = new TextFilter(); |
|
19
|
|
|
$this->slugify = new Slugify(); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
// denna funktion skall förhoppningsvis returnera en fråga + ev kommentarer, därefter svar i sorterad ordning + ev kommentarer till dem |
|
24
|
|
|
public function enskiltinlaggActionGet($slug) |
|
25
|
|
|
{ |
|
26
|
|
|
$sortsv = $this->di->get("request")->getGet("sortsv"); |
|
27
|
|
|
$sortko = $this->di->get("request")->getGet("sortko"); |
|
28
|
|
|
|
|
29
|
|
|
$sorteraren = new Sorteraren($this->di); |
|
30
|
|
|
$hamtaren = new Hamtaren($this->di); |
|
31
|
|
|
|
|
32
|
|
|
$res = $sorteraren->sorteraFragorOchSvar($slug, $sortsv, $sortko); |
|
33
|
|
|
$taggar = $hamtaren->hamtataggar($res[0]->id); |
|
34
|
|
|
|
|
35
|
|
|
$page = $this->di->get("page"); |
|
36
|
|
|
$page->add("anax/v2/inlagg/enskiltinlagg", [ |
|
37
|
|
|
"res" => $res, |
|
38
|
|
|
"taggar"=> $taggar |
|
39
|
|
|
]); |
|
40
|
|
|
return $page->render([ |
|
41
|
|
|
"title"=>"Frågor" |
|
42
|
|
|
]); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function postakommentarActionPost() |
|
46
|
|
|
{ |
|
47
|
|
|
$rankning = new Rankning($this->di); |
|
48
|
|
|
$posta = new Posta($this->di); |
|
49
|
|
|
$data = $this->di->get("request")->getPost("data"); |
|
50
|
|
|
$userid = $this->di->get("request")->getPost("userid"); |
|
51
|
|
|
$tillhor = $this->di->get("request")->getPost("tillhor"); |
|
52
|
|
|
$type = $this->di->get("request")->getPost("type"); |
|
53
|
|
|
$retursida = $this->di->get("request")->getPost("retursida"); |
|
54
|
|
|
|
|
55
|
|
|
$posta->postaNyKommentar($data, $userid, $tillhor, $type); |
|
56
|
|
|
$rankning->uppdatera($userid, "kommentar", 1); |
|
57
|
|
|
|
|
58
|
|
|
return $this->di->get("response")->redirect($retursida)->send(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function postasvarActionPost() |
|
62
|
|
|
{ |
|
63
|
|
|
$rankning = new Rankning($this->di); |
|
64
|
|
|
$posta = new Posta($this->di); |
|
65
|
|
|
$data = $this->di->get("request")->getPost("data"); |
|
66
|
|
|
$userid = $this->di->get("request")->getPost("userid"); |
|
67
|
|
|
$tillhor = $this->di->get("request")->getPost("tillhor"); |
|
68
|
|
|
$type = $this->di->get("request")->getPost("type"); |
|
69
|
|
|
$retursida = $this->di->get("request")->getPost("retursida"); |
|
70
|
|
|
|
|
71
|
|
|
$posta->postaSvar($data, $userid, $tillhor, $type); |
|
72
|
|
|
$rankning->uppdatera($userid, "svar", 1); |
|
73
|
|
|
return $this->di->get("response")->redirect($retursida)->send(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function rankaUppInlaggActionPost($id) |
|
77
|
|
|
{ |
|
78
|
|
|
$rankning = new Rankning($this->di); |
|
79
|
|
|
$retursida = $this->di->get("request")->getPost("retursida"); |
|
80
|
|
|
|
|
81
|
|
|
$rankning->upp($id); |
|
82
|
|
|
$inlagg = $rankning->vemsInlagg($id); |
|
83
|
|
|
$rankning->uppdatera($inlagg->userid, "r" .$inlagg->type, 1); |
|
84
|
|
|
return $this->di->get("response")->redirect($retursida)->send(); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function rankaNerInlaggActionPost($id) |
|
88
|
|
|
{ |
|
89
|
|
|
$rankning = new Rankning($this->di); |
|
90
|
|
|
$retursida = $this->di->get("request")->getPost("retursida"); |
|
91
|
|
|
|
|
92
|
|
|
$rankning->ner($id); |
|
93
|
|
|
$inlagg = $rankning->vemsInlagg($id); |
|
94
|
|
|
$rankning->uppdatera($inlagg->userid, "r" . $inlagg->type, -1); |
|
95
|
|
|
|
|
96
|
|
|
return $this->di->get("response")->redirect($retursida)->send(); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function accepteraActionPost($id) |
|
100
|
|
|
{ |
|
101
|
|
|
$rankning = new Rankning($this->di); |
|
102
|
|
|
$retursida = $this->di->get("request")->getPost("retursida"); |
|
103
|
|
|
|
|
104
|
|
|
$rankning->acceptera($id); |
|
105
|
|
|
|
|
106
|
|
|
return $this->di->get("response")->redirect($retursida)->send(); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function postafragaActionPost() |
|
110
|
|
|
{ |
|
111
|
|
|
$hamtaren = new Hamtaren($this->di); |
|
112
|
|
|
$posta = new Posta($this->di); |
|
113
|
|
|
$rankning = new Rankning($this->di); |
|
114
|
|
|
|
|
115
|
|
|
$retursida = $this->di->get("request")->getPost("retursida"); |
|
116
|
|
|
$valdataggar = $this->di->get("request")->getPost("tag"); |
|
117
|
|
|
$nyataggar = $this->di->get("request")->getPost("nyataggar"); |
|
118
|
|
|
$title = $this->di->get("request")->getPost("title"); |
|
119
|
|
|
$data = $this->di->get("request")->getPost("data"); |
|
120
|
|
|
$taggar = []; |
|
121
|
|
|
|
|
122
|
|
|
$userid = $this->di->session->get("anvandarid"); |
|
|
|
|
|
|
123
|
|
|
$nastaTaggId = intval($hamtaren->nastaAutoInc("taggar")->auto_increment); |
|
124
|
|
|
$nastaInlaggId = intval($hamtaren->nastaAutoInc("inlagg")->auto_increment); |
|
125
|
|
|
$sluggarna = $hamtaren->befintligaSluggar(); |
|
126
|
|
|
|
|
127
|
|
|
$rankning->uppdatera($userid, "fraga", 1); |
|
128
|
|
|
|
|
129
|
|
|
if ($valdataggar!=null) { |
|
130
|
|
|
foreach ($valdataggar as $value) { |
|
131
|
|
|
array_push($taggar, $value); |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
if ($nyataggar!=null) { |
|
136
|
|
|
$nyataggar = explode(",", $nyataggar); |
|
137
|
|
|
$posta->nyaTaggar($nyataggar); |
|
138
|
|
|
$i = 0; |
|
139
|
|
|
foreach ($nyataggar as $value) { |
|
140
|
|
|
array_push($taggar, $i + intval($nastaTaggId)); |
|
141
|
|
|
$i++; |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
$slug = $this->slugify->slugify($title); |
|
145
|
|
|
|
|
146
|
|
|
while (in_array($slug, $sluggarna)) { |
|
147
|
|
|
$slug = $slug . "-i"; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
$posta->postaFraga($title, $data, $slug, $userid); |
|
151
|
|
|
$posta->kopplaFragaTaggar($nastaInlaggId, $taggar); |
|
152
|
|
|
return $this->di->get("response")->redirect($retursida)->send(); |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
|