1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Controllers\Ajax; |
4
|
|
|
|
5
|
|
|
use App\Models\PostModel; |
6
|
|
|
use Core\AjaxController; |
7
|
|
|
use Core\Container; |
8
|
|
|
|
9
|
|
|
class postModification extends AjaxController |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
private $postModule; |
14
|
|
|
|
15
|
|
|
public function __construct(Container $container) |
16
|
|
|
{ |
17
|
|
|
parent::__construct($container); |
18
|
|
|
$this->postModule = new PostModel($this->container); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Ajax call to update the published state of a post |
23
|
|
|
* @throws \Core\JsonException |
24
|
|
|
*/ |
25
|
|
|
public function modifyPublished() |
26
|
|
|
{ |
27
|
|
|
$this->onlyAdmin(); |
28
|
|
|
if (!$this->container->getRequest()->isPost()) { |
29
|
|
|
throw new \Core\JsonException('Call is not post'); |
30
|
|
|
} |
31
|
|
|
$state = (bool)($this->request->getData("state") === 'true'); |
32
|
|
|
$postId = (int)$this->request->getData("postId"); |
33
|
|
|
|
34
|
|
|
$result = array(); |
35
|
|
|
$result["success"] = $this->postModule->setPublished(!$state, $postId); |
36
|
|
|
$result["state"] = !$state; |
37
|
|
|
$result["postId"] = $postId; |
38
|
|
|
echo json_encode($result); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Ajax call to update the on front page state of a post |
43
|
|
|
* @throws \Core\JsonException |
44
|
|
|
*/ |
45
|
|
|
public function modifyOnFrontPage() |
46
|
|
|
{ |
47
|
|
|
$this->onlyAdmin(); |
48
|
|
|
if (!$this->container->getRequest()->isPost()) { |
49
|
|
|
throw new \Core\JsonException('Call is not post'); |
50
|
|
|
} |
51
|
|
|
$state = ($this->request->getData("state") === 'true'); |
52
|
|
|
$postId = (int)$this->request->getData("postId"); |
53
|
|
|
|
54
|
|
|
$result = array(); |
55
|
|
|
$result["success"] = $this->postModule->setOnFrontPage(!$state, $postId); |
56
|
|
|
$result["state"] = !$state; |
57
|
|
|
$result["postId"] = $postId; |
58
|
|
|
echo json_encode($result); |
59
|
|
|
} |
60
|
|
|
} |