Use correct phone for response to discussion

This commit is contained in:
osaajani 2020-01-11 17:27:07 +01:00
parent c4bc7d94c1
commit aee9fc847f
7 changed files with 104 additions and 6 deletions

View file

@ -388,4 +388,31 @@ namespace models;
return $this->_run_query($query, $params);
}
/**
* Find destination of last received message for an origin and user
* @param int $id_user : User id
* @param string $origin : Origin number
* @return array
*/
public function get_last_for_origin_and_user (int $id_user, string $origin)
{
$query = "
SELECT *
FROM received
WHERE origin = :origin
AND destination IN (SELECT number FROM phone WHERE id_user = :id_user)
ORDER BY at DESC
LIMIT 0,1
";
$params = [
'origin' => $origin,
'id_user' => $id_user,
];
$result = $this->_run_query($query, $params);
return ($result[0] ?? []);
}
}