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