Passed
Push — develop ( 558982...38f712 )
by Nikolay
06:07
created

ConferenceRoomsManagementProcessor::callBack()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 15
c 1
b 0
f 1
dl 0
loc 22
rs 9.7666
cc 3
nc 3
nop 1
1
<?php
2
/*
3
 * MikoPBX - free phone system for small business
4
 * Copyright © 2017-2023 Alexey Portnov and Nikolay Beketov
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License along with this program.
17
 * If not, see <https://www.gnu.org/licenses/>.
18
 */
19
20
namespace MikoPBX\PBXCoreREST\Lib;
21
22
use MikoPBX\PBXCoreREST\Lib\ConferenceRooms\DeleteRecord;
23
use Phalcon\Di\Injectable;
24
25
/**
26
 * Class ConferenceRoomsManagementProcessor
27
 *
28
 * @package MikoPBX\PBXCoreREST\Lib
29
 *
30
 */
31
class ConferenceRoomsManagementProcessor extends Injectable
32
{
33
    /**
34
     * Processes Conference Rooms management requests
35
     *
36
     * @param array $request
37
     *
38
     * @return PBXApiResult An object containing the result of the API call.
39
     */
40
    public static function callBack(array $request): PBXApiResult
41
    {
42
        $res = new PBXApiResult();
43
        $res->processor = __METHOD__;
44
45
        $action = $request['action'];
46
        $data = $request['data'];
47
        switch ($action) {
48
            case 'deleteRecord':
49
                if (!empty($data['id'])) {
50
                    $res = DeleteRecord::main($data['id']);
51
                } else {
52
                    $res->messages['error'][] = 'Empty ID in POST/GET data';
53
                }
54
                break;
55
            default:
56
                $res->messages['error'][] = "Unknown action - $action in " . __CLASS__;
57
        }
58
59
        $res->function = $action;
60
61
        return $res;
62
    }
63
64
65
}