2019-10-29 14:57:13 +01:00
|
|
|
<?php
|
2019-10-29 18:33:49 +01:00
|
|
|
namespace models;
|
|
|
|
|
|
|
|
class User extends \descartes\Model
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Retourne un user par son email
|
|
|
|
* @param string $email : L'email du user
|
|
|
|
* @return mixed array | false : false si pas de user pour ce mail, sinon le user associé sous forme de tableau
|
|
|
|
*/
|
2019-10-29 18:33:49 +01:00
|
|
|
public function get_by_email($email)
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2019-10-29 18:33:49 +01:00
|
|
|
return $this->_select_one('user', ['email' => $email]);
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
2019-10-29 18:33:49 +01:00
|
|
|
/**
|
2019-10-29 14:57:13 +01:00
|
|
|
* Return list of user
|
|
|
|
* @param int $limit : Number of user to return
|
|
|
|
* @param int $offset : Number of user to skip
|
2019-10-29 18:33:49 +01:00
|
|
|
*/
|
|
|
|
public function list($limit, $offset)
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2019-10-29 18:33:49 +01:00
|
|
|
return $this->_select('user', [], '', false, $limit, $offset);
|
|
|
|
}
|
2019-10-29 14:57:13 +01:00
|
|
|
|
|
|
|
/**
|
2019-10-29 18:33:49 +01:00
|
|
|
* Retourne une liste de useres sous forme d'un tableau
|
2019-10-29 14:57:13 +01:00
|
|
|
* @param array $ids : un ou plusieurs id d'entrées à supprimer
|
|
|
|
* @return int : Le nombre de lignes supprimées
|
2019-10-29 18:33:49 +01:00
|
|
|
*/
|
|
|
|
public function remove($id)
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2019-10-29 18:33:49 +01:00
|
|
|
return $this->_delete('user', ['id' => $id]);
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Insert un user
|
|
|
|
* @param array $user : La user à insérer avec les champs name, script, admin & admin
|
|
|
|
* @return mixed bool|int : false si echec, sinon l'id de la nouvelle lignée insérée
|
|
|
|
*/
|
2019-10-29 18:33:49 +01:00
|
|
|
public function insert($user)
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2019-10-29 18:33:49 +01:00
|
|
|
$result = $this->_insert('user', $user);
|
2019-10-29 14:57:13 +01:00
|
|
|
|
2019-10-29 18:33:49 +01:00
|
|
|
if (!$result) {
|
2019-10-29 14:57:13 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-10-29 18:33:49 +01:00
|
|
|
return $this->_last_id();
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Met à jour un user par son id
|
|
|
|
* @param int $id : L'id de la user à modifier
|
|
|
|
* @param array $user : Les données à mettre à jour pour la user
|
|
|
|
* @return int : le nombre de ligne modifiées
|
|
|
|
*/
|
2019-10-29 18:33:49 +01:00
|
|
|
public function update($id, $user)
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2019-10-29 18:33:49 +01:00
|
|
|
return $this->_update('user', $user, ['id' => $id]);
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update a user password by his id
|
|
|
|
* @param int $id : User id
|
|
|
|
* @param array $password : The new password of the user
|
|
|
|
* @return int : Number of modified lines
|
|
|
|
*/
|
2019-10-29 18:33:49 +01:00
|
|
|
public function update_password($id, $password)
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2019-10-29 18:33:49 +01:00
|
|
|
return $this->_update('user', ['password' => $password], ['id' => $id]);
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update a user transfer property value by his id
|
|
|
|
* @param int $id : User id
|
|
|
|
* @param array $transfer : The new transfer property value
|
|
|
|
* @return int : Number of modified lines
|
|
|
|
*/
|
2019-10-29 18:33:49 +01:00
|
|
|
public function update_transfer($id, $transfer)
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2019-10-29 18:33:49 +01:00
|
|
|
return $this->_update('user', ['transfer' => $transfer], ['id' => $id]);
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update a user email by his id
|
|
|
|
* @param int $id : User id
|
|
|
|
* @param array $email : The new email
|
|
|
|
* @return int : Number of modified lines
|
|
|
|
*/
|
2019-10-29 18:33:49 +01:00
|
|
|
public function update_email($id, $email)
|
2019-10-29 14:57:13 +01:00
|
|
|
{
|
2019-10-29 18:33:49 +01:00
|
|
|
return $this->_update('user', ['email' => $email], ['id' => $id]);
|
2019-10-29 14:57:13 +01:00
|
|
|
}
|
|
|
|
}
|