Passed
Push — master ( e0ed8e...0d3aa7 )
by Nils
11:00
created

ItemController::listAction()   B

Complexity

Conditions 6
Paths 20

Size

Total Lines 35
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 24
c 1
b 0
f 0
nc 20
nop 0
dl 0
loc 35
rs 8.9137
1
<?php
2
/**
3
 * Teampass - a collaborative passwords manager.
4
 * ---
5
 * This library is distributed in the hope that it will be useful,
6
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8
 * ---
9
 *
10
 * @project   Teampass API
11
 *
12
 * @file      ItemControler.php
13
 * ---
14
 *
15
 * @author    Nils Laumaillé ([email protected])
16
 *
17
 * @copyright 2009-2022 Teampass.net
18
 *
19
 * @license   https://spdx.org/licenses/GPL-3.0-only.html#licenseText GPL-3.0
20
 * ---
21
 *
22
 * @see       https://www.teampass.net
23
 */
24
class ItemController extends BaseController
25
{
26
    /**
27
     * "/user/list" Endpoint - Get list of users
28
     */
29
    public function listInFoldersAction()
30
    {
31
        $strErrorDesc = '';
32
        $requestMethod = $_SERVER["REQUEST_METHOD"];
33
34
        // get parameters
35
        $arrQueryStringParams = $this->getQueryStringParams();
36
        print_r($arrQueryStringParams);
37
38
        if (strtoupper($requestMethod) == 'GET') {
39
            try {
40
                $itemModel = new ItemModel();
41
 
42
                $intLimit = 0;
43
                if (isset($arrQueryStringParams['limit']) && $arrQueryStringParams['limit']) {
44
                    $intLimit = $arrQueryStringParams['limit'];
45
                }
46
 
47
                $arrItems = $itemModel->getItems($intLimit);
48
                $responseData = json_encode($arrItems);
49
            } catch (Error $e) {
50
                $strErrorDesc = $e->getMessage().'Something went wrong! Please contact support.';
51
                $strErrorHeader = 'HTTP/1.1 500 Internal Server Error';
52
            }
53
        } else {
54
            $strErrorDesc = 'Method not supported';
55
            $strErrorHeader = 'HTTP/1.1 422 Unprocessable Entity';
56
        }
57
 
58
        // send output
59
        if (!$strErrorDesc) {
60
            $this->sendOutput(
61
                $responseData,
62
                array('Content-Type: application/json', 'HTTP/1.1 200 OK')
63
            );
64
        } else {
65
            $this->sendOutput(json_encode(array('error' => $strErrorDesc)), 
66
                array('Content-Type: application/json', $strErrorHeader)
67
            );
68
        }
69
    }
70
}