add a get for user in default model
This commit is contained in:
parent
35b74c9458
commit
25b461d611
|
@ -21,7 +21,30 @@ namespace models;
|
|||
* @return string
|
||||
*/
|
||||
protected function get_table_name() : string { return 'received'; }
|
||||
|
||||
|
||||
/**
|
||||
* Return an entry by his id for a user
|
||||
* @param int $id_user : user id
|
||||
* @param int $id : entry id
|
||||
* @return array
|
||||
*/
|
||||
public function get_for_user(int $id_user, int $id)
|
||||
{
|
||||
$query = '
|
||||
SELECT * FROM `' . $this->get_table_name() . '`
|
||||
WHERE destination IN (SELECT number FROM phone WHERE id_user = :id_user)
|
||||
';
|
||||
|
||||
$params = [
|
||||
'id_user' => $id_user,
|
||||
];
|
||||
|
||||
$receiveds = $this->_run_query($query, $params);
|
||||
return $receiveds[0] ?? [];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a list of received for a user
|
||||
* @param int $id_user : User id
|
||||
|
|
|
@ -23,6 +23,28 @@ namespace models;
|
|||
protected function get_table_name() : string { return 'sended'; }
|
||||
|
||||
|
||||
/**
|
||||
* Return an entry by his id for a user
|
||||
* @param int $id_user : user id
|
||||
* @param int $id : entry id
|
||||
* @return array
|
||||
*/
|
||||
public function get_for_user(int $id_user, int $id)
|
||||
{
|
||||
$query = '
|
||||
SELECT * FROM `' . $this->get_table_name() . '`
|
||||
WHERE origin IN (SELECT number FROM phone WHERE id_user = :id_user)
|
||||
';
|
||||
|
||||
$params = [
|
||||
'id_user' => $id_user,
|
||||
];
|
||||
|
||||
$receiveds = $this->_run_query($query, $params);
|
||||
return $receiveds[0] ?? [];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a list of sended for a user
|
||||
* @param int $id_user : User id
|
||||
|
|
|
@ -29,7 +29,19 @@ namespace models;
|
|||
* @param int $id : entry id
|
||||
* @return array
|
||||
*/
|
||||
public function get($id)
|
||||
public function get(int $id)
|
||||
{
|
||||
return $this->_select_one($this->get_table_name(), ['id' => $id]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return an entry by his id for a user
|
||||
* @param int $id_user : user id
|
||||
* @param int $id : entry id
|
||||
* @return array
|
||||
*/
|
||||
public function get_for_user(int $id_user, int $id)
|
||||
{
|
||||
return $this->_select_one($this->get_table_name(), ['id' => $id]);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue