Passed
Pull Request — master (#58)
by Stone
04:29 queued 02:04
created

Tag::update()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 11
nc 2
nop 0
dl 0
loc 20
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
namespace App\Controllers\Ajax;
4
5
use App\Models\TagModel;
6
use Core\AjaxController;
7
use Core\JsonException;
8
9
class Tag extends AjaxController
10
{
11
12
13
    /**
14
     * Update the tag via ajax
15
     * @throws \Core\JsonException
16
     */
17
    public function update()
18
    {
19
        //security checks
20
        $this->onlyAdmin();
21
        $this->onlyPost();
22
23
        //preparing our return results
24
        $result = array();
25
        $tagUpdateJson = ($this->request->getData('tag-update'));
26
        $tagUpdate = json_decode($tagUpdateJson);
27
28
        //Converting our array of objects to simple array
29
        $send = array();
30
        foreach ($tagUpdate as $item) {
31
            $send[$item->name] = $item->value;
32
        }
33
34
        $tagModel = new TagModel($this->container);
35
        $result['success'] = $tagModel->update($send["idtags"], $send["tag_name"]);
36
        echo json_encode($result);
37
    }
38
39
    /**
40
     * Delete a tag via Ajax
41
     * @throws \Core\JsonException
42
     */
43
    public function delete()
44
    {
45
        //security checks
46
        $this->onlyAdmin();
47
        $this->onlyPost();
48
49
        //preparing our return results
50
        $result = array();
51
        $DeleteJson = ($this->request->getData('tag-delete'));
52
        $Delete = json_decode($DeleteJson);
53
54
        //Converting our array of objects to simple array
55
        $send = array();
56
        foreach ($Delete as $item) {
57
            $send[$item->name] = $item->value;
58
        }
59
60
        $tagModel = new TagModel($this->container);
61
        $result['success'] = $tagModel->delete($send["idtags"]);
62
        echo json_encode($result);
63
    }
64
}