1
|
|
|
<?php |
2
|
|
|
// Copyright 1999-2016. Parallels IP Holdings GmbH. |
3
|
|
|
|
4
|
|
|
namespace PleskX\Api\Operator; |
5
|
|
|
use PleskX\Api\Struct\Customer as Struct; |
6
|
|
|
|
7
|
|
|
class Customer extends \PleskX\Api\Operator |
8
|
|
|
{ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @param array $properties |
12
|
|
|
* @return Struct\Info |
13
|
|
|
*/ |
14
|
|
|
public function create($properties) |
15
|
|
|
{ |
16
|
|
|
$packet = $this->_client->getPacket(); |
17
|
|
|
$info = $packet->addChild('customer')->addChild('add')->addChild('gen_info'); |
18
|
|
|
|
19
|
|
|
foreach ($properties as $name => $value) { |
20
|
|
|
$info->addChild($name, $value); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
$response = $this->_client->request($packet); |
24
|
|
|
return new Struct\Info($response); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param string $field |
29
|
|
|
* @param integer|string $value |
30
|
|
|
* @return bool |
31
|
|
|
*/ |
32
|
|
|
public function delete($field, $value) |
33
|
|
|
{ |
34
|
|
|
$packet = $this->_client->getPacket(); |
35
|
|
|
$packet->addChild('customer')->addChild('del')->addChild('filter')->addChild($field, $value); |
36
|
|
|
$response = $this->_client->request($packet); |
37
|
|
|
return 'ok' === (string)$response->status; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string $field |
42
|
|
|
* @param integer|string $value |
43
|
|
|
* @return Struct\GeneralInfo |
44
|
|
|
*/ |
45
|
|
|
public function get($field, $value) |
46
|
|
|
{ |
47
|
|
|
return $this->_get($field, $value); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return Struct\GeneralInfo[] |
52
|
|
|
*/ |
53
|
|
|
public function getAll() |
54
|
|
|
{ |
55
|
|
|
return $this->_get(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param string|null $field |
60
|
|
|
* @param integer|string|null $value |
61
|
|
|
* @return Struct\GeneralInfo|Struct\GeneralInfo[] |
62
|
|
|
*/ |
63
|
|
|
private function _get($field = null, $value = null) |
64
|
|
|
{ |
65
|
|
|
$packet = $this->_client->getPacket(); |
66
|
|
|
$getTag = $packet->addChild('customer')->addChild('get'); |
67
|
|
|
|
68
|
|
|
$filterTag = $getTag->addChild('filter'); |
69
|
|
|
if ($field) { |
|
|
|
|
70
|
|
|
$filterTag->addChild($field, $value); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$getTag->addChild('dataset')->addChild('gen_info'); |
74
|
|
|
|
75
|
|
|
$response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL); |
76
|
|
|
|
77
|
|
|
$customers = []; |
78
|
|
|
foreach ($response->xpath('//result') as $xmlResult) { |
79
|
|
|
$customers[] = new Struct\GeneralInfo($xmlResult->data->gen_info); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
return $field ? reset($customers) : $customers; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
} |
86
|
|
|
|