1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Controllers\Ajax; |
4
|
|
|
|
5
|
|
|
use App\Models\CategoryModel; |
6
|
|
|
use Core\AjaxController; |
7
|
|
|
|
8
|
|
|
class Category extends AjaxController |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
public function new() |
13
|
|
|
{ |
14
|
|
|
//security checks |
15
|
|
|
$this->onlyAdmin(); |
16
|
|
|
if (!$this->container->getRequest()->isPost()) { |
17
|
|
|
throw new JsonException('Call is not post'); |
|
|
|
|
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
//prepating our return results |
21
|
|
|
$result = array(); |
22
|
|
|
$categoryUpdateJson = ($this->request->getData('category-new')); |
23
|
|
|
$categoryUpdate = json_decode($categoryUpdateJson); |
24
|
|
|
|
25
|
|
|
//Converting our array of objects to simple array |
26
|
|
|
$send = array(); |
27
|
|
|
foreach ($categoryUpdate as $item) { |
28
|
|
|
$send[$item->name] = $item->value; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
$categoryModel = new CategoryModel($this->container); |
32
|
|
|
$result['success'] = $categoryModel->new($send["category_name"], $send["categories_slug"]); |
33
|
|
|
echo json_encode($result); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Update the category via ajax |
38
|
|
|
* @throws \Core\JsonException |
39
|
|
|
*/ |
40
|
|
|
public function update() |
41
|
|
|
{ |
42
|
|
|
//security checks |
43
|
|
|
$this->onlyAdmin(); |
44
|
|
|
if (!$this->container->getRequest()->isPost()) { |
45
|
|
|
throw new JsonException('Call is not post'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
//prepating our return results |
49
|
|
|
$result = array(); |
50
|
|
|
$categoryUpdateJson = ($this->request->getData('category-update')); |
51
|
|
|
$categoryUpdate = json_decode($categoryUpdateJson); |
52
|
|
|
|
53
|
|
|
//Converting our array of objects to simple array |
54
|
|
|
$send = array(); |
55
|
|
|
foreach ($categoryUpdate as $item) { |
56
|
|
|
$send[$item->name] = $item->value; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$categoryModel = new CategoryModel($this->container); |
60
|
|
|
$result['success'] = $categoryModel->update($send["idcategories"], $send["category_name"], |
61
|
|
|
$send["categories_slug"]); |
62
|
|
|
echo json_encode($result); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @throws \Core\JsonException |
67
|
|
|
*/ |
68
|
|
|
public function delete() |
69
|
|
|
{ |
70
|
|
|
//security checks |
71
|
|
|
$this->onlyAdmin(); |
72
|
|
|
if (!$this->container->getRequest()->isPost()) { |
73
|
|
|
throw new JsonException('Call is not post'); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
//prepating our return results |
77
|
|
|
$result = array(); |
78
|
|
|
$categoryDeleteJson = ($this->request->getData('category-delete')); |
79
|
|
|
$categoryDelete = json_decode($categoryDeleteJson); |
80
|
|
|
|
81
|
|
|
//Converting our array of objects to simple array |
82
|
|
|
$send = array(); |
83
|
|
|
foreach ($categoryDelete as $item) { |
84
|
|
|
$send[$item->name] = $item->value; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$categoryModel = new CategoryModel($this->container); |
88
|
|
|
$result['success'] = $categoryModel->delete($send["idcategories"]); |
89
|
|
|
echo json_encode($result); |
90
|
|
|
} |
91
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths