@@ -196,14 +196,8 @@ public function search(
196
196
$ limit = 100 ,
197
197
$ order = ''
198
198
) {
199
- $ msg = new Request ('execute ' );
200
-
201
- $ msg ->addParam ($ this ->stringValue ($ this ->database ));
202
- $ msg ->addParam ($ this ->intValue ($ this ->getUserId ()));
203
- $ msg ->addParam ($ this ->stringValue ($ this ->password ));
199
+ $ msg = $ this ->getBaseObjectRequest ($ modelName , 'search ' );
204
200
205
- $ msg ->addParam ($ this ->stringValue ($ modelName ));
206
- $ msg ->addParam ($ this ->stringValue ('search ' ));
207
201
$ msg ->addParam ($ this ->objectifyArray ($ criteria ));
208
202
209
203
$ msg ->addParam ($ this ->intValue ($ offset )); // offset
@@ -223,14 +217,8 @@ public function searchCount(
223
217
string $ modelName ,
224
218
array $ criteria = []
225
219
) {
226
- $ msg = new Request ('execute ' );
227
-
228
- $ msg ->addParam ($ this ->stringValue ($ this ->database ));
229
- $ msg ->addParam ($ this ->intValue ($ this ->getUserId ()));
230
- $ msg ->addParam ($ this ->stringValue ($ this ->password ));
220
+ $ msg = $ this ->getBaseObjectRequest ($ modelName , 'search_count ' );
231
221
232
- $ msg ->addParam ($ this ->stringValue ($ modelName ));
233
- $ msg ->addParam ($ this ->stringValue ('search_count ' ));
234
222
$ msg ->addParam ($ this ->objectifyArray ($ criteria ));
235
223
236
224
$ response = $ this ->getXmlRpcClient ('object ' )->send ($ msg );
@@ -249,17 +237,11 @@ public function searchRead(
249
237
$ limit = 100 ,
250
238
$ order = ''
251
239
) {
252
- $ msg = new Request ( ' execute ' );
240
+ $ msg = $ this -> getBaseObjectRequest ( $ modelName , ' search_read ' );
253
241
254
- $ msg ->addParam ($ this ->stringValue ($ this ->database ));
255
- $ msg ->addParam ($ this ->intValue ($ this ->getUserId ()));
256
- $ msg ->addParam ($ this ->stringValue ($ this ->password ));
257
-
258
- $ msg ->addParam ($ this ->stringValue ($ modelName ));
259
- $ msg ->addParam ($ this ->stringValue ('search_read ' ));
260
242
$ msg ->addParam ($ this ->objectifyArray ($ criteria ));
261
243
262
- // To be fixed when we have Odoo 8 available.
244
+ // To be fixed when we have Odoo 8 available to develop against .
263
245
264
246
//$msg->addParam($this->stringValue('id'));
265
247
@@ -280,14 +262,8 @@ public function read(
280
262
string $ modelName ,
281
263
array $ criteria = []
282
264
) {
283
- $ msg = new Request ('execute ' );
284
-
285
- $ msg ->addParam ($ this ->stringValue ($ this ->database ));
286
- $ msg ->addParam ($ this ->intValue ($ this ->getUserId ()));
287
- $ msg ->addParam ($ this ->stringValue ($ this ->password ));
265
+ $ msg = $ this ->getBaseObjectRequest ($ modelName , 'read ' );
288
266
289
- $ msg ->addParam ($ this ->stringValue ($ modelName ));
290
- $ msg ->addParam ($ this ->stringValue ('read ' ));
291
267
$ msg ->addParam ($ this ->objectifyArray ($ criteria ));
292
268
293
269
$ response = $ this ->getXmlRpcClient ('object ' )->send ($ msg );
@@ -296,9 +272,38 @@ public function read(
296
272
}
297
273
298
274
//
299
- // TODO: create write unlink
275
+ // TODO: actions to implement = create write unlink
300
276
//
301
277
278
+ /**
279
+ * Return a message with the base parameters for any object call.
280
+ * Identified the login credentials, model and action.
281
+ *
282
+ * @param string|null $modelName
283
+ * @param string|null $action will be used only the $modelName is provided
284
+ * @return Request
285
+ */
286
+ public function getBaseObjectRequest (
287
+ string $ modelName = null ,
288
+ string $ action = null
289
+ ) {
290
+ $ msg = new Request ('execute ' );
291
+
292
+ $ msg ->addParam ($ this ->stringValue ($ this ->database ));
293
+ $ msg ->addParam ($ this ->intValue ($ this ->getUserId ()));
294
+ $ msg ->addParam ($ this ->stringValue ($ this ->password ));
295
+
296
+ if ($ modelName !== null ) {
297
+ $ msg ->addParam ($ this ->stringValue ($ modelName ));
298
+
299
+ if ($ action !== null ) {
300
+ $ msg ->addParam ($ this ->stringValue ($ action ));
301
+ }
302
+ }
303
+
304
+ return $ msg ;
305
+ }
306
+
302
307
/**
303
308
* Walk through the criteria array and convert scalar values to
304
309
* XML-RPC objects, and nested arrays to array and struct objects.
@@ -337,7 +342,7 @@ public function objectifyArray($item)
337
342
}
338
343
339
344
// Map to an array or a struct, depending on whether a numeric
340
- // array or associative array.
345
+ // keyed array or an associative array is to be encoded .
341
346
342
347
if ($ item === [] || array_keys ($ item ) === range (0 , count ($ item ) - 1 )) {
343
348
return $ this ->arrayValue ($ item );
0 commit comments