Conditions | 5 |
Paths | 5 |
Total Lines | 29 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
19 | public function isSlugUnique() |
||
20 | { |
||
21 | $this->onlyAdmin(); |
||
22 | if (!$this->container->getRequest()->isPost()) { |
||
23 | throw new \Core\JsonException('Call is not post'); |
||
24 | } |
||
25 | |||
26 | $postSlug = $this->request->getData("postSlug"); |
||
27 | $postId = $this->request->getData("postId"); |
||
28 | |||
29 | $data = false; |
||
30 | if (!$this->isAlphaNum($postSlug)) { |
||
31 | echo json_encode($data); |
||
32 | return true; |
||
33 | } |
||
34 | |||
35 | $postModel = new PostModel($this->container); |
||
36 | |||
37 | $data = $postModel->isPostSlugUnique($postSlug); |
||
38 | |||
39 | if ($data === false) //slug is not unique, but could be from the same post |
||
40 | { |
||
41 | $slugOfId = $postModel->getPostSlugFromId($postId); |
||
42 | if ($slugOfId === $postSlug) { |
||
43 | //it's the same post, return true |
||
44 | $data = true; |
||
45 | } |
||
46 | } |
||
47 | echo json_encode($data); |
||
48 | } |
||
50 | } |