Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit b62a99c

Browse files
DIOHz0rajsb85
authored andcommitted
feat(item): added ItemHandler class
1 parent 794d594 commit b62a99c

File tree

1 file changed

+149
-0
lines changed

1 file changed

+149
-0
lines changed
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
<?php
2+
3+
namespace GlpiProject\API\Rest;
4+
5+
6+
class ItemHandler
7+
{
8+
/**
9+
* @var Client
10+
*/
11+
protected $client;
12+
13+
public function __construct(Client $client) {
14+
$this->client = $client;
15+
}
16+
17+
/**
18+
* Return the instance fields of itemtype identified by id.
19+
* @param $itemType
20+
* @param $id
21+
* @param array $queryString
22+
* @return array
23+
*/
24+
public function getAnItem($itemType, $id, array $queryString = []) {
25+
$response = $this->client->request('get', $itemType . '/' . $id, $queryString);
26+
return [
27+
'statusCode' => $response->getStatusCode(),
28+
'body' => $response->getBody()->getContents(),
29+
];
30+
}
31+
32+
/**
33+
* Return a collection of rows of the itemtype.
34+
* @param $itemType
35+
* @param array $queryString
36+
* @return array
37+
*/
38+
public function getAllItems($itemType, array $queryString = []) {
39+
$response = $this->client->request('get', $itemType . '/', $queryString);
40+
return [
41+
'statusCode' => $response->getStatusCode(),
42+
'body' => $response->getBody()->getContents(),
43+
];
44+
}
45+
46+
/**
47+
* Return a collection of rows of the itemtype.
48+
* @param $itemType
49+
* @param $id
50+
* @param $subItem
51+
* @param array $queryString
52+
* @return array
53+
*/
54+
public function getSubItems($itemType, $id, $subItem, array $queryString = []) {
55+
$response = $this->client->request('get', $itemType . '/' . $id . '/' . $subItem,
56+
$queryString);
57+
return [
58+
'statusCode' => $response->getStatusCode(),
59+
'body' => $response->getBody()->getContents(),
60+
];
61+
}
62+
63+
/**
64+
* Virtually call Get an item for each line in input. So, you can have a ticket, an user in the same query.
65+
* @param array $queryString
66+
* @return array
67+
*/
68+
public function getMultipleItems(array $queryString = []) {
69+
$response = $this->client->request('get', 'getMultipleItems', $queryString);
70+
return [
71+
'statusCode' => $response->getStatusCode(),
72+
'body' => $response->getBody()->getContents(),
73+
];
74+
}
75+
76+
/**
77+
* Virtually call Get an item for each line in input. So, you can have a ticket, an user in the same query.
78+
* @param $itemType
79+
* @param array $queryString
80+
* @return array
81+
*/
82+
public function listSearchOptions($itemType, array $queryString = []) {
83+
$response = $this->client->request('get', 'listSearchOptions/' . $itemType, $queryString);
84+
return [
85+
'statusCode' => $response->getStatusCode(),
86+
'body' => $response->getBody()->getContents(),
87+
];
88+
}
89+
90+
/**
91+
* Virtually call Get an item for each line in input. So, you can have a ticket, an user in the same query.
92+
* @param $itemType
93+
* @param array $queryString
94+
* @return array
95+
*/
96+
public function searchItems($itemType, array $queryString = []) {
97+
$response = $this->client->request('get', 'search/' . $itemType, $queryString);
98+
return [
99+
'statusCode' => $response->getStatusCode(),
100+
'body' => $response->getBody()->getContents(),
101+
];
102+
}
103+
104+
/**
105+
* Add an object (or multiple objects) into GLPI.
106+
*
107+
* Important: In case of 'multipart/data' content_type (aka file upload),
108+
* you should insert your parameters into a 'uploadManifest' parameter.
109+
* Theses serialized data should be a json string.
110+
*
111+
* @param $itemType
112+
* @param array $queryString
113+
* @return array
114+
*/
115+
public function addItem($itemType, array $queryString = []) {
116+
$queryString['input'] = $queryString;
117+
$response = $this->client->request('post', $itemType . '/', $queryString);
118+
return [
119+
'statusCode' => $response->getStatusCode(),
120+
'body' => $response->getBody()->getContents(),
121+
];
122+
}
123+
124+
/**
125+
* Update an object (or multiple objects) existing in GLPI.
126+
* @param $itemType
127+
* @param $id
128+
* @param array $queryString
129+
* @return array
130+
*/
131+
public function updateItem($itemType, $id, array $queryString = []) {
132+
$queryString['input'] = $queryString;
133+
$response = $this->client->request('put', $itemType . '/' . $id, $queryString);
134+
return [
135+
'statusCode' => $response->getStatusCode(),
136+
'body' => $response->getBody()->getContents(),
137+
];
138+
}
139+
140+
public function deleteItem($itemType, $id, array $queryString = []) {
141+
$queryString['input'] = $queryString;
142+
$response = $this->client->request('delete', $itemType . '/' . $id, $queryString);
143+
return [
144+
'statusCode' => $response->getStatusCode(),
145+
'body' => $response->getBody()->getContents(),
146+
];
147+
}
148+
149+
}

0 commit comments

Comments
 (0)