You are not logged in.
Bonjour, je cherche un moyen de transformer ma requête:
$request = $DB->request(
'SELECT u.firstname, u.realname, e.name entities
from glpi_users u, glpi_entities e
where e.id = u.entities_id and (u.phone = \'' . $num . '\'
OR u.phone2 = \'' . $num . '\' OR u.mobile = \'' . $num . '\'
OR u.phone = \'' . $num2 . '\' OR u.phone2 = \'' . $num2 . '\'
OR u.mobile = \'' . $num2 . '\'OR u.phone = \'' . $num3 . '\'
OR u.phone2 = \'' . $num3 . '\' OR u.mobile = \'' . $num3 . '\'
OR u.phone = \'' . $num4 . '\' OR u.phone2 = \'' . $num4 . '\'
OR u.mobile = \'' . $num4 . '\')'
);
en arraylist mais je n'arrive pas a transformer mes "or" car j'utilise plusieurs fois par exemple le "phone".
J'ai cherché a trouver une solution avec la documentation mais je n'ai trouver aucune réponce : glpi-developer-documentation.readthedocs.io/en/master/devapi/database/dbiterator.html
Voila actuèlement a quoi ressemble la request transformer :
$requestQuery = [
'SELECT' => [
'glpi_users' => ['firstname', 'realname'],
'glpi_entities' => 'name AS entities'
],
'FROM' => ['glpi_users', 'glpi_entities'],
'FKEY' => [
'glpi_entities' => 'id',
'glpi_users' => 'entities_id'
],
'WHERE' => [
'OR' => [
'phone' => [$num,$num2,$num3,$num4],
'phone2' => [$num,$num2,$num3,$num4],
'mobile' => [$num,$num2,$num3,$num4]
]
]
];
$request = $DB->request($requestQuery);
Dans cette request, j'ai essayer d'utiliser les "IN" comme dans cette request SQL ci-dessous mais cela n'a pas marche alors que le request SQL fonctionne :
SELECT u.firstname, u.realname, e.name entities, phone, phone2, mobile
from glpi_users u, glpi_entities e
where e.id = u.entities_id and (
phone in ("","", "","")
OR phone2 in ("","","","")
OR mobile in ("","","","")
)
Si quelqu'un pourrais l'aider je le remercierais.
Bien a vous et bonne journée
Last edited by Juju38 (2024-04-09 10:27:30)
Offline
La solution est trouvé il faut mettre le "FKEY" dans le "WHERE" :
$requestQuery = [
'FIELDS' => [
'glpi_users' => ['firstname', 'realname'],
'glpi_entities' => 'name AS entities'
],
'FROM' => ['glpi_users', 'glpi_entities'],
'WHERE' => [
'FKEY' => [
'glpi_entities' => 'id',
'glpi_users' => 'entities_id'
],
'OR' => [
'phone' => [$num,$num2,$num3,$num4],
'phone2' => [$num,$num2,$num3,$num4],
'mobile' => [$num,$num2,$num3,$num4]
]
]
];
Offline