@@ -32,49 +32,7 @@ public function get($id, $sideload = false)
32
32
$ ticket = $ response ['ticket ' ];
33
33
34
34
if ($ sideload ) {
35
- // Sideload user information
36
- if (isset ($ response ['users ' ])) {
37
- // Generate the list of user IDs from the users provided
38
- $ users = array ();
39
- foreach ($ response ['users ' ] as $ user ) {
40
- $ users [$ user ['id ' ]] = $ user ;
41
- }
42
-
43
- // Use the list of generated users to attach additional details to the ticket
44
- if (isset ($ ticket ['requester_id ' ])) {
45
- if (isset ($ users [$ ticket ['requester_id ' ]])) {
46
- $ ticket ['requester ' ] = $ users [$ ticket ['requester_id ' ]];
47
- }
48
- }
49
-
50
- if (isset ($ ticket ['submitter_id ' ])) {
51
- if (isset ($ users [$ ticket ['submitter_id ' ]])) {
52
- $ ticket ['submitter ' ] = $ users [$ ticket ['submitter_id ' ]];
53
- }
54
- }
55
-
56
- if (isset ($ ticket ['assignee_id ' ])) {
57
- if (isset ($ users [$ ticket ['assignee_id ' ]])) {
58
- $ ticket ['assignee ' ] = $ users [$ ticket ['assignee_id ' ]];
59
- }
60
- }
61
- }
62
-
63
- // Sideload group information
64
- if (isset ($ response ['groups ' ])) {
65
- // Generate the list of group IDs from the users provided
66
- $ groups = array ();
67
- foreach ($ response ['groups ' ] as $ group ) {
68
- $ groups [$ group ['id ' ]] = $ group ;
69
- }
70
-
71
- // Use the list of generated groups to attach additional details to the ticket
72
- if (isset ($ ticket ['group_id ' ])) {
73
- if (isset ($ groups [$ ticket ['group_id ' ]])) {
74
- $ ticket ['group ' ] = $ groups [$ ticket ['group_id ' ]];
75
- }
76
- }
77
- }
35
+ $ this ->formatSideloaded ($ response , $ ticket );
78
36
}
79
37
80
38
return $ ticket ;
@@ -146,8 +104,19 @@ public function forRequester($customerEmail)
146
104
{
147
105
$ user = Mage::getModel ('zendesk/api_users ' )->find ($ customerEmail );
148
106
if (isset ($ user ['id ' ])) {
149
- $ response = $ this ->_call ('users/ ' . $ user ['id ' ] . '/requests.json ' , null , 'GET ' , null , false );
150
- return $ response ['requests ' ];
107
+ $ response = $ this ->_call (
108
+ 'users/ ' . $ user ['id ' ] . '/tickets/requested.json ' ,
109
+ array ('include ' => 'users,groups ' , 'sort_by ' => 'updated_at ' , 'sort_order ' => 'desc ' ),
110
+ 'GET ' ,
111
+ null ,
112
+ false
113
+ );
114
+
115
+ foreach ($ response ['tickets ' ] as &$ request ) {
116
+ $ request = $ this ->formatSideloaded ($ response , $ request );
117
+ }
118
+
119
+ return $ response ['tickets ' ];
151
120
} else {
152
121
return array ();
153
122
}
@@ -192,4 +161,52 @@ public function create($data)
192
161
return (isset ($ response ['ticket ' ]) ? $ response ['ticket ' ] : null );
193
162
}
194
163
164
+ private function formatSideloaded ($ response , $ ticket )
165
+ {
166
+ // Sideload user information
167
+ if (isset ($ response ['users ' ])) {
168
+ // Generate the list of user IDs from the users provided
169
+ $ users = array ();
170
+ foreach ($ response ['users ' ] as $ user ) {
171
+ $ users [$ user ['id ' ]] = $ user ;
172
+ }
173
+
174
+ // Use the list of generated users to attach additional details to the ticket
175
+ if (isset ($ ticket ['requester_id ' ])) {
176
+ if (isset ($ users [$ ticket ['requester_id ' ]])) {
177
+ $ ticket ['requester ' ] = $ users [$ ticket ['requester_id ' ]];
178
+ }
179
+ }
180
+
181
+ if (isset ($ ticket ['submitter_id ' ])) {
182
+ if (isset ($ users [$ ticket ['submitter_id ' ]])) {
183
+ $ ticket ['submitter ' ] = $ users [$ ticket ['submitter_id ' ]];
184
+ }
185
+ }
186
+
187
+ if (isset ($ ticket ['assignee_id ' ])) {
188
+ if (isset ($ users [$ ticket ['assignee_id ' ]])) {
189
+ $ ticket ['assignee ' ] = $ users [$ ticket ['assignee_id ' ]];
190
+ }
191
+ }
192
+ }
193
+
194
+ // Sideload group information
195
+ if (isset ($ response ['groups ' ])) {
196
+ // Generate the list of group IDs from the users provided
197
+ $ groups = array ();
198
+ foreach ($ response ['groups ' ] as $ group ) {
199
+ $ groups [$ group ['id ' ]] = $ group ;
200
+ }
201
+
202
+ // Use the list of generated groups to attach additional details to the ticket
203
+ if (isset ($ ticket ['group_id ' ])) {
204
+ if (isset ($ groups [$ ticket ['group_id ' ]])) {
205
+ $ ticket ['group ' ] = $ groups [$ ticket ['group_id ' ]];
206
+ }
207
+ }
208
+ }
209
+
210
+ return $ ticket ;
211
+ }
195
212
}
0 commit comments