mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-06-06 14:46:27 +02:00
Update all models to use StandardModel basis
This commit is contained in:
parent
0e22f3d02c
commit
155a048834
17 changed files with 580 additions and 1478 deletions
|
@ -11,91 +11,23 @@
|
|||
|
||||
namespace models;
|
||||
|
||||
/**
|
||||
* Allow phone database management
|
||||
*/
|
||||
class Phone extends \descartes\Model
|
||||
class Phone extends StandardModel
|
||||
{
|
||||
/**
|
||||
* Return a phone by his id
|
||||
* @param int $id : Phone id
|
||||
* @return array
|
||||
* Return table name
|
||||
* @return string
|
||||
*/
|
||||
public function get (int $id)
|
||||
{
|
||||
return $this->_select_one('phone', ['id' => $id]);
|
||||
}
|
||||
protected function get_table_name() : string { return 'phone'; }
|
||||
|
||||
|
||||
/**
|
||||
* 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_for_user($id_user, $limit, $offset)
|
||||
{
|
||||
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
|
||||
* @param string $number : phone number
|
||||
* @return array
|
||||
*/
|
||||
public function get_by_number_for_user (string $number, int $id_user)
|
||||
public function get_by_number_for_user (int $id_user, string $number)
|
||||
{
|
||||
return $this->_select_one('phone', ['number' => $number, 'id_user' => $id_user]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find phones of a user
|
||||
* @param string $id_user : user's id
|
||||
* @return array
|
||||
*/
|
||||
public function gets_for_user (int $id_user)
|
||||
{
|
||||
return $this->_select('phone', ['id_user' => $id_user]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a phone
|
||||
* @param int $id : phone id
|
||||
* @return array
|
||||
*/
|
||||
public function delete_for_user ($id_user, $id)
|
||||
{
|
||||
return $this->_delete('phone', ['id_user' => $id_user, 'id' => $id]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a 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)
|
||||
* @return mixed bool : false on error, true on success
|
||||
*/
|
||||
public function insert($phone)
|
||||
{
|
||||
return (bool) $this->_insert('phone', $phone);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update a phone
|
||||
* @param int $id : Id of the phone
|
||||
* @param int $id_user : User to insert phone for
|
||||
* @param array $phone : updated datas
|
||||
* @return mixed bool : false on error, true on success
|
||||
*/
|
||||
public function update_for_user ($id_user, $id, $phone)
|
||||
{
|
||||
return (bool) $this->_update('phone', $phone, ['id_user' => $id_user, 'id' => $id]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue