mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-04-21 00:46:27 +02:00
to keep
This commit is contained in:
parent
65dacb5302
commit
4c27d8ccf2
13 changed files with 121 additions and 137 deletions
|
@ -17,57 +17,47 @@ namespace models;
|
|||
class Command extends \descartes\Model
|
||||
{
|
||||
/**
|
||||
* Get all commands.
|
||||
*
|
||||
* Return a command by his id
|
||||
* @param int $id : command id
|
||||
* @return array
|
||||
*/
|
||||
public function get_all()
|
||||
{
|
||||
return $this->_select('command');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne une entrée par son id.
|
||||
*
|
||||
* @param int $id : L'id de l'entrée
|
||||
*
|
||||
* @return array : L'entrée
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
$commands = $this->_select('command', ['id' => $id]);
|
||||
|
||||
return isset($commands[0]) ? $commands[0] : false;
|
||||
return $this->_select_one('command', ['id' => $id]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retourne une liste de commandes sous forme d'un tableau.
|
||||
*
|
||||
* @param int $limit : Nombre de résultat maximum à retourner
|
||||
* @param int $offset : Nombre de résultat à ingnorer
|
||||
* Return a list of commands for a user
|
||||
* @param int $id_user : user id
|
||||
* @param int $limit : Number of command to return
|
||||
* @param int $offset : Number of command to ignore
|
||||
* @return array
|
||||
*/
|
||||
public function list($limit, $offset)
|
||||
public function list_for_user (int $id_user, $limit, $offset)
|
||||
{
|
||||
return $this->_select('command', [], null, false, $limit, $offset);
|
||||
return $this->_select('command', ['id_user' => $id_user], null, false, $limit, $offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne une liste de commandes sous forme d'un tableau.
|
||||
*
|
||||
* Return a list of commands in a group of ids and for a user
|
||||
* @param int $id_user : user id
|
||||
* @param array $ids : un ou plusieurs id d'entrées à récupérer
|
||||
*
|
||||
* @return array : La liste des entrées
|
||||
*/
|
||||
public function gets($ids)
|
||||
public function gets_in_for_user($id_user, $ids)
|
||||
{
|
||||
$query = '
|
||||
SELECT * FROM command
|
||||
WHERE id ';
|
||||
WHERE id_user = :id_user
|
||||
AND id ';
|
||||
|
||||
//On génère la clause IN et les paramètres adaptés depuis le tableau des id
|
||||
$generated_in = $this->_generate_in_from_array($ids);
|
||||
$query .= $generated_in['QUERY'];
|
||||
$params = $generated_in['PARAMS'];
|
||||
$params['id_user'] = $id_user;
|
||||
|
||||
return $this->_run_query($query, $params);
|
||||
}
|
||||
|
|
|
@ -82,33 +82,35 @@ namespace models;
|
|||
}
|
||||
|
||||
/**
|
||||
* Retourne une liste de contactes sous forme d'un tableau.
|
||||
*
|
||||
* @param int $limit : Nombre de résultat maximum à retourner
|
||||
* @param int $offset : Nombre de résultat à ingnorer
|
||||
* List contacts for a user
|
||||
* @param int $id_user : user id
|
||||
* @param mixed(int|bool) $nb_entry : Number of entry to return
|
||||
* @param mixed(int|bool) $page : Pagination, will offset $nb_entry * $page results
|
||||
* @return array
|
||||
*/
|
||||
public function list($limit, $offset)
|
||||
public function list_for_user($id_user, $limit, $offset)
|
||||
{
|
||||
return $this->_select('contact', [], null, false, $limit, $offset);
|
||||
return $this->_select('contact', ['id_user' => $id_user], null, false, $limit, $offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne une liste de contactes sous forme d'un tableau.
|
||||
*
|
||||
* @param int $id_user : user id
|
||||
* @param array $ids : un ou plusieurs id d'entrées à récupérer
|
||||
*
|
||||
* @return array : La liste des entrées
|
||||
*/
|
||||
public function gets($ids)
|
||||
public function gets_for_user($id_user, $ids)
|
||||
{
|
||||
$query = '
|
||||
SELECT * FROM contact
|
||||
WHERE id ';
|
||||
WHERE id_user = :id_user
|
||||
AND ';
|
||||
|
||||
//On génère la clause IN et les paramètres adaptés depuis le tableau des id
|
||||
$generated_in = $this->_generate_in_from_array($ids);
|
||||
$query .= $generated_in['QUERY'];
|
||||
$params = $generated_in['PARAMS'];
|
||||
$params['id_user'] = $id_user;
|
||||
|
||||
return $this->_run_query($query, $params);
|
||||
}
|
||||
|
|
|
@ -16,18 +16,6 @@ namespace models;
|
|||
*/
|
||||
class Phone extends \descartes\Model
|
||||
{
|
||||
/**
|
||||
* Return list of phones.
|
||||
* @param int $id_user : User id
|
||||
* @param int $limit : Number of user to return
|
||||
* @param int $offset : Number of user to skip
|
||||
*/
|
||||
public function list($id_user, $limit, $offset)
|
||||
{
|
||||
return $this->_select('phone', ['id_user' => $id_user], null, false, $limit, $offset);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a phone by his id
|
||||
* @param int $id : Phone id
|
||||
|
@ -37,24 +25,27 @@ namespace models;
|
|||
{
|
||||
return $this->_select_one('phone', ['id' => $id]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Return a phone by his number
|
||||
* @param string $number : phone number
|
||||
* @return array
|
||||
* Return list of phones.
|
||||
* @param int $id_user : User id
|
||||
* @param int $limit : Number of user to return
|
||||
* @param int $offset : Number of user to skip
|
||||
*/
|
||||
public function get_by_number (string $number)
|
||||
public function list_for_user($id_user, $limit, $offset)
|
||||
{
|
||||
return $this->_select_one('phone', ['number' => $number]);
|
||||
return $this->_select('phone', ['id_user' => $id_user], null, false, $limit, $offset);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a phone by his number and user
|
||||
* @param string $number : phone number
|
||||
* @param int $id_user : user id
|
||||
* @return array
|
||||
*/
|
||||
public function get_by_number_and_user (string $number, int $id_user)
|
||||
public function get_by_number_for_user (string $number, int $id_user)
|
||||
{
|
||||
return $this->_select_one('phone', ['number' => $number, 'id_user' => $id_user]);
|
||||
}
|
||||
|
@ -71,23 +62,14 @@ namespace models;
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find all phones
|
||||
* @return array
|
||||
*/
|
||||
public function get_all ()
|
||||
{
|
||||
return $this->_select('phone');
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a phone
|
||||
* @param int $id : phone id
|
||||
* @return array
|
||||
*/
|
||||
public function delete ($id)
|
||||
public function delete_for_user ($id_user, $id)
|
||||
{
|
||||
return $this->_delete('phone', ['id' => $id]);
|
||||
return $this->_delete('phone', ['id_user' => $id_user, 'id' => $id]);
|
||||
}
|
||||
|
||||
|
||||
|
@ -109,13 +91,11 @@ namespace models;
|
|||
* Update a phone
|
||||
* @param int $id : Id of the phone
|
||||
* @param int $id_user : User to insert phone for
|
||||
* @param string $number : The number of the phone
|
||||
* @param string $adapter : The adapter to use the phone
|
||||
* @param string JSON $adapter_datas : A json string representing the datas of the adapter (for exemple credentials of an api)
|
||||
* @param array $phone : updated datas
|
||||
* @return mixed bool : false on error, true on success
|
||||
*/
|
||||
public function update ($id, $phone)
|
||||
public function update_for_user ($id_user, $id, $phone)
|
||||
{
|
||||
return (bool) $this->_update('phone', $phone, ['id' => $id]);
|
||||
return (bool) $this->_update('phone', $phone, ['id_user' => $id_user, 'id' => $id]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue