|
28 | 28 | -------------------------------------------------------------------------- |
29 | 29 | */ |
30 | 30 |
|
| 31 | +use Glpi\Search\Provider\SQLProvider; |
31 | 32 | use GlpiPlugin\Connections\Connection; |
32 | 33 | use GlpiPlugin\Connections\Connection_Item; |
33 | 34 | use GlpiPlugin\Connections\ConnectionRate; |
@@ -326,56 +327,100 @@ function plugin_connections_getAddSearchOptions($itemtype) |
326 | 327 | * @param $linkfield |
327 | 328 | * @param $already_link_tables |
328 | 329 | * |
329 | | - * @return Left|string |
| 330 | + * @return array |
330 | 331 | */ |
331 | 332 | function plugin_connections_addLeftJoin($type, $ref_table, $new_table, $linkfield, &$already_link_tables) |
332 | 333 | { |
333 | 334 | switch ($new_table) { |
334 | 335 | case "glpi_plugin_connections_connections_items": |
335 | | - return " LEFT JOIN `$new_table` ON (`$ref_table`.`id` = `$new_table`.`plugin_connections_connections_id`) "; |
336 | | - break; |
337 | | - |
| 336 | + $out['LEFT JOIN'] = [ |
| 337 | + $new_table => [ |
| 338 | + 'ON' => [ |
| 339 | + $ref_table => 'id', |
| 340 | + $new_table => 'plugin_connections_connections_id' |
| 341 | + ], |
| 342 | + ], |
| 343 | + ]; |
| 344 | + return $out; |
338 | 345 | case "glpi_plugin_connections_connections": |
339 | | - $out = " LEFT JOIN `glpi_plugin_connections_connections_items` ON (`$ref_table`.`id` = `glpi_plugin_connections_connections_items`.`items_id` AND `glpi_plugin_connections_connections_items`.`itemtype` = '$type') "; |
340 | | - $out .= " LEFT JOIN `glpi_plugin_connections_connections` ON (`glpi_plugin_connections_connections`.`id` = `glpi_plugin_connections_connections_items`.`plugin_connections_connections_id`) "; |
| 346 | + $out['LEFT JOIN'] = [ |
| 347 | + 'glpi_plugin_connections_connections_items' => [ |
| 348 | + 'ON' => [ |
| 349 | + $ref_table => 'id', |
| 350 | + 'glpi_plugin_connections_connections_items' => 'items_id', [ |
| 351 | + 'AND' => [ |
| 352 | + 'glpi_plugin_connections_connections_items.itemtype' => $type, |
| 353 | + ], |
| 354 | + ], |
| 355 | + ], |
| 356 | + ], |
| 357 | + 'glpi_plugin_connections_connections' => [ |
| 358 | + 'ON' => [ |
| 359 | + 'glpi_plugin_connections_connections' => 'id', |
| 360 | + 'glpi_plugin_connections_connections_items' => 'plugin_connections_connections_id' |
| 361 | + ], |
| 362 | + ], |
| 363 | + ]; |
341 | 364 | return $out; |
342 | | - break; |
343 | | - |
344 | 365 | case "glpi_plugin_connections_connectiontypes": |
345 | | - $out = Search::addLeftJoin( |
| 366 | + $out = SQLProvider::getLeftJoinCriteria( |
346 | 367 | $type, |
347 | 368 | $ref_table, |
348 | 369 | $already_link_tables, |
349 | 370 | "glpi_plugin_connections_connections", |
350 | 371 | $linkfield |
351 | 372 | ); |
352 | | - $out .= " LEFT JOIN `glpi_plugin_connections_connectiontypes` ON (`glpi_plugin_connections_connectiontypes`.`id` = `glpi_plugin_connections_connections`.`plugin_connections_connectiontypes_id`) "; |
| 373 | + $left = [ |
| 374 | + 'glpi_plugin_connections_connectiontypes' => [ |
| 375 | + 'ON' => [ |
| 376 | + 'glpi_plugin_connections_connectiontypes' => 'id', |
| 377 | + 'glpi_plugin_connections_connections' => 'plugin_connections_connectiontypes_id' |
| 378 | + ], |
| 379 | + ], |
| 380 | + ]; |
| 381 | + $out['LEFT JOIN'] = array_merge($out, $left); |
353 | 382 | return $out; |
354 | 383 |
|
355 | 384 | case "glpi_plugin_connections_connectionrates": |
356 | | - $out = Search::addLeftJoin( |
| 385 | + $out = SQLProvider::getLeftJoinCriteria( |
357 | 386 | $type, |
358 | 387 | $ref_table, |
359 | 388 | $already_link_tables, |
360 | 389 | "glpi_plugin_connections_connections", |
361 | 390 | $linkfield |
362 | 391 | ); |
363 | | - $out .= " LEFT JOIN `glpi_plugin_connections_connectionrates` ON (`glpi_plugin_connections_connectionrates`.`id` = `glpi_plugin_connections_connections`.`plugin_connections_connectionrates_id`) "; |
| 392 | + $left = [ |
| 393 | + 'glpi_plugin_connections_connectionrates' => [ |
| 394 | + 'ON' => [ |
| 395 | + 'glpi_plugin_connections_connectionrates' => 'id', |
| 396 | + 'glpi_plugin_connections_connections' => 'plugin_connections_connectionrates_id' |
| 397 | + ], |
| 398 | + ], |
| 399 | + ]; |
| 400 | + $out['LEFT JOIN'] = array_merge($out, $left); |
364 | 401 | return $out; |
365 | 402 |
|
366 | 403 | case "glpi_plugin_connections_guaranteedconnectionrates": |
367 | | - $out = Search::addLeftJoin( |
| 404 | + $out = SQLProvider::getLeftJoinCriteria( |
368 | 405 | $type, |
369 | 406 | $ref_table, |
370 | 407 | $already_link_tables, |
371 | 408 | "glpi_plugin_connections_connections", |
372 | 409 | $linkfield |
373 | 410 | ); |
374 | | - $out .= " LEFT JOIN `glpi_plugin_connections_guaranteedconnectionrates` ON (`glpi_plugin_connections_guaranteedconnectionrates`.`id` = `glpi_plugin_connections_connections`.`plugin_connections_guaranteedconnectionrates_id`) "; |
| 411 | + $left = [ |
| 412 | + 'glpi_plugin_connections_guaranteedconnectionrates' => [ |
| 413 | + 'ON' => [ |
| 414 | + 'glpi_plugin_connections_guaranteedconnectionrates' => 'id', |
| 415 | + 'glpi_plugin_connections_connections' => 'plugin_connections_guaranteedconnectionrates_id' |
| 416 | + ], |
| 417 | + ], |
| 418 | + ]; |
| 419 | + $out['LEFT JOIN'] = array_merge($out, $left); |
375 | 420 | return $out; |
376 | 421 | } |
377 | 422 |
|
378 | | - return ""; |
| 423 | + return []; |
379 | 424 | } |
380 | 425 |
|
381 | 426 | /** |
|
0 commit comments