1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of product_management |
4
|
|
|
* User: Sinan TURGUT <[email protected]> |
5
|
|
|
* Date: 24.06.2019 |
6
|
|
|
* php version 7.2 |
7
|
|
|
* |
8
|
|
|
* @category Assessment |
9
|
|
|
* @package ProductManagement |
10
|
|
|
* @author Sinan TURGUT <[email protected]> |
11
|
|
|
* @license See LICENSE file |
12
|
|
|
* @link https://dev.sinanturgut.com.tr |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace App\Controller; |
16
|
|
|
|
17
|
|
|
use App\Utility; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class Product |
21
|
|
|
* |
22
|
|
|
* @category Assessment |
23
|
|
|
* @package App\Controller |
24
|
|
|
* @author Sinan TURGUT <[email protected]> |
25
|
|
|
* @license See LICENSE file |
26
|
|
|
* @link https://dev.sinanturgut.com.tr |
27
|
|
|
*/ |
28
|
|
|
class Product |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* List products |
32
|
|
|
* |
33
|
|
|
* @return object |
34
|
|
|
*/ |
35
|
|
|
public function listProducts() |
36
|
|
|
{ |
37
|
|
|
$db = new \App\Model\Product(); |
38
|
|
|
$products = $db->query("SELECT * FROM products where is_active")->data(); |
39
|
|
|
return Utility\Response::write(true, $products); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Add new product |
44
|
|
|
* |
45
|
|
|
* @return string |
46
|
|
|
*/ |
47
|
|
|
public function addProduct() |
48
|
|
|
{ |
49
|
|
|
// Get user info from user management service |
50
|
|
|
$user = Utility\Request::getUser(); |
51
|
|
|
|
52
|
|
|
// Die if user is not admin |
53
|
|
|
if(!$user['user']['is_admin']) { |
54
|
|
|
return Utility\Response::write(true, ['error'=>'authentication error!']); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$params = json_decode(file_get_contents('php://input'),true); |
58
|
|
|
|
59
|
|
|
$db = new \App\Model\Product(); |
60
|
|
|
$product = $db->query( |
61
|
|
|
"INSERT INTO products VALUES (NULL, :productName, :category, :summary, :price, 1)", |
62
|
|
|
[ |
63
|
|
|
"productName" => $params['ProductName'], |
64
|
|
|
"category"=>$params['Category'], |
65
|
|
|
"summary"=>$params['Description'], |
66
|
|
|
"price"=>$params['Price'] |
67
|
|
|
] |
68
|
|
|
)->data(); |
69
|
|
|
return Utility\Response::write(true, $params); |
70
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.