raspisms/models/User.php

133 lines
3.7 KiB
PHP
Raw Normal View History

2019-10-29 14:57:13 +01:00
<?php
/*
2019-11-10 17:48:54 +01:00
* This file is part of RaspiSMS.
*
2019-11-10 17:48:54 +01:00
* (c) Pierre-Lin Bonnemaison <plebwebsas@gmail.com>
*
2019-11-10 17:48:54 +01:00
* This source file is subject to the GPL-3.0 license that is bundled
* with this source code in the file LICENSE.
*/
namespace models;
class User extends \descartes\Model
2019-10-29 14:57:13 +01:00
{
/**
* Retourne un user par son email.
*
2019-10-29 14:57:13 +01:00
* @param string $email : L'email du user
*
2019-10-29 14:57:13 +01:00
* @return mixed array | false : false si pas de user pour ce mail, sinon le user associé sous forme de tableau
*/
public function get_by_email($email)
2019-10-29 14:57:13 +01:00
{
return $this->_select_one('user', ['email' => $email]);
2019-10-29 14:57:13 +01:00
}
/**
* Return users by transfer status.
*
* @param bool $transfer : transfer status
*/
public function gets_by_transfer($transfer)
{
return $this->_select('transfer', ['transfer' => $transfer]);
}
/**
* Return list of user.
*
* @param int $limit : Number of user to return
2019-10-29 14:57:13 +01:00
* @param int $offset : Number of user to skip
*/
public function list($limit, $offset)
2019-10-29 14:57:13 +01:00
{
return $this->_select('user', [], null, false, $limit, $offset);
}
2019-10-29 14:57:13 +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
* @param mixed $id
*
2019-10-29 14:57:13 +01:00
* @return int : Le nombre de lignes supprimées
*/
public function remove($id)
2019-10-29 14:57:13 +01:00
{
return $this->_delete('user', ['id' => $id]);
2019-10-29 14:57:13 +01:00
}
/**
* Insert un user.
*
2019-10-29 14:57:13 +01:00
* @param array $user : La user à insérer avec les champs name, script, admin & admin
*
2019-10-29 14:57:13 +01:00
* @return mixed bool|int : false si echec, sinon l'id de la nouvelle lignée insérée
*/
public function insert($user)
2019-10-29 14:57:13 +01:00
{
$result = $this->_insert('user', $user);
2019-10-29 14:57:13 +01:00
if (!$result)
{
2019-10-29 14:57:13 +01:00
return false;
}
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
2019-10-29 14:57:13 +01:00
* @param array $user : Les données à mettre à jour pour la user
*
2019-10-29 14:57:13 +01:00
* @return int : le nombre de ligne modifiées
*/
public function update($id, $user)
2019-10-29 14:57:13 +01:00
{
return $this->_update('user', $user, ['id' => $id]);
2019-10-29 14:57:13 +01:00
}
2019-10-29 14:57:13 +01:00
/**
* Update a user password by his id.
*
* @param int $id : User id
2019-10-29 14:57:13 +01:00
* @param array $password : The new password of the user
*
2019-10-29 14:57:13 +01:00
* @return int : Number of modified lines
*/
public function update_password($id, $password)
2019-10-29 14:57:13 +01:00
{
return $this->_update('user', ['password' => $password], ['id' => $id]);
2019-10-29 14:57:13 +01:00
}
2019-10-29 14:57:13 +01:00
/**
* Update a user transfer property value by his id.
*
* @param int $id : User id
2019-10-29 14:57:13 +01:00
* @param array $transfer : The new transfer property value
*
2019-10-29 14:57:13 +01:00
* @return int : Number of modified lines
*/
public function update_transfer($id, $transfer)
2019-10-29 14:57:13 +01:00
{
return $this->_update('user', ['transfer' => $transfer], ['id' => $id]);
2019-10-29 14:57:13 +01:00
}
2019-10-29 14:57:13 +01:00
/**
* Update a user email by his id.
*
* @param int $id : User id
2019-10-29 14:57:13 +01:00
* @param array $email : The new email
*
2019-10-29 14:57:13 +01:00
* @return int : Number of modified lines
*/
public function update_email($id, $email)
2019-10-29 14:57:13 +01:00
{
return $this->_update('user', ['email' => $email], ['id' => $id]);
2019-10-29 14:57:13 +01:00
}
}