User
extends ModelClass
in package
uses
ModelTrait, CompanyRelationTrait, GravatarTrait
Usuario de FacturaScripts.
Tags
Table of Contents
Constants
- DEFAULT_LEVEL = 2
- UPDATE_ACTIVITY_PERIOD = 3600
Properties
- $admin : bool
- $codagente : string
- $codalmacen : string
- $codserie : string
- $creationdate : string
- $email : string
- $enabled : bool
- $homepage : string
- $idempresa : int
- $langcode : string
- $lastactivity : string
- $lastbrowser : string
- $lastip : string
- $level : int
- $logkey : string
- $newPassword : string
- $newPassword2 : string
- $nick : string
- $password : string
- $two_factor_enabled : bool
- $two_factor_secret_key : string
- $attributes : array<string|int, mixed>
- The model's attributes.
- $dataBase : DataBase
- It provides direct access to the database.
- $fields : array<string|int, mixed>
- List of fields in the table.
- $original : array<string|int, mixed>
- The model's original attributes.
Methods
- __construct() : mixed
- __get() : mixed
- __isset() : bool
- __set() : void
- __unset() : void
- addExtension() : void
- addRole() : bool
- all() : array<string|int, static>
- Devuelve todos los registros que cumplen las condiciones.
- can() : bool
- Devuelve true si el usuario tiene acceso a la página $pageName. Para comprobar si el usuario tiene permiso para modificar datos en la página, se debe pasar 'update' como parámetro $permission.
- changeId() : bool
- changePrimaryColumnValue() : bool
- clear() : void
- clearCache() : void
- count() : int
- create() : static|null
- delete() : bool
- deleteWhere() : bool
- disableTwoFactor() : void
- Desactiva la autenticación de dos factores para el usuario.
- enableTwoFactor() : string
- Activa la autenticación de dos factores para el usuario.
- exists() : bool
- find() : static|null
- findOrCreate() : static|null
- findWhere() : static|null
- findWhereEq() : static|null
- get() : mixed
- getApiFieldsToHide() : array<string|int, string>
- Devuelve los nombres de campos que no deben exponerse en la API.
- getCompany() : Empresa
- getDirty() : array<string|int, mixed>
- Devuelve un array asociativo con los campos modificados y sus valores actuales.
- getModelFields() : array<string|int, mixed>
- Returns the list of fields in the table.
- getOriginal() : mixed|null
- Devuelve el valor original de un campo, si no se indica campo devuelve todo el array original
- getRoles() : array<string|int, Role>
- Devuelve los roles asignados al usuario.
- getTwoFactorQR() : string
- getTwoFactorUrl() : string
- gravatar() : string
- Returns gravatar image url.
- hasChanged() : bool
- hasColumn() : bool
- hasExtension() : bool
- id() : mixed
- install() : string
- isDirty() : bool
- Comprueba si los campos del modelo han sido modificados.
- load() : bool
- Carga un modelo dada su primary key
- loadFromCode() : bool
- Carga un registro del modelo utilizando un código y opcionalmente condiciones adicionales.
- loadFromData() : void
- loadWhere() : bool
- Carga el primer registro que coincida con las condiciones especificadas.
- loadWhereEq() : bool
- modelClassName() : string
- Returns the name of the class of the model.
- newCode() : mixed
- newLogkey() : string
- pipe() : mixed
- pipeFalse() : bool
- primaryColumn() : string
- primaryColumnValue() : mixed
- primaryDescription() : mixed
- primaryDescriptionColumn() : string
- reload() : bool
- removeRole() : bool
- save() : bool
- Guarda el modelo en la base de datos después de ejecutar las comprobaciones `$this->test()`
- setPassword() : bool
- syncOriginal() : void
- table() : DbQuery
- tableName() : string
- test() : bool
- Realiza pruebas de validación sobre los campos del modelo antes de guardarlo.
- toArray() : array<string|int, mixed>
- Devuelve un array con los campos y valores del modelo.
- totalSum() : float
- update() : bool
- Actualiza el modelo con los valores proporcionados en el array
- updateActivity() : void
- updateOrCreate() : static|null
- url() : string
- Genera una URL para el modelo según el tipo especificado.
- verifyLogkey() : bool
- verifyPassword() : bool
- verifyTwoFactorCode() : bool
- Verifica un código TOTP proporcionado por el usuario.
- belongsTo() : object|null
- Define una relación uno a uno.
- db() : DataBase
- hasMany() : array<string|int, mixed>
- Define a one-to-many relationship.
- loadModelFields() : void
- onChange() : bool
- Este método se llama antes de guardar (insertar) un nuevo registro en la base de datos.
- onDelete() : void
- Este método se llama al eliminar un registro de la base de datos.
- onInsert() : void
- Este método se llama al insertar un nuevo registro en la base de datos (saveInsert).
- onUpdate() : void
- Este método se llama al insertar un nuevo registro en la base de datos (saveUpdate).
- saveInsert() : bool
- saveUpdate() : bool
- Este método se llama al actualizar un registro existente en la base de datos.
- testAgent() : bool
- testPassword() : bool
- testWarehouse() : bool
Constants
DEFAULT_LEVEL
public
mixed
DEFAULT_LEVEL
= 2
UPDATE_ACTIVITY_PERIOD
public
mixed
UPDATE_ACTIVITY_PERIOD
= 3600
Properties
$admin
public
bool
$admin
$codagente
public
string
$codagente
$codalmacen
public
string
$codalmacen
$codserie
public
string
$codserie
$creationdate
public
string
$creationdate
public
string
$email
$enabled
public
bool
$enabled
$homepage
public
string
$homepage
$idempresa
public
int
$idempresa
$langcode
public
string
$langcode
$lastactivity
public
string
$lastactivity
$lastbrowser
public
string
$lastbrowser
$lastip
public
string
$lastip
$level
public
int
$level
$logkey
public
string
$logkey
$newPassword
public
string
$newPassword
$newPassword2
public
string
$newPassword2
$nick
public
string
$nick
$password
public
string
$password
$two_factor_enabled
public
bool
$two_factor_enabled
$two_factor_secret_key
public
string
$two_factor_secret_key
$attributes
The model's attributes.
protected
array<string|int, mixed>
$attributes
= []
$dataBase
It provides direct access to the database.
protected
static DataBase
$dataBase
$fields
List of fields in the table.
protected
static array<string|int, mixed>
$fields
= []
$original
The model's original attributes.
protected
array<string|int, mixed>
$original
= []
Methods
__construct()
public
__construct([array<string|int, mixed> $data = [] ]) : mixed
Parameters
- $data : array<string|int, mixed> = []
__get()
public
__get(string $key) : mixed
Parameters
- $key : string
__isset()
public
__isset(string $key) : bool
Parameters
- $key : string
Return values
bool__set()
public
__set(string $key, mixed $value) : void
Parameters
- $key : string
- $value : mixed
__unset()
public
__unset(string $key) : void
Parameters
- $key : string
addExtension()
public
abstract static addExtension(mixed $extension[, int $priority = 100 ]) : void
Parameters
- $extension : mixed
- $priority : int = 100
addRole()
public
addRole(string|null $code) : bool
Parameters
- $code : string|null
Return values
boolall()
Devuelve todos los registros que cumplen las condiciones.
public
static all([array<string|int, mixed> $where = [] ][, array<string|int, mixed> $order = [] ][, int $offset = 0 ][, int $limit = 0 ]) : array<string|int, static>
Parameters
- $where : array<string|int, mixed> = []
- $order : array<string|int, mixed> = []
- $offset : int = 0
- $limit : int = 0
Return values
array<string|int, static>can()
Devuelve true si el usuario tiene acceso a la página $pageName. Para comprobar si el usuario tiene permiso para modificar datos en la página, se debe pasar 'update' como parámetro $permission.
public
can(string $pageName[, string $permission = 'access' ]) : bool
Parameters
- $pageName : string
- $permission : string = 'access'
Return values
boolchangeId()
public
changeId(mixed $new_id) : bool
Parameters
- $new_id : mixed
Return values
boolchangePrimaryColumnValue()
public
changePrimaryColumnValue(mixed $new_id) : bool
replace with changeId()
Parameters
- $new_id : mixed
Return values
boolclear()
public
clear() : void
clearCache()
public
clearCache() : void
count()
public
static count([array<string|int, mixed> $where = [] ]) : int
Parameters
- $where : array<string|int, mixed> = []
Return values
intcreate()
public
static create(array<string|int, mixed> $data) : static|null
Parameters
- $data : array<string|int, mixed>
Return values
static|nulldelete()
public
delete() : bool
Return values
booldeleteWhere()
public
static deleteWhere(array<string|int, mixed> $where) : bool
Parameters
- $where : array<string|int, mixed>
Return values
booldisableTwoFactor()
Desactiva la autenticación de dos factores para el usuario.
public
disableTwoFactor() : void
enableTwoFactor()
Activa la autenticación de dos factores para el usuario.
public
enableTwoFactor([string $key = '' ]) : string
Parameters
- $key : string = ''
Return values
string —La clave secreta generada para configurar la aplicación TOTP.
exists()
public
exists() : bool
Return values
boolfind()
public
static find(mixed $code) : static|null
Parameters
- $code : mixed
Return values
static|nullfindOrCreate()
public
static findOrCreate(array<string|int, mixed> $where[, array<string|int, mixed> $data = [] ]) : static|null
Parameters
- $where : array<string|int, mixed>
- $data : array<string|int, mixed> = []
Return values
static|nullfindWhere()
public
static findWhere(array<string|int, mixed> $where[, array<string|int, mixed> $order = [] ]) : static|null
Parameters
- $where : array<string|int, mixed>
- $order : array<string|int, mixed> = []
Return values
static|nullfindWhereEq()
public
static findWhereEq(string $field, mixed $value) : static|null
Parameters
- $field : string
- $value : mixed
Return values
static|nullget()
public
get(mixed $code) : mixed
Use find() instead
Parameters
- $code : mixed
getApiFieldsToHide()
Devuelve los nombres de campos que no deben exponerse en la API.
public
getApiFieldsToHide() : array<string|int, string>
Return values
array<string|int, string>getCompany()
public
getCompany() : Empresa
Return values
EmpresagetDirty()
Devuelve un array asociativo con los campos modificados y sus valores actuales.
public
getDirty() : array<string|int, mixed>
Return values
array<string|int, mixed>getModelFields()
Returns the list of fields in the table.
public
getModelFields() : array<string|int, mixed>
Return values
array<string|int, mixed>getOriginal()
Devuelve el valor original de un campo, si no se indica campo devuelve todo el array original
public
getOriginal([string|null $key = null ]) : mixed|null
Parameters
- $key : string|null = null
Return values
mixed|null —Devuelve el valor original del campo o null si no existe
getRoles()
Devuelve los roles asignados al usuario.
public
getRoles() : array<string|int, Role>
Return values
array<string|int, Role>getTwoFactorQR()
public
getTwoFactorQR() : string
Return values
stringgetTwoFactorUrl()
public
getTwoFactorUrl() : string
Return values
stringgravatar()
Returns gravatar image url.
public
gravatar([int $size = 80 ]) : string
Parameters
- $size : int = 80
Return values
stringhasChanged()
public
hasChanged(string $field) : bool
replace with isDirty()
Parameters
- $field : string
Return values
boolhasColumn()
public
hasColumn(string $columnName) : bool
Parameters
- $columnName : string
Return values
boolhasExtension()
public
abstract hasExtension(mixed $extension) : bool
Parameters
- $extension : mixed
Return values
boolid()
public
id() : mixed
install()
public
install() : string
Return values
stringisDirty()
Comprueba si los campos del modelo han sido modificados.
public
isDirty([string|null $key = null ]) : bool
Devuelve true si hay cambios, false en caso contrario.
Si introduces un parámetro key, comprueba solo ese campo
Parameters
- $key : string|null = null
Return values
bool —true si ha sido modificado, false en caso contrario
load()
Carga un modelo dada su primary key
public
load(mixed $code) : bool
Parameters
- $code : mixed
-
Código o identificador del registro a cargar
Return values
bool —Devuelve true si se encontró y cargó un registro exitosamente.
loadFromCode()
Carga un registro del modelo utilizando un código y opcionalmente condiciones adicionales.
public
loadFromCode(mixed $code[, array<string|int, mixed> $where = [] ][, array<string|int, mixed> $order = [] ]) : bool
Usar load() cuando solo se necesita cargar por código, o loadWhere() cuando se requieren condiciones WHERE u ordenamiento adicionales.
IMPORTANTE: Este método está deprecado. Se recomienda usar las alternativas siguientes:
- Si solo se proporciona $code: usar directamente load($code)
- Si se proporciona $code junto con $where o $order: usar loadWhere() con las condiciones apropiadas
Este método actúa como wrapper que redirige a load() cuando solo se proporciona el código, o a loadWhere() cuando se incluyen condiciones WHERE u ordenamiento adicionales.
Parameters
- $code : mixed
-
Código o identificador del registro a cargar. Se usa únicamente cuando no se proporcionan condiciones WHERE adicionales.
- $where : array<string|int, mixed> = []
-
Array de instancias de Where o DatabaseWhere que definen condiciones de filtrado adicionales. Si se proporciona, el método delega a loadWhere(). Por defecto es un array vacío.
- $order : array<string|int, mixed> = []
-
Array asociativo que define el ordenamiento de los resultados. Las claves son nombres de columnas y los valores la dirección del ordenamiento. Por defecto es un array vacío.
Return values
bool —Retorna true si se encontró y cargó un registro exitosamente. Retorna false si no se encontró ningún registro.
loadFromData()
public
loadFromData([array<string|int, mixed> $data = [] ][, array<string|int, mixed> $exclude = [] ][, bool $sync = true ]) : void
Parameters
- $data : array<string|int, mixed> = []
- $exclude : array<string|int, mixed> = []
- $sync : bool = true
loadWhere()
Carga el primer registro que coincida con las condiciones especificadas.
public
loadWhere(array<string|int, mixed> $where[, array<string|int, mixed> $order = [] ]) : bool
Este método consulta la tabla asociada al modelo aplicando las condiciones WHERE proporcionadas y el ordenamiento especificado. Si encuentra un registro, carga sus datos en la instancia actual del modelo. Si no encuentra ningún registro, limpia la instancia y retorna false.
Parameters
- $where : array<string|int, mixed>
-
Array de instancias de Where o DatabaseWhere que definen las condiciones de filtrado para la consulta. Cada elemento representa una condición que debe cumplir el registro a cargar.
- $order : array<string|int, mixed> = []
-
Array asociativo que define el ordenamiento de los resultados. Las claves son nombres de columnas y los valores indican la dirección del ordenamiento (ej: ['id' => 'DESC', 'nombre' => 'ASC']). Por defecto es un array vacío (sin ordenamiento específico).
Return values
bool —Retorna true si se encontró y cargó un registro exitosamente. Retorna false si no se encontró ningún registro que cumpla las condiciones.
loadWhereEq()
public
loadWhereEq(string $field, mixed $value) : bool
Parameters
- $field : string
- $value : mixed
Return values
boolmodelClassName()
Returns the name of the class of the model.
public
modelClassName() : string
Return values
stringnewCode()
public
newCode([string $field = '' ][, array<string|int, mixed> $where = [] ]) : mixed
Parameters
- $field : string = ''
- $where : array<string|int, mixed> = []
newLogkey()
public
newLogkey(string $ipAddress[, string $browser = '' ]) : string
Parameters
- $ipAddress : string
- $browser : string = ''
Return values
stringpipe()
public
abstract pipe(mixed $name, mixed ...$arguments) : mixed
Parameters
- $name : mixed
- $arguments : mixed
pipeFalse()
public
abstract pipeFalse(mixed $name, mixed ...$arguments) : bool
Parameters
- $name : mixed
- $arguments : mixed
Return values
boolprimaryColumn()
public
static primaryColumn() : string
Return values
stringprimaryColumnValue()
public
primaryColumnValue() : mixed
Use id() instead
Attributes
- #[Deprecated]
- $reason: 'Use id() instead'
- $replacement: '%class%->id()'
primaryDescription()
public
primaryDescription() : mixed
primaryDescriptionColumn()
public
primaryDescriptionColumn() : string
Return values
stringreload()
public
reload() : bool
Return values
boolremoveRole()
public
removeRole(string|null $code) : bool
Parameters
- $code : string|null
Return values
boolsave()
Guarda el modelo en la base de datos después de ejecutar las comprobaciones `$this->test()`
public
save() : bool
Return values
bool —Devuelve true si se ha guardado correctamente, false en caso contrario
setPassword()
public
setPassword(mixed $value) : bool
Parameters
- $value : mixed
Return values
boolsyncOriginal()
public
syncOriginal() : void
table()
public
static table() : DbQuery
Return values
DbQuerytableName()
public
static tableName() : string
Return values
stringtest()
Realiza pruebas de validación sobre los campos del modelo antes de guardarlo.
public
test() : bool
Return values
bool —Devuelve true si todas las pruebas pasan, false en caso contrario
toArray()
Devuelve un array con los campos y valores del modelo.
public
toArray([bool $dynamic_attributes = false ]) : array<string|int, mixed>
Parameters
- $dynamic_attributes : bool = false
-
Si es true, añade también los atributos dinámicos al array resultante
Return values
array<string|int, mixed> —Array asociativo con los campos y valores del modelo
totalSum()
public
static totalSum(string $field[, array<string|int, mixed> $where = [] ]) : float
Parameters
- $field : string
- $where : array<string|int, mixed> = []
Return values
floatupdate()
Actualiza el modelo con los valores proporcionados en el array
public
update(array<string|int, mixed> $values) : bool
Parameters
- $values : array<string|int, mixed>
-
Array asociativo con los campos y valores a actualizar
Return values
bool —Devuelve true si la actualización se ha realizado correctamente, false en caso
updateActivity()
public
updateActivity(string $ipAddress[, string $browser = '' ]) : void
Parameters
- $ipAddress : string
- $browser : string = ''
updateOrCreate()
public
static updateOrCreate(array<string|int, mixed> $where, array<string|int, mixed> $data) : static|null
Parameters
- $where : array<string|int, mixed>
- $data : array<string|int, mixed>
Return values
static|nullurl()
Genera una URL para el modelo según el tipo especificado.
public
url([string $type = 'auto' ][, string $list = 'List' ]) : string
Parameters
- $type : string = 'auto'
-
Tipo de URL a generar. Puede ser 'auto', 'edit', 'list' o 'new'.
- $list : string = 'List'
-
Nombre de la lista a utilizar en la URL cuando el tipo es 'list' o 'auto'.
Return values
string —URL generada para el modelo
verifyLogkey()
public
verifyLogkey(string $value) : bool
Parameters
- $value : string
Return values
boolverifyPassword()
public
verifyPassword(string $value) : bool
Parameters
- $value : string
Return values
boolverifyTwoFactorCode()
Verifica un código TOTP proporcionado por el usuario.
public
verifyTwoFactorCode(string $code) : bool
Parameters
- $code : string
-
El código TOTP a verificar.
Return values
bool —Verdadero si el código es válido.
belongsTo()
Define una relación uno a uno.
protected
belongsTo(string $modelName, string $foreignKey) : object|null
Parameters
- $modelName : string
- $foreignKey : string
Return values
object|nulldb()
protected
abstract static db() : DataBase
Return values
DataBasehasMany()
Define a one-to-many relationship.
protected
hasMany(string $modelName, string $foreignKey[, array<string|int, mixed> $where = [] ][, array<string|int, mixed> $order = [] ]) : array<string|int, mixed>
Parameters
- $modelName : string
- $foreignKey : string
- $where : array<string|int, mixed> = []
- $order : array<string|int, mixed> = []
Return values
array<string|int, mixed>loadModelFields()
protected
loadModelFields() : void
onChange()
Este método se llama antes de guardar (insertar) un nuevo registro en la base de datos.
protected
onChange(string $field) : bool
Parameters
- $field : string
Return values
boolonDelete()
Este método se llama al eliminar un registro de la base de datos.
protected
onDelete() : void
onInsert()
Este método se llama al insertar un nuevo registro en la base de datos (saveInsert).
protected
onInsert() : void
onUpdate()
Este método se llama al insertar un nuevo registro en la base de datos (saveUpdate).
protected
onUpdate() : void
saveInsert()
protected
saveInsert() : bool
Return values
boolsaveUpdate()
Este método se llama al actualizar un registro existente en la base de datos.
protected
saveUpdate() : bool
Return values
bool —Devuelve true si la actualización se realizó correctamente, false en caso contrario
testAgent()
protected
testAgent() : bool
Return values
booltestPassword()
protected
testPassword() : bool
Return values
booltestWarehouse()
protected
testWarehouse() : bool