@@ -19,14 +19,14 @@ discard block |
||
19 | 19 | |
20 | 20 | final class Functions extends \Twig_Extension { |
21 | 21 | |
22 | - /** |
|
23 | - * Redirecciona a una URL |
|
24 | - * |
|
25 | - * @param string $url: Sitio a donde redireccionará, si no se pasa, por defecto |
|
26 | - * se redirecciona a la URL principal del sitio |
|
27 | - * |
|
28 | - * @return void |
|
29 | - */ |
|
22 | + /** |
|
23 | + * Redirecciona a una URL |
|
24 | + * |
|
25 | + * @param string $url: Sitio a donde redireccionará, si no se pasa, por defecto |
|
26 | + * se redirecciona a la URL principal del sitio |
|
27 | + * |
|
28 | + * @return void |
|
29 | + */ |
|
30 | 30 | final public function redir($url = null) { |
31 | 31 | global $config; |
32 | 32 | |
@@ -41,13 +41,13 @@ discard block |
||
41 | 41 | //------------------------------------------------ |
42 | 42 | |
43 | 43 | /** |
44 | - * Calcula el porcentaje de una cantidad |
|
45 | - * |
|
46 | - * @param float $por: El porcentaje a evaluar, por ejemplo 1, 20, 30 % sin el "%", sólamente el número |
|
47 | - * @param float $n: El número al cual se le quiere sacar el porcentaje |
|
48 | - * |
|
49 | - * @return float con el porcentaje correspondiente |
|
50 | - */ |
|
44 | + * Calcula el porcentaje de una cantidad |
|
45 | + * |
|
46 | + * @param float $por: El porcentaje a evaluar, por ejemplo 1, 20, 30 % sin el "%", sólamente el número |
|
47 | + * @param float $n: El número al cual se le quiere sacar el porcentaje |
|
48 | + * |
|
49 | + * @return float con el porcentaje correspondiente |
|
50 | + */ |
|
51 | 51 | final public function percent(float $por, float $n) : float { |
52 | 52 | return $n * ($por / 100); |
53 | 53 | } |
@@ -55,12 +55,12 @@ discard block |
||
55 | 55 | //------------------------------------------------ |
56 | 56 | |
57 | 57 | /** |
58 | - * Da unidades de peso a un integer según sea su tamaño asumida en bytes |
|
59 | - * |
|
60 | - * @param int $size: Un entero que representa el tamaño a convertir |
|
61 | - * |
|
62 | - * @return string del tamaño $size convertido a la unidad más adecuada |
|
63 | - */ |
|
58 | + * Da unidades de peso a un integer según sea su tamaño asumida en bytes |
|
59 | + * |
|
60 | + * @param int $size: Un entero que representa el tamaño a convertir |
|
61 | + * |
|
62 | + * @return string del tamaño $size convertido a la unidad más adecuada |
|
63 | + */ |
|
64 | 64 | final public function convert(int $size) : string { |
65 | 65 | $unit = array('bytes','kb','mb','gb','tb','pb'); |
66 | 66 | return round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i]; |
@@ -69,57 +69,57 @@ discard block |
||
69 | 69 | //------------------------------------------------ |
70 | 70 | |
71 | 71 | /** |
72 | - * Retorna la URL de un gravatar, según el email |
|
73 | - * |
|
74 | - * @param string $email: El email del usuario a extraer el gravatar |
|
75 | - * @param int $size: El tamaño del gravatar |
|
76 | - * @return string con la URl |
|
77 | - */ |
|
78 | - final public function get_gravatar(string $email, int $size = 32) : string { |
|
79 | - return 'http://www.gravatar.com/avatar/' . md5($email) . '?s=' . (int) abs($size); |
|
80 | - } |
|
81 | - |
|
82 | - //------------------------------------------------ |
|
83 | - |
|
84 | - /** |
|
72 | + * Retorna la URL de un gravatar, según el email |
|
73 | + * |
|
74 | + * @param string $email: El email del usuario a extraer el gravatar |
|
75 | + * @param int $size: El tamaño del gravatar |
|
76 | + * @return string con la URl |
|
77 | + */ |
|
78 | + final public function get_gravatar(string $email, int $size = 32) : string { |
|
79 | + return 'http://www.gravatar.com/avatar/' . md5($email) . '?s=' . (int) abs($size); |
|
80 | + } |
|
81 | + |
|
82 | + //------------------------------------------------ |
|
83 | + |
|
84 | + /** |
|
85 | 85 | * Alias de Empty, más completo |
86 | 86 | * |
87 | 87 | * @param midex $var: Variable a analizar |
88 | 88 | * |
89 | 89 | * @return true si está vacío, false si no, un espacio en blanco cuenta como vacío |
90 | - */ |
|
91 | - final public function emp($var) : bool { |
|
92 | - return (isset($var) && empty(trim(str_replace(' ','',$var)))); |
|
93 | - } |
|
90 | + */ |
|
91 | + final public function emp($var) : bool { |
|
92 | + return (isset($var) && empty(trim(str_replace(' ','',$var)))); |
|
93 | + } |
|
94 | 94 | |
95 | - //------------------------------------------------ |
|
95 | + //------------------------------------------------ |
|
96 | 96 | |
97 | - /** |
|
97 | + /** |
|
98 | 98 | * Aanaliza que TODOS los elementos de un arreglo estén llenos, útil para analizar por ejemplo que todos los elementos de un formulario esté llenos |
99 | 99 | * pasando como parámetro $_POST |
100 | 100 | * |
101 | 101 | * @param array $array, arreglo a analizar |
102 | 102 | * |
103 | 103 | * @return true si están todos llenos, false si al menos uno está vacío |
104 | - */ |
|
105 | - final public function all_full(array $array) : bool { |
|
106 | - foreach($array as $e) { |
|
107 | - if(self::emp($e) and $e != '0') { |
|
108 | - return false; |
|
109 | - } |
|
110 | - } |
|
111 | - return true; |
|
112 | - } |
|
113 | - |
|
114 | - //------------------------------------------------ |
|
115 | - |
|
116 | - /** |
|
104 | + */ |
|
105 | + final public function all_full(array $array) : bool { |
|
106 | + foreach($array as $e) { |
|
107 | + if(self::emp($e) and $e != '0') { |
|
108 | + return false; |
|
109 | + } |
|
110 | + } |
|
111 | + return true; |
|
112 | + } |
|
113 | + |
|
114 | + //------------------------------------------------ |
|
115 | + |
|
116 | + /** |
|
117 | 117 | * Alias de Empty() pero soporta más de un parámetro |
118 | 118 | * |
119 | 119 | * @param infinitos parámetros |
120 | 120 | * |
121 | 121 | * @return true si al menos uno está vacío, false si todos están llenos |
122 | - */ |
|
122 | + */ |
|
123 | 123 | final public function e() : bool { |
124 | 124 | for ($i = 0, $nargs = func_num_args(); $i < $nargs; $i++) { |
125 | 125 | if(null === func_get_arg($i) || (self::emp(func_get_arg($i)) && func_get_arg($i) != '0')) { |
@@ -132,58 +132,58 @@ discard block |
||
132 | 132 | //------------------------------------------------ |
133 | 133 | |
134 | 134 | /** |
135 | - * Alias de date() pero devuele días y meses en español |
|
136 | - * |
|
137 | - * @param string $format: Formato de salida (igual que en date()) |
|
138 | - * @param int $time: Tiempo, por defecto es time() (igual que en date()) |
|
139 | - * |
|
140 | - * @return string con la fecha en formato humano (y en español) |
|
141 | - */ |
|
142 | - final public function fecha(string $format, int $time = 0) : string { |
|
143 | - $date = date($format,$time == 0 ? time() : $time); |
|
144 | - $cambios = array( |
|
145 | - 'Monday'=> 'Lunes', |
|
146 | - 'Tuesday'=> 'Martes', |
|
147 | - 'Wednesday'=> 'Miércoles', |
|
148 | - 'Thursday'=> 'Jueves', |
|
149 | - 'Friday'=> 'Viernes', |
|
150 | - 'Saturday'=> 'Sábado', |
|
151 | - 'Sunday'=> 'Domingo', |
|
152 | - 'January'=> 'Enero', |
|
153 | - 'February'=> 'Febrero', |
|
154 | - 'March'=> 'Marzo', |
|
155 | - 'April'=> 'Abril', |
|
156 | - 'May'=> 'Mayo', |
|
157 | - 'June'=> 'Junio', |
|
158 | - 'July'=> 'Julio', |
|
159 | - 'August'=> 'Agosto', |
|
160 | - 'September'=> 'Septiembre', |
|
161 | - 'October'=> 'Octubre', |
|
162 | - 'November'=> 'Noviembre', |
|
163 | - 'December'=> 'Diciembre', |
|
164 | - 'Mon'=> 'Lun', |
|
165 | - 'Tue'=> 'Mar', |
|
166 | - 'Wed'=> 'Mie', |
|
167 | - 'Thu'=> 'Jue', |
|
168 | - 'Fri'=> 'Vie', |
|
169 | - 'Sat'=> 'Sab', |
|
170 | - 'Sun'=> 'Dom', |
|
171 | - 'Jan'=> 'Ene', |
|
172 | - 'Aug'=> 'Ago', |
|
173 | - 'Apr'=> 'Abr', |
|
174 | - 'Dec'=> 'Dic' |
|
175 | - ); |
|
176 | - return str_replace(array_keys($cambios),array_values($cambios),$date); |
|
177 | - } |
|
178 | - |
|
179 | - //------------------------------------------------ |
|
135 | + * Alias de date() pero devuele días y meses en español |
|
136 | + * |
|
137 | + * @param string $format: Formato de salida (igual que en date()) |
|
138 | + * @param int $time: Tiempo, por defecto es time() (igual que en date()) |
|
139 | + * |
|
140 | + * @return string con la fecha en formato humano (y en español) |
|
141 | + */ |
|
142 | + final public function fecha(string $format, int $time = 0) : string { |
|
143 | + $date = date($format,$time == 0 ? time() : $time); |
|
144 | + $cambios = array( |
|
145 | + 'Monday'=> 'Lunes', |
|
146 | + 'Tuesday'=> 'Martes', |
|
147 | + 'Wednesday'=> 'Miércoles', |
|
148 | + 'Thursday'=> 'Jueves', |
|
149 | + 'Friday'=> 'Viernes', |
|
150 | + 'Saturday'=> 'Sábado', |
|
151 | + 'Sunday'=> 'Domingo', |
|
152 | + 'January'=> 'Enero', |
|
153 | + 'February'=> 'Febrero', |
|
154 | + 'March'=> 'Marzo', |
|
155 | + 'April'=> 'Abril', |
|
156 | + 'May'=> 'Mayo', |
|
157 | + 'June'=> 'Junio', |
|
158 | + 'July'=> 'Julio', |
|
159 | + 'August'=> 'Agosto', |
|
160 | + 'September'=> 'Septiembre', |
|
161 | + 'October'=> 'Octubre', |
|
162 | + 'November'=> 'Noviembre', |
|
163 | + 'December'=> 'Diciembre', |
|
164 | + 'Mon'=> 'Lun', |
|
165 | + 'Tue'=> 'Mar', |
|
166 | + 'Wed'=> 'Mie', |
|
167 | + 'Thu'=> 'Jue', |
|
168 | + 'Fri'=> 'Vie', |
|
169 | + 'Sat'=> 'Sab', |
|
170 | + 'Sun'=> 'Dom', |
|
171 | + 'Jan'=> 'Ene', |
|
172 | + 'Aug'=> 'Ago', |
|
173 | + 'Apr'=> 'Abr', |
|
174 | + 'Dec'=> 'Dic' |
|
175 | + ); |
|
176 | + return str_replace(array_keys($cambios),array_values($cambios),$date); |
|
177 | + } |
|
178 | + |
|
179 | + //------------------------------------------------ |
|
180 | 180 | |
181 | 181 | /** |
182 | - * Devuelve la etiqueta <base> html adecuada para que los assets carguen desde allí. |
|
183 | - * Se adapta a la configuración del dominio en general. |
|
184 | - * |
|
185 | - * @return string <base href="ruta" /> |
|
186 | - */ |
|
182 | + * Devuelve la etiqueta <base> html adecuada para que los assets carguen desde allí. |
|
183 | + * Se adapta a la configuración del dominio en general. |
|
184 | + * |
|
185 | + * @return string <base href="ruta" /> |
|
186 | + */ |
|
187 | 187 | public function base_assets() : string { |
188 | 188 | global $config, $http; |
189 | 189 | |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | * @param int $anio: Año (1975 a 2xxx) |
212 | 212 | * |
213 | 213 | * @return int con el número del día |
214 | - */ |
|
214 | + */ |
|
215 | 215 | public function last_day_month(int $mes, int $anio) : int { |
216 | 216 | return date('d', (mktime(0,0,0,$mes + 1, 1, $anio) - 1)); |
217 | 217 | } |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | * @param int $num: cifra |
225 | 225 | * |
226 | 226 | * @return string cifra con cero a la izquirda |
227 | - */ |
|
227 | + */ |
|
228 | 228 | public function cero_izq(int $num) : string { |
229 | 229 | if($num < 10) { |
230 | 230 | return '0' . $num; |
@@ -233,16 +233,16 @@ discard block |
||
233 | 233 | return $num; |
234 | 234 | } |
235 | 235 | |
236 | - //------------------------------------------------ |
|
236 | + //------------------------------------------------ |
|
237 | 237 | |
238 | - /** |
|
239 | - * Devuelve el timestamp de una fecha, y null si su formato es incorrecto. |
|
240 | - * |
|
241 | - * @param string|null $fecha: Fecha con formato dd/mm/yy |
|
242 | - * @param string $hora: Hora de inicio de la $fecha |
|
243 | - * |
|
244 | - * @return int|null con el timestamp |
|
245 | - */ |
|
238 | + /** |
|
239 | + * Devuelve el timestamp de una fecha, y null si su formato es incorrecto. |
|
240 | + * |
|
241 | + * @param string|null $fecha: Fecha con formato dd/mm/yy |
|
242 | + * @param string $hora: Hora de inicio de la $fecha |
|
243 | + * |
|
244 | + * @return int|null con el timestamp |
|
245 | + */ |
|
246 | 246 | public function str_to_time($fecha, string $hora = '00:00:00') { |
247 | 247 | if(null == $fecha) { |
248 | 248 | return null; |
@@ -286,24 +286,24 @@ discard block |
||
286 | 286 | * @param int $desde: Desde donde |
287 | 287 | * |
288 | 288 | * @return string fecha |
289 | - */ |
|
290 | - public function desde_date(int $desde) : string { |
|
291 | - # Obtener esta fecha |
|
292 | - $hoy = date('d/m/Y/D',time()); |
|
293 | - $hoy = explode('/',$hoy); |
|
289 | + */ |
|
290 | + public function desde_date(int $desde) : string { |
|
291 | + # Obtener esta fecha |
|
292 | + $hoy = date('d/m/Y/D',time()); |
|
293 | + $hoy = explode('/',$hoy); |
|
294 | 294 | |
295 | 295 | |
296 | - switch($desde) { |
|
297 | - # Hoy |
|
298 | - case 1: |
|
296 | + switch($desde) { |
|
297 | + # Hoy |
|
298 | + case 1: |
|
299 | 299 | return date('d/m/Y', time()); |
300 | - break; |
|
301 | - # Ayer |
|
302 | - case 2: |
|
300 | + break; |
|
301 | + # Ayer |
|
302 | + case 2: |
|
303 | 303 | return date('d/m/Y', time() - (60*60*24)); |
304 | - break; |
|
305 | - # Semana |
|
306 | - case 3: |
|
304 | + break; |
|
305 | + # Semana |
|
306 | + case 3: |
|
307 | 307 | # Día de la semana actual |
308 | 308 | switch($hoy[3]) { |
309 | 309 | case 'Mon': |
@@ -341,20 +341,20 @@ discard block |
||
341 | 341 | } |
342 | 342 | |
343 | 343 | return $this->cero_izq($dia) .'/'. $this->cero_izq($hoy[1]) .'/' . $hoy[2]; |
344 | - break; |
|
345 | - # Mes |
|
346 | - case 4: |
|
344 | + break; |
|
345 | + # Mes |
|
346 | + case 4: |
|
347 | 347 | return '01/'. $this->cero_izq($hoy[1]) .'/' . $hoy[2]; |
348 | - break; |
|
349 | - # Año |
|
350 | - case 5: |
|
348 | + break; |
|
349 | + # Año |
|
350 | + case 5: |
|
351 | 351 | return '01/01/' . $hoy[2]; |
352 | - break; |
|
353 | - default: |
|
352 | + break; |
|
353 | + default: |
|
354 | 354 | throw new \RuntimeException('Problema con el valor $desde en desde_date()'); |
355 | - break; |
|
356 | - } |
|
357 | - } |
|
355 | + break; |
|
356 | + } |
|
357 | + } |
|
358 | 358 | |
359 | 359 | //------------------------------------------------ |
360 | 360 | |
@@ -362,44 +362,44 @@ discard block |
||
362 | 362 | * Obtiene el tiempo actual |
363 | 363 | * |
364 | 364 | * @return int devuelve time() |
365 | - */ |
|
366 | - public function timestamp() : int { |
|
367 | - return time(); |
|
368 | - } |
|
365 | + */ |
|
366 | + public function timestamp() : int { |
|
367 | + return time(); |
|
368 | + } |
|
369 | 369 | |
370 | 370 | //------------------------------------------------ |
371 | 371 | |
372 | 372 | /** |
373 | 373 | * Se obtiene de Twig_Extension y sirve para que cada función esté disponible como etiqueta en twig |
374 | - * |
|
374 | + * |
|
375 | 375 | * @return array: Todas las funciones con sus respectivos nombres de acceso en plantillas twig |
376 | - */ |
|
377 | - public function getFunctions() : array { |
|
376 | + */ |
|
377 | + public function getFunctions() : array { |
|
378 | 378 | return array( |
379 | - new \Twig_Function('percent', array($this, 'percent')), |
|
380 | - new \Twig_Function('convert', array($this, 'convert')), |
|
381 | - new \Twig_Function('get_gravatar', array($this, 'get_gravatar')), |
|
382 | - new \Twig_Function('emp', array($this, 'emp')), |
|
383 | - new \Twig_Function('e_dynamic', array($this, 'e')), |
|
384 | - new \Twig_Function('all_full', array($this, 'all_full')), |
|
385 | - new \Twig_Function('fecha', array($this, 'fecha')), |
|
386 | - new \Twig_Function('base_assets',array($this, 'base_assets')), |
|
387 | - new \Twig_Function('timestamp',array($this, 'timestamp')), |
|
388 | - new \Twig_Function('desde_date',array($this, 'desde_date')), |
|
389 | - new \Twig_Function('cero_izq',array($this, 'cero_izq')), |
|
390 | - new \Twig_Function('last_day_month',array($this, 'last_day_month')), |
|
391 | - new \Twig_Function('str_to_time',array($this, 'str_to_time')), |
|
392 | - new \Twig_Function('desde_date',array($this, 'desde_date')) |
|
393 | - ); |
|
394 | - } |
|
395 | - |
|
396 | - //------------------------------------------------ |
|
379 | + new \Twig_Function('percent', array($this, 'percent')), |
|
380 | + new \Twig_Function('convert', array($this, 'convert')), |
|
381 | + new \Twig_Function('get_gravatar', array($this, 'get_gravatar')), |
|
382 | + new \Twig_Function('emp', array($this, 'emp')), |
|
383 | + new \Twig_Function('e_dynamic', array($this, 'e')), |
|
384 | + new \Twig_Function('all_full', array($this, 'all_full')), |
|
385 | + new \Twig_Function('fecha', array($this, 'fecha')), |
|
386 | + new \Twig_Function('base_assets',array($this, 'base_assets')), |
|
387 | + new \Twig_Function('timestamp',array($this, 'timestamp')), |
|
388 | + new \Twig_Function('desde_date',array($this, 'desde_date')), |
|
389 | + new \Twig_Function('cero_izq',array($this, 'cero_izq')), |
|
390 | + new \Twig_Function('last_day_month',array($this, 'last_day_month')), |
|
391 | + new \Twig_Function('str_to_time',array($this, 'str_to_time')), |
|
392 | + new \Twig_Function('desde_date',array($this, 'desde_date')) |
|
393 | + ); |
|
394 | + } |
|
395 | + |
|
396 | + //------------------------------------------------ |
|
397 | 397 | |
398 | 398 | /** |
399 | - * Identificador único para la extensión de twig |
|
400 | - * |
|
401 | - * @return string: Nombre de la extensión |
|
402 | - */ |
|
399 | + * Identificador único para la extensión de twig |
|
400 | + * |
|
401 | + * @return string: Nombre de la extensión |
|
402 | + */ |
|
403 | 403 | public function getName() : string { |
404 | 404 | return 'ocrend_framework_func_class'; |
405 | 405 | } |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | final public function redir($url = null) { |
31 | 31 | global $config; |
32 | 32 | |
33 | - if(null == $url) { |
|
33 | + if (null == $url) { |
|
34 | 34 | $url = $config['site']['url']; |
35 | 35 | } |
36 | 36 | |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * @return float con el porcentaje correspondiente |
50 | 50 | */ |
51 | 51 | final public function percent(float $por, float $n) : float { |
52 | - return $n * ($por / 100); |
|
52 | + return $n*($por/100); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | //------------------------------------------------ |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | * @return string del tamaño $size convertido a la unidad más adecuada |
63 | 63 | */ |
64 | 64 | final public function convert(int $size) : string { |
65 | - $unit = array('bytes','kb','mb','gb','tb','pb'); |
|
66 | - return round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i]; |
|
65 | + $unit = array('bytes', 'kb', 'mb', 'gb', 'tb', 'pb'); |
|
66 | + return round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . ' ' . $unit[$i]; |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | //------------------------------------------------ |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | * @return true si está vacío, false si no, un espacio en blanco cuenta como vacío |
90 | 90 | */ |
91 | 91 | final public function emp($var) : bool { |
92 | - return (isset($var) && empty(trim(str_replace(' ','',$var)))); |
|
92 | + return (isset($var) && empty(trim(str_replace(' ', '', $var)))); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | //------------------------------------------------ |
@@ -103,8 +103,8 @@ discard block |
||
103 | 103 | * @return true si están todos llenos, false si al menos uno está vacío |
104 | 104 | */ |
105 | 105 | final public function all_full(array $array) : bool { |
106 | - foreach($array as $e) { |
|
107 | - if(self::emp($e) and $e != '0') { |
|
106 | + foreach ($array as $e) { |
|
107 | + if (self::emp($e) and $e != '0') { |
|
108 | 108 | return false; |
109 | 109 | } |
110 | 110 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | */ |
123 | 123 | final public function e() : bool { |
124 | 124 | for ($i = 0, $nargs = func_num_args(); $i < $nargs; $i++) { |
125 | - if(null === func_get_arg($i) || (self::emp(func_get_arg($i)) && func_get_arg($i) != '0')) { |
|
125 | + if (null === func_get_arg($i) || (self::emp(func_get_arg($i)) && func_get_arg($i) != '0')) { |
|
126 | 126 | return true; |
127 | 127 | } |
128 | 128 | } |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | * @return string con la fecha en formato humano (y en español) |
141 | 141 | */ |
142 | 142 | final public function fecha(string $format, int $time = 0) : string { |
143 | - $date = date($format,$time == 0 ? time() : $time); |
|
143 | + $date = date($format, $time == 0 ? time() : $time); |
|
144 | 144 | $cambios = array( |
145 | 145 | 'Monday'=> 'Lunes', |
146 | 146 | 'Tuesday'=> 'Martes', |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | 'Apr'=> 'Abr', |
174 | 174 | 'Dec'=> 'Dic' |
175 | 175 | ); |
176 | - return str_replace(array_keys($cambios),array_values($cambios),$date); |
|
176 | + return str_replace(array_keys($cambios), array_values($cambios), $date); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | //------------------------------------------------ |
@@ -193,13 +193,13 @@ discard block |
||
193 | 193 | # Revisar protocolo |
194 | 194 | $base = $config['site']['router']['protocol'] . '://'; |
195 | 195 | |
196 | - if(strtolower($www) == 'www') { |
|
196 | + if (strtolower($www) == 'www') { |
|
197 | 197 | $base .= 'www.' . $config['site']['router']['path']; |
198 | 198 | } else { |
199 | 199 | $base .= $config['site']['router']['path']; |
200 | 200 | } |
201 | 201 | |
202 | - return '<base href="'.$base.'" />'; |
|
202 | + return '<base href="' . $base . '" />'; |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | //------------------------------------------------ |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | * @return int con el número del día |
214 | 214 | */ |
215 | 215 | public function last_day_month(int $mes, int $anio) : int { |
216 | - return date('d', (mktime(0,0,0,$mes + 1, 1, $anio) - 1)); |
|
216 | + return date('d', (mktime(0, 0, 0, $mes + 1, 1, $anio) - 1)); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | //------------------------------------------------ |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | * @return string cifra con cero a la izquirda |
227 | 227 | */ |
228 | 228 | public function cero_izq(int $num) : string { |
229 | - if($num < 10) { |
|
229 | + if ($num < 10) { |
|
230 | 230 | return '0' . $num; |
231 | 231 | } |
232 | 232 | |
@@ -244,24 +244,24 @@ discard block |
||
244 | 244 | * @return int|null con el timestamp |
245 | 245 | */ |
246 | 246 | public function str_to_time($fecha, string $hora = '00:00:00') { |
247 | - if(null == $fecha) { |
|
247 | + if (null == $fecha) { |
|
248 | 248 | return null; |
249 | 249 | } |
250 | 250 | |
251 | - $detail = explode('/',$fecha); |
|
251 | + $detail = explode('/', $fecha); |
|
252 | 252 | |
253 | 253 | // Formato de día incorrecto |
254 | - if(!array_key_exists(0,$detail) || !is_numeric($detail[0]) || intval($detail[0]) < 1) { |
|
254 | + if (!array_key_exists(0, $detail) || !is_numeric($detail[0]) || intval($detail[0]) < 1) { |
|
255 | 255 | return null; |
256 | 256 | } |
257 | 257 | |
258 | 258 | // Formato del año |
259 | - if(!array_key_exists(2,$detail) || !is_numeric($detail[2]) || intval($detail[2]) < 1975) { |
|
259 | + if (!array_key_exists(2, $detail) || !is_numeric($detail[2]) || intval($detail[2]) < 1975) { |
|
260 | 260 | return null; |
261 | 261 | } |
262 | 262 | |
263 | 263 | // Formato de mes incorrecto |
264 | - if(!array_key_exists(1,$detail) || !is_numeric($detail[1]) || intval($detail[1]) < 1 || intval($detail[1]) > 12) { |
|
264 | + if (!array_key_exists(1, $detail) || !is_numeric($detail[1]) || intval($detail[1]) < 1 || intval($detail[1]) > 12) { |
|
265 | 265 | return null; |
266 | 266 | } |
267 | 267 | |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | $year = intval($detail[2]); |
272 | 272 | |
273 | 273 | // Veriricar dia según mes |
274 | - if($day > $this->last_day_month($month,$year)) { |
|
274 | + if ($day > $this->last_day_month($month, $year)) { |
|
275 | 275 | return null; |
276 | 276 | } |
277 | 277 | |
@@ -289,11 +289,11 @@ discard block |
||
289 | 289 | */ |
290 | 290 | public function desde_date(int $desde) : string { |
291 | 291 | # Obtener esta fecha |
292 | - $hoy = date('d/m/Y/D',time()); |
|
293 | - $hoy = explode('/',$hoy); |
|
292 | + $hoy = date('d/m/Y/D', time()); |
|
293 | + $hoy = explode('/', $hoy); |
|
294 | 294 | |
295 | 295 | |
296 | - switch($desde) { |
|
296 | + switch ($desde) { |
|
297 | 297 | # Hoy |
298 | 298 | case 1: |
299 | 299 | return date('d/m/Y', time()); |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | # Semana |
306 | 306 | case 3: |
307 | 307 | # Día de la semana actual |
308 | - switch($hoy[3]) { |
|
308 | + switch ($hoy[3]) { |
|
309 | 309 | case 'Mon': |
310 | 310 | $dia = $hoy[0]; |
311 | 311 | break; |
@@ -330,21 +330,21 @@ discard block |
||
330 | 330 | } |
331 | 331 | |
332 | 332 | # Mes anterior y posiblemente, año también. |
333 | - if($dia == 0) { |
|
333 | + if ($dia == 0) { |
|
334 | 334 | # Verificamos si estamos en enero |
335 | - if($hoy[1] == 1) { |
|
336 | - return $this->last_day_month($hoy[1],$hoy[2]) .'/'. $this->cero_izq($hoy[1] - 1) .'/' . ($hoy[2] - 1); |
|
335 | + if ($hoy[1] == 1) { |
|
336 | + return $this->last_day_month($hoy[1], $hoy[2]) . '/' . $this->cero_izq($hoy[1] - 1) . '/' . ($hoy[2] - 1); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | # Si no es enero, es el año actual |
340 | - return $this->last_day_month($hoy[1],$hoy[2]) .'/'. $this->cero_izq($hoy[1] - 1) .'/' . $hoy[2]; |
|
340 | + return $this->last_day_month($hoy[1], $hoy[2]) . '/' . $this->cero_izq($hoy[1] - 1) . '/' . $hoy[2]; |
|
341 | 341 | } |
342 | 342 | |
343 | - return $this->cero_izq($dia) .'/'. $this->cero_izq($hoy[1]) .'/' . $hoy[2]; |
|
343 | + return $this->cero_izq($dia) . '/' . $this->cero_izq($hoy[1]) . '/' . $hoy[2]; |
|
344 | 344 | break; |
345 | 345 | # Mes |
346 | 346 | case 4: |
347 | - return '01/'. $this->cero_izq($hoy[1]) .'/' . $hoy[2]; |
|
347 | + return '01/' . $this->cero_izq($hoy[1]) . '/' . $hoy[2]; |
|
348 | 348 | break; |
349 | 349 | # Año |
350 | 350 | case 5: |
@@ -383,13 +383,13 @@ discard block |
||
383 | 383 | new \Twig_Function('e_dynamic', array($this, 'e')), |
384 | 384 | new \Twig_Function('all_full', array($this, 'all_full')), |
385 | 385 | new \Twig_Function('fecha', array($this, 'fecha')), |
386 | - new \Twig_Function('base_assets',array($this, 'base_assets')), |
|
387 | - new \Twig_Function('timestamp',array($this, 'timestamp')), |
|
388 | - new \Twig_Function('desde_date',array($this, 'desde_date')), |
|
389 | - new \Twig_Function('cero_izq',array($this, 'cero_izq')), |
|
390 | - new \Twig_Function('last_day_month',array($this, 'last_day_month')), |
|
391 | - new \Twig_Function('str_to_time',array($this, 'str_to_time')), |
|
392 | - new \Twig_Function('desde_date',array($this, 'desde_date')) |
|
386 | + new \Twig_Function('base_assets', array($this, 'base_assets')), |
|
387 | + new \Twig_Function('timestamp', array($this, 'timestamp')), |
|
388 | + new \Twig_Function('desde_date', array($this, 'desde_date')), |
|
389 | + new \Twig_Function('cero_izq', array($this, 'cero_izq')), |
|
390 | + new \Twig_Function('last_day_month', array($this, 'last_day_month')), |
|
391 | + new \Twig_Function('str_to_time', array($this, 'str_to_time')), |
|
392 | + new \Twig_Function('desde_date', array($this, 'desde_date')) |
|
393 | 393 | ); |
394 | 394 | } |
395 | 395 |
@@ -23,32 +23,32 @@ discard block |
||
23 | 23 | abstract class Models { |
24 | 24 | |
25 | 25 | /** |
26 | - * Tiene siempre el id pasado por la ruta, en caso de no haber ninguno, será cero. |
|
27 | - * |
|
28 | - * @var int |
|
29 | - */ |
|
26 | + * Tiene siempre el id pasado por la ruta, en caso de no haber ninguno, será cero. |
|
27 | + * |
|
28 | + * @var int |
|
29 | + */ |
|
30 | 30 | protected $id = 0; |
31 | 31 | |
32 | 32 | /** |
33 | - * Contiene una instancia del helper para funciones |
|
34 | - * |
|
35 | - * @var Ocrend\Kernel\Helpers\Functions |
|
36 | - */ |
|
33 | + * Contiene una instancia del helper para funciones |
|
34 | + * |
|
35 | + * @var Ocrend\Kernel\Helpers\Functions |
|
36 | + */ |
|
37 | 37 | protected $functions; |
38 | 38 | |
39 | 39 | /** |
40 | - * Contiene el id del usuario que tiene su sesión iniciada. |
|
41 | - * |
|
42 | - * @var int|null con id del usuario |
|
43 | - */ |
|
40 | + * Contiene el id del usuario que tiene su sesión iniciada. |
|
41 | + * |
|
42 | + * @var int|null con id del usuario |
|
43 | + */ |
|
44 | 44 | protected $id_user = null; |
45 | 45 | |
46 | 46 | /** |
47 | - * Inicia la configuración inicial de cualquier modelo |
|
48 | - * |
|
49 | - * @param IRouter $router: Instancia de un Router |
|
50 | - * |
|
51 | - */ |
|
47 | + * Inicia la configuración inicial de cualquier modelo |
|
48 | + * |
|
49 | + * @param IRouter $router: Instancia de un Router |
|
50 | + * |
|
51 | + */ |
|
52 | 52 | protected function __construct(IRouter $router = null) { |
53 | 53 | global $session, $config; |
54 | 54 | |
@@ -63,19 +63,19 @@ discard block |
||
63 | 63 | |
64 | 64 | # Verificar sesión del usuario |
65 | 65 | if(null != $session->get('user_id') && $session->get('unique_session') == $config['sessions']['unique']) { |
66 | - $this->id_user = $session->get('user_id'); |
|
66 | + $this->id_user = $session->get('user_id'); |
|
67 | 67 | } |
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
71 | - * Asigna el id desde un modelo, ideal para cuando queremos darle un valor numérico |
|
72 | - * que proviene de un formulario y puede ser inseguro. |
|
73 | - * |
|
74 | - * @param mixed $id : Id a asignar en $this->id |
|
75 | - * @param string $default_msg : Mensaje a mostrar en caso de que no se pueda asignar |
|
76 | - * |
|
77 | - * @throws ModelsException |
|
78 | - */ |
|
71 | + * Asigna el id desde un modelo, ideal para cuando queremos darle un valor numérico |
|
72 | + * que proviene de un formulario y puede ser inseguro. |
|
73 | + * |
|
74 | + * @param mixed $id : Id a asignar en $this->id |
|
75 | + * @param string $default_msg : Mensaje a mostrar en caso de que no se pueda asignar |
|
76 | + * |
|
77 | + * @throws ModelsException |
|
78 | + */ |
|
79 | 79 | protected function setId($id, string $default_msg = 'No puedede asignarse el id.') { |
80 | 80 | if(null == $id || !is_numeric($id) || $id <= 0) { |
81 | 81 | throw new ModelsException($default_msg); |
@@ -85,8 +85,8 @@ discard block |
||
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
88 | - * Cierra el modelo |
|
89 | - */ |
|
88 | + * Cierra el modelo |
|
89 | + */ |
|
90 | 90 | protected function __destruct() {} |
91 | 91 | |
92 | 92 | } |
93 | 93 | \ No newline at end of file |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * @author Brayan Narváez <[email protected]> |
21 | 21 | */ |
22 | 22 | |
23 | -abstract class Models { |
|
23 | +abstract class Models { |
|
24 | 24 | |
25 | 25 | /** |
26 | 26 | * Tiene siempre el id pasado por la ruta, en caso de no haber ninguno, será cero. |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | global $session, $config; |
54 | 54 | |
55 | 55 | # Id captado por la ruta |
56 | - if(null != $router) { |
|
56 | + if (null != $router) { |
|
57 | 57 | $this->id = $router->getId(true); |
58 | 58 | $this->id = null == $this->id ? 0 : $this->id; |
59 | 59 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | $this->functions = new Functions(); |
63 | 63 | |
64 | 64 | # Verificar sesión del usuario |
65 | - if(null != $session->get('user_id') && $session->get('unique_session') == $config['sessions']['unique']) { |
|
65 | + if (null != $session->get('user_id') && $session->get('unique_session') == $config['sessions']['unique']) { |
|
66 | 66 | $this->id_user = $session->get('user_id'); |
67 | 67 | } |
68 | 68 | } |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * @throws ModelsException |
78 | 78 | */ |
79 | 79 | protected function setId($id, string $default_msg = 'No puedede asignarse el id.') { |
80 | - if(null == $id || !is_numeric($id) || $id <= 0) { |
|
80 | + if (null == $id || !is_numeric($id) || $id <= 0) { |
|
81 | 81 | throw new ModelsException($default_msg); |
82 | 82 | } |
83 | 83 |
@@ -20,15 +20,15 @@ |
||
20 | 20 | class ModelsException extends \Exception { |
21 | 21 | |
22 | 22 | /** |
23 | - * __construct() |
|
24 | - */ |
|
23 | + * __construct() |
|
24 | + */ |
|
25 | 25 | public function __construct($message = null, $code = 1, \Exception $previous = null) { |
26 | 26 | parent::__construct($message, $code, $previous); |
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
30 | - * Muestra el error con un formato u otro dependiendo desde donde se hace la petición. |
|
31 | - */ |
|
30 | + * Muestra el error con un formato u otro dependiendo desde donde se hace la petición. |
|
31 | + */ |
|
32 | 32 | public function errorResponse() { |
33 | 33 | throw new \RuntimeException($this->getMessage()); |
34 | 34 | } |
@@ -19,7 +19,7 @@ |
||
19 | 19 | * @author Brayan Narváez <[email protected]> |
20 | 20 | */ |
21 | 21 | |
22 | - interface IModels { |
|
23 | - public function __construct(IRouter $router = null); |
|
24 | - public function __destruct(); |
|
25 | - } |
|
26 | 22 | \ No newline at end of file |
23 | + interface IModels { |
|
24 | + public function __construct(IRouter $router = null); |
|
25 | + public function __destruct(); |
|
26 | + } |
|
27 | 27 | \ No newline at end of file |
@@ -9,43 +9,43 @@ discard block |
||
9 | 9 | * file that was distributed with this source code. |
10 | 10 | */ |
11 | 11 | |
12 | - namespace Ocrend\Kernel\Models\Traits; |
|
12 | + namespace Ocrend\Kernel\Models\Traits; |
|
13 | 13 | |
14 | - use Ocrend\Kernel\Database\Database; |
|
14 | + use Ocrend\Kernel\Database\Database; |
|
15 | 15 | |
16 | 16 | /** |
17 | - * Añade características a un modelo para que pueda conectarse a una base de datos. |
|
18 | - * |
|
19 | - * @author Brayan Narváez <[email protected]> |
|
17 | + * Añade características a un modelo para que pueda conectarse a una base de datos. |
|
18 | + * |
|
19 | + * @author Brayan Narváez <[email protected]> |
|
20 | 20 | */ |
21 | 21 | |
22 | 22 | trait DBModel { |
23 | 23 | |
24 | 24 | /** |
25 | - * Tiene la instancia de la base de datos actual |
|
26 | - * |
|
27 | - * @var null|Database |
|
28 | - */ |
|
25 | + * Tiene la instancia de la base de datos actual |
|
26 | + * |
|
27 | + * @var null|Database |
|
28 | + */ |
|
29 | 29 | protected $db = null; |
30 | 30 | |
31 | 31 | /** |
32 | - * Contiene la información que se pasa al manejador de la base de datos. |
|
33 | - * - Nombre de base de datos |
|
34 | - * - Motor de base de datos |
|
35 | - * - Valor de nueva instancia |
|
36 | - * |
|
37 | - * @var array |
|
38 | - */ |
|
32 | + * Contiene la información que se pasa al manejador de la base de datos. |
|
33 | + * - Nombre de base de datos |
|
34 | + * - Motor de base de datos |
|
35 | + * - Valor de nueva instancia |
|
36 | + * |
|
37 | + * @var array |
|
38 | + */ |
|
39 | 39 | private $databaseConfig = array(); |
40 | 40 | |
41 | 41 | /** |
42 | - * Establece la configuración de la base de datos |
|
43 | - * |
|
44 | - * @param array|null $databaseConfig: Configuración de conexión con base de datos con la forma |
|
45 | - * 'name' => string, # Nombre de la base de datos |
|
46 | - * 'motor' => string, # Motor de la base de datos |
|
47 | - * 'new_instance' => bool, # Establecer nueva instancia distinta a alguna ya existente |
|
48 | - */ |
|
42 | + * Establece la configuración de la base de datos |
|
43 | + * |
|
44 | + * @param array|null $databaseConfig: Configuración de conexión con base de datos con la forma |
|
45 | + * 'name' => string, # Nombre de la base de datos |
|
46 | + * 'motor' => string, # Motor de la base de datos |
|
47 | + * 'new_instance' => bool, # Establecer nueva instancia distinta a alguna ya existente |
|
48 | + */ |
|
49 | 49 | private function setDatabaseConfig($databaseConfig) { |
50 | 50 | global $config; |
51 | 51 | |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | # Añadir según lo pasado por $databaseConfig |
58 | 58 | if(is_array($databaseConfig)) { |
59 | 59 | if(array_key_exists('name',$databaseConfig)) { |
60 | - $this->databaseConfig['name'] = $databaseConfig['name']; |
|
60 | + $this->databaseConfig['name'] = $databaseConfig['name']; |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | if(array_key_exists('motor',$databaseConfig)) { |
@@ -71,13 +71,13 @@ discard block |
||
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
74 | - * Constructor inicial del modelo. |
|
75 | - * |
|
76 | - * @param array|null $databaseConfig: Configuración de conexión con base de datos con la forma |
|
77 | - * 'name' => string, # Nombre de la base de datos |
|
78 | - * 'motor' => string, # Motor de la base de datos |
|
79 | - * 'new_instance' => bool, # Establecer nueva instancia distinta a alguna ya existente |
|
80 | - */ |
|
74 | + * Constructor inicial del modelo. |
|
75 | + * |
|
76 | + * @param array|null $databaseConfig: Configuración de conexión con base de datos con la forma |
|
77 | + * 'name' => string, # Nombre de la base de datos |
|
78 | + * 'motor' => string, # Motor de la base de datos |
|
79 | + * 'new_instance' => bool, # Establecer nueva instancia distinta a alguna ya existente |
|
80 | + */ |
|
81 | 81 | protected function startDBConexion($databaseConfig = null) { |
82 | 82 | # Llenar la configuración a la base de datos |
83 | 83 | $this->setDatabaseConfig($databaseConfig); |
@@ -91,8 +91,8 @@ discard block |
||
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
94 | - * Finaliza la conexión con la base de datos. |
|
95 | - */ |
|
94 | + * Finaliza la conexión con la base de datos. |
|
95 | + */ |
|
96 | 96 | protected function endDBConexion() { |
97 | 97 | $this->db = null; |
98 | 98 | } |
@@ -55,16 +55,16 @@ |
||
55 | 55 | $this->databaseConfig['new_instance'] = false; |
56 | 56 | |
57 | 57 | # Añadir según lo pasado por $databaseConfig |
58 | - if(is_array($databaseConfig)) { |
|
59 | - if(array_key_exists('name',$databaseConfig)) { |
|
60 | - $this->databaseConfig['name'] = $databaseConfig['name']; |
|
58 | + if (is_array($databaseConfig)) { |
|
59 | + if (array_key_exists('name', $databaseConfig)) { |
|
60 | + $this->databaseConfig['name'] = $databaseConfig['name']; |
|
61 | 61 | } |
62 | 62 | |
63 | - if(array_key_exists('motor',$databaseConfig)) { |
|
64 | - $this->databaseConfig['motor'] = $databaseConfig['motor']; |
|
63 | + if (array_key_exists('motor', $databaseConfig)) { |
|
64 | + $this->databaseConfig['motor'] = $databaseConfig['motor']; |
|
65 | 65 | } |
66 | 66 | |
67 | - if(array_key_exists('new_instance',$databaseConfig)) { |
|
67 | + if (array_key_exists('new_instance', $databaseConfig)) { |
|
68 | 68 | $this->databaseConfig['new_instance'] = (bool) $databaseConfig['new_instance']; |
69 | 69 | } |
70 | 70 | } |
@@ -28,36 +28,36 @@ discard block |
||
28 | 28 | |
29 | 29 | class Users extends Models implements IModels { |
30 | 30 | /** |
31 | - * Característica para establecer conexión con base de datos. |
|
32 | - */ |
|
31 | + * Característica para establecer conexión con base de datos. |
|
32 | + */ |
|
33 | 33 | use DBModel; |
34 | 34 | |
35 | 35 | /** |
36 | - * Máximos intentos de inincio de sesión de un usuario |
|
37 | - * |
|
38 | - * @var int |
|
39 | - */ |
|
36 | + * Máximos intentos de inincio de sesión de un usuario |
|
37 | + * |
|
38 | + * @var int |
|
39 | + */ |
|
40 | 40 | const MAX_ATTEMPTS = 5; |
41 | 41 | |
42 | 42 | /** |
43 | - * Tiempo entre máximos intentos en segundos |
|
44 | - * |
|
45 | - * @var int |
|
46 | - */ |
|
43 | + * Tiempo entre máximos intentos en segundos |
|
44 | + * |
|
45 | + * @var int |
|
46 | + */ |
|
47 | 47 | const MAX_ATTEMPTS_TIME = 120; # (dos minutos) |
48 | 48 | |
49 | 49 | /** |
50 | - * Log de intentos recientes con la forma 'email' => (int) intentos |
|
51 | - * |
|
52 | - * @var array |
|
53 | - */ |
|
50 | + * Log de intentos recientes con la forma 'email' => (int) intentos |
|
51 | + * |
|
52 | + * @var array |
|
53 | + */ |
|
54 | 54 | private $recentAttempts = array(); |
55 | 55 | |
56 | - /** |
|
57 | - * Hace un set() a la sesión login_user_recentAttempts con el valor actualizado. |
|
58 | - * |
|
59 | - * @return void |
|
60 | - */ |
|
56 | + /** |
|
57 | + * Hace un set() a la sesión login_user_recentAttempts con el valor actualizado. |
|
58 | + * |
|
59 | + * @return void |
|
60 | + */ |
|
61 | 61 | private function updateSessionAttempts() { |
62 | 62 | global $session; |
63 | 63 | |
@@ -65,13 +65,13 @@ discard block |
||
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
68 | - * Genera la sesión con el id del usuario que ha iniciado |
|
69 | - * |
|
70 | - * @param string $pass : Contraseña sin encriptar |
|
71 | - * @param string $pass_repeat : Contraseña repetida sin encriptar |
|
72 | - * |
|
73 | - * @throws ModelsException cuando las contraseñas no coinciden |
|
74 | - */ |
|
68 | + * Genera la sesión con el id del usuario que ha iniciado |
|
69 | + * |
|
70 | + * @param string $pass : Contraseña sin encriptar |
|
71 | + * @param string $pass_repeat : Contraseña repetida sin encriptar |
|
72 | + * |
|
73 | + * @throws ModelsException cuando las contraseñas no coinciden |
|
74 | + */ |
|
75 | 75 | private function checkPassMatch(string $pass, string $pass_repeat) { |
76 | 76 | if($pass != $pass_repeat) { |
77 | 77 | throw new ModelsException('Las contraseñas no coinciden.'); |
@@ -79,12 +79,12 @@ discard block |
||
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
82 | - * Verifica el email introducido, tanto el formato como su existencia en el sistema |
|
83 | - * |
|
84 | - * @param string $email: Email del usuario |
|
85 | - * |
|
86 | - * @throws ModelsException en caso de que no tenga formato válido o ya exista |
|
87 | - */ |
|
82 | + * Verifica el email introducido, tanto el formato como su existencia en el sistema |
|
83 | + * |
|
84 | + * @param string $email: Email del usuario |
|
85 | + * |
|
86 | + * @throws ModelsException en caso de que no tenga formato válido o ya exista |
|
87 | + */ |
|
88 | 88 | private function checkEmail(string $email) { |
89 | 89 | # Formato de email |
90 | 90 | if(!Strings::is_email($email)) { |
@@ -99,13 +99,13 @@ discard block |
||
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
102 | - * Restaura los intentos de un usuario al iniciar sesión |
|
103 | - * |
|
104 | - * @param string $email: Email del usuario a restaurar |
|
105 | - * |
|
106 | - * @throws ModelsException cuando hay un error de lógica utilizando este método |
|
107 | - * @return void |
|
108 | - */ |
|
102 | + * Restaura los intentos de un usuario al iniciar sesión |
|
103 | + * |
|
104 | + * @param string $email: Email del usuario a restaurar |
|
105 | + * |
|
106 | + * @throws ModelsException cuando hay un error de lógica utilizando este método |
|
107 | + * @return void |
|
108 | + */ |
|
109 | 109 | private function restoreAttempts(string $email) { |
110 | 110 | if(array_key_exists($email,$this->recentAttempts)) { |
111 | 111 | $this->recentAttempts[$email]['attempts'] = 0; |
@@ -118,12 +118,12 @@ discard block |
||
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
121 | - * Genera la sesión con el id del usuario que ha iniciado |
|
122 | - * |
|
123 | - * @param array $user_data: Arreglo con información de la base de datos, del usuario |
|
124 | - * |
|
125 | - * @return void |
|
126 | - */ |
|
121 | + * Genera la sesión con el id del usuario que ha iniciado |
|
122 | + * |
|
123 | + * @param array $user_data: Arreglo con información de la base de datos, del usuario |
|
124 | + * |
|
125 | + * @return void |
|
126 | + */ |
|
127 | 127 | private function generateSession(array $user_data) { |
128 | 128 | global $session, $config; |
129 | 129 | |
@@ -132,14 +132,14 @@ discard block |
||
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
135 | - * Verifica en la base de datos, el email y contraseña ingresados por el usuario |
|
136 | - * |
|
137 | - * @param string $email: Email del usuario que intenta el login |
|
138 | - * @param string $pass: Contraseña sin encriptar del usuario que intenta el login |
|
139 | - * |
|
140 | - * @return bool true: Cuando el inicio de sesión es correcto |
|
141 | - * false: Cuando el inicio de sesión no es correcto |
|
142 | - */ |
|
135 | + * Verifica en la base de datos, el email y contraseña ingresados por el usuario |
|
136 | + * |
|
137 | + * @param string $email: Email del usuario que intenta el login |
|
138 | + * @param string $pass: Contraseña sin encriptar del usuario que intenta el login |
|
139 | + * |
|
140 | + * @return bool true: Cuando el inicio de sesión es correcto |
|
141 | + * false: Cuando el inicio de sesión no es correcto |
|
142 | + */ |
|
143 | 143 | private function authentication(string $email,string $pass) : bool { |
144 | 144 | $email = $this->db->scape($email); |
145 | 145 | $query = $this->db->select('id_user,pass','users',"email='$email'",'LIMIT 1'); |
@@ -159,10 +159,10 @@ discard block |
||
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
162 | - * Establece los intentos recientes desde la variable de sesión acumulativa |
|
163 | - * |
|
164 | - * @return void |
|
165 | - */ |
|
162 | + * Establece los intentos recientes desde la variable de sesión acumulativa |
|
163 | + * |
|
164 | + * @return void |
|
165 | + */ |
|
166 | 166 | private function setDefaultAttempts() { |
167 | 167 | global $session; |
168 | 168 | |
@@ -172,12 +172,12 @@ discard block |
||
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
175 | - * Establece el intento del usuario actual o incrementa su cantidad si ya existe |
|
176 | - * |
|
177 | - * @param string $email: Email del usuario |
|
178 | - * |
|
179 | - * @return void |
|
180 | - */ |
|
175 | + * Establece el intento del usuario actual o incrementa su cantidad si ya existe |
|
176 | + * |
|
177 | + * @param string $email: Email del usuario |
|
178 | + * |
|
179 | + * @return void |
|
180 | + */ |
|
181 | 181 | private function setNewAttempt(string $email) { |
182 | 182 | if(!array_key_exists($email,$this->recentAttempts)) { |
183 | 183 | $this->recentAttempts[$email] = array( |
@@ -191,14 +191,14 @@ discard block |
||
191 | 191 | } |
192 | 192 | |
193 | 193 | /** |
194 | - * Controla la cantidad de intentos permitidos máximos por usuario, si llega al límite, |
|
195 | - * el usuario podrá seguir intentando en self::MAX_ATTEMPTS_TIME segundos. |
|
196 | - * |
|
197 | - * @param string $email: Email del usuario |
|
198 | - * |
|
199 | - * @throws ModelsException cuando ya ha excedido self::MAX_ATTEMPTS |
|
200 | - * @return void |
|
201 | - */ |
|
194 | + * Controla la cantidad de intentos permitidos máximos por usuario, si llega al límite, |
|
195 | + * el usuario podrá seguir intentando en self::MAX_ATTEMPTS_TIME segundos. |
|
196 | + * |
|
197 | + * @param string $email: Email del usuario |
|
198 | + * |
|
199 | + * @throws ModelsException cuando ya ha excedido self::MAX_ATTEMPTS |
|
200 | + * @return void |
|
201 | + */ |
|
202 | 202 | private function maximumAttempts(string $email) { |
203 | 203 | if($this->recentAttempts[$email]['attempts'] >= self::MAX_ATTEMPTS) { |
204 | 204 | |
@@ -219,10 +219,10 @@ discard block |
||
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
222 | - * Realiza la acción de login dentro del sistema |
|
223 | - * |
|
224 | - * @return array : Con información de éxito/falla al inicio de sesión. |
|
225 | - */ |
|
222 | + * Realiza la acción de login dentro del sistema |
|
223 | + * |
|
224 | + * @return array : Con información de éxito/falla al inicio de sesión. |
|
225 | + */ |
|
226 | 226 | public function login() : array { |
227 | 227 | try { |
228 | 228 | global $http; |
@@ -258,10 +258,10 @@ discard block |
||
258 | 258 | } |
259 | 259 | |
260 | 260 | /** |
261 | - * Realiza la acción de registro dentro del sistema |
|
262 | - * |
|
263 | - * @return array : Con información de éxito/falla al registrar el usuario nuevo. |
|
264 | - */ |
|
261 | + * Realiza la acción de registro dentro del sistema |
|
262 | + * |
|
263 | + * @return array : Con información de éxito/falla al registrar el usuario nuevo. |
|
264 | + */ |
|
265 | 265 | public function register() : array { |
266 | 266 | try { |
267 | 267 | global $http; |
@@ -302,11 +302,11 @@ discard block |
||
302 | 302 | } |
303 | 303 | |
304 | 304 | /** |
305 | - * Envía un correo electrónico al usuario que quiere recuperar la contraseña, con un token y una nueva contraseña. |
|
306 | - * Si el usuario no visita el enlace, el sistema no cambiará la contraseña. |
|
307 | - * |
|
308 | - * @return void |
|
309 | - */ |
|
305 | + * Envía un correo electrónico al usuario que quiere recuperar la contraseña, con un token y una nueva contraseña. |
|
306 | + * Si el usuario no visita el enlace, el sistema no cambiará la contraseña. |
|
307 | + * |
|
308 | + * @return void |
|
309 | + */ |
|
310 | 310 | public function lostpass() { |
311 | 311 | try { |
312 | 312 | global $http, $config; |
@@ -341,8 +341,8 @@ discard block |
||
341 | 341 | Para cambiar su contraseña por <b>'. $pass .'</b> haga <a href="'. $config['site']['url'] . 'lostpass/cambiar/&token='.$token.'&user='.$user_data[0]['id_user'].'" target="_blank">clic aquí</a>.'; |
342 | 342 | |
343 | 343 | # Enviar el correo electrónico |
344 | - $dest[$email] = $user_data[0]['name']; |
|
345 | - $email = Emails::send_mail($dest,Emails::plantilla($HTML),'Recuperar contraseña perdida'); |
|
344 | + $dest[$email] = $user_data[0]['name']; |
|
345 | + $email = Emails::send_mail($dest,Emails::plantilla($HTML),'Recuperar contraseña perdida'); |
|
346 | 346 | |
347 | 347 | # Verificar si hubo algún problema con el envío del correo |
348 | 348 | if(false === $email) { |
@@ -363,13 +363,13 @@ discard block |
||
363 | 363 | } |
364 | 364 | |
365 | 365 | /** |
366 | - * Cambia la contraseña de un usuario en el sistema, luego de que éste haya solicitado cambiarla. |
|
367 | - * Luego retorna al sitio de inicio con la variable GET success=(bool) |
|
368 | - * |
|
369 | - * La URL debe tener la forma URL/lostpass/cambiar/&token=TOKEN&user=ID |
|
370 | - * |
|
371 | - * @return void |
|
372 | - */ |
|
366 | + * Cambia la contraseña de un usuario en el sistema, luego de que éste haya solicitado cambiarla. |
|
367 | + * Luego retorna al sitio de inicio con la variable GET success=(bool) |
|
368 | + * |
|
369 | + * La URL debe tener la forma URL/lostpass/cambiar/&token=TOKEN&user=ID |
|
370 | + * |
|
371 | + * @return void |
|
372 | + */ |
|
373 | 373 | public function changeTemporalPass() { |
374 | 374 | global $config, $http; |
375 | 375 | |
@@ -396,10 +396,10 @@ discard block |
||
396 | 396 | } |
397 | 397 | |
398 | 398 | /** |
399 | - * Desconecta a un usuario si éste está conectado, y lo devuelve al inicio |
|
400 | - * |
|
401 | - * @return void |
|
402 | - */ |
|
399 | + * Desconecta a un usuario si éste está conectado, y lo devuelve al inicio |
|
400 | + * |
|
401 | + * @return void |
|
402 | + */ |
|
403 | 403 | public function logout() { |
404 | 404 | global $session; |
405 | 405 | |
@@ -411,36 +411,36 @@ discard block |
||
411 | 411 | } |
412 | 412 | |
413 | 413 | /** |
414 | - * Obtiene datos de un usuario según su id en la base de datos |
|
415 | - * |
|
416 | - * @param int $id: Id del usuario a obtener |
|
417 | - * @param string $select : Por defecto es *, se usa para obtener sólo los parámetros necesarios |
|
418 | - * |
|
419 | - * @return false|array con información del usuario |
|
420 | - */ |
|
414 | + * Obtiene datos de un usuario según su id en la base de datos |
|
415 | + * |
|
416 | + * @param int $id: Id del usuario a obtener |
|
417 | + * @param string $select : Por defecto es *, se usa para obtener sólo los parámetros necesarios |
|
418 | + * |
|
419 | + * @return false|array con información del usuario |
|
420 | + */ |
|
421 | 421 | public function getUserById(int $id, string $select = '*') { |
422 | - return $this->db->select($select,'users',"id_user='$id'",'LIMIT 1'); |
|
422 | + return $this->db->select($select,'users',"id_user='$id'",'LIMIT 1'); |
|
423 | 423 | } |
424 | 424 | |
425 | 425 | /** |
426 | - * Obtiene a todos los usuarios |
|
427 | - * |
|
428 | - * @param string $select : Por defecto es *, se usa para obtener sólo los parámetros necesarios |
|
429 | - * |
|
430 | - * @return false|array con información de los usuarios |
|
431 | - */ |
|
426 | + * Obtiene a todos los usuarios |
|
427 | + * |
|
428 | + * @param string $select : Por defecto es *, se usa para obtener sólo los parámetros necesarios |
|
429 | + * |
|
430 | + * @return false|array con información de los usuarios |
|
431 | + */ |
|
432 | 432 | public function getUsers(string $select = '*') { |
433 | - return $this->db->select($select,'users'); |
|
433 | + return $this->db->select($select,'users'); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | /** |
437 | - * Obtiene datos del usuario conectado actualmente |
|
438 | - * |
|
439 | - * @param string $select : Por defecto es *, se usa para obtener sólo los parámetros necesarios |
|
440 | - * |
|
441 | - * @throws ModelsException si el usuario no está logeado |
|
442 | - * @return array con datos del usuario conectado |
|
443 | - */ |
|
437 | + * Obtiene datos del usuario conectado actualmente |
|
438 | + * |
|
439 | + * @param string $select : Por defecto es *, se usa para obtener sólo los parámetros necesarios |
|
440 | + * |
|
441 | + * @throws ModelsException si el usuario no está logeado |
|
442 | + * @return array con datos del usuario conectado |
|
443 | + */ |
|
444 | 444 | public function getOwnerUser(string $select = '*') : array { |
445 | 445 | if(null != $this->id_user) { |
446 | 446 | |
@@ -458,10 +458,10 @@ discard block |
||
458 | 458 | } |
459 | 459 | |
460 | 460 | /** |
461 | - * Instala el módulo de usuarios en la base de datos para que pueda funcionar correctamete. |
|
462 | - * |
|
463 | - * @throws \RuntimeException si no se puede realizar la query |
|
464 | - */ |
|
461 | + * Instala el módulo de usuarios en la base de datos para que pueda funcionar correctamete. |
|
462 | + * |
|
463 | + * @throws \RuntimeException si no se puede realizar la query |
|
464 | + */ |
|
465 | 465 | public function install() { |
466 | 466 | if(!$this->db->query(" |
467 | 467 | CREATE TABLE IF NOT EXISTS `users` ( |
@@ -482,16 +482,16 @@ discard block |
||
482 | 482 | } |
483 | 483 | |
484 | 484 | /** |
485 | - * __construct() |
|
486 | - */ |
|
485 | + * __construct() |
|
486 | + */ |
|
487 | 487 | public function __construct(IRouter $router = null) { |
488 | 488 | parent::__construct($router); |
489 | 489 | $this->startDBConexion(); |
490 | 490 | } |
491 | 491 | |
492 | 492 | /** |
493 | - * __destruct() |
|
494 | - */ |
|
493 | + * __destruct() |
|
494 | + */ |
|
495 | 495 | public function __destruct() { |
496 | 496 | parent::__destruct(); |
497 | 497 | $this->endDBConexion(); |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * @throws ModelsException cuando las contraseñas no coinciden |
74 | 74 | */ |
75 | 75 | private function checkPassMatch(string $pass, string $pass_repeat) { |
76 | - if($pass != $pass_repeat) { |
|
76 | + if ($pass != $pass_repeat) { |
|
77 | 77 | throw new ModelsException('Las contraseñas no coinciden.'); |
78 | 78 | } |
79 | 79 | } |
@@ -87,13 +87,13 @@ discard block |
||
87 | 87 | */ |
88 | 88 | private function checkEmail(string $email) { |
89 | 89 | # Formato de email |
90 | - if(!Strings::is_email($email)) { |
|
90 | + if (!Strings::is_email($email)) { |
|
91 | 91 | throw new ModelsException('El email no tiene un formato válido.'); |
92 | 92 | } |
93 | 93 | # Existencia de email |
94 | 94 | $email = $this->db->scape($email); |
95 | - $query = $this->db->select('id_user','users',"email='$email'",'LIMIT 1'); |
|
96 | - if(false !== $query) { |
|
95 | + $query = $this->db->select('id_user', 'users', "email='$email'", 'LIMIT 1'); |
|
96 | + if (false !== $query) { |
|
97 | 97 | throw new ModelsException('El email introducido ya existe.'); |
98 | 98 | } |
99 | 99 | } |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | * @return void |
108 | 108 | */ |
109 | 109 | private function restoreAttempts(string $email) { |
110 | - if(array_key_exists($email,$this->recentAttempts)) { |
|
110 | + if (array_key_exists($email, $this->recentAttempts)) { |
|
111 | 111 | $this->recentAttempts[$email]['attempts'] = 0; |
112 | 112 | $this->recentAttempts[$email]['time'] = null; |
113 | 113 | $this->updateSessionAttempts(); |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | private function generateSession(array $user_data) { |
128 | 128 | global $session, $config; |
129 | 129 | |
130 | - $session->set('user_id',(int) $user_data['id_user']); |
|
130 | + $session->set('user_id', (int) $user_data['id_user']); |
|
131 | 131 | $session->set('unique_session', $config['sessions']['unique']); |
132 | 132 | } |
133 | 133 | |
@@ -140,12 +140,12 @@ discard block |
||
140 | 140 | * @return bool true: Cuando el inicio de sesión es correcto |
141 | 141 | * false: Cuando el inicio de sesión no es correcto |
142 | 142 | */ |
143 | - private function authentication(string $email,string $pass) : bool { |
|
143 | + private function authentication(string $email, string $pass) : bool { |
|
144 | 144 | $email = $this->db->scape($email); |
145 | - $query = $this->db->select('id_user,pass','users',"email='$email'",'LIMIT 1'); |
|
145 | + $query = $this->db->select('id_user,pass', 'users', "email='$email'", 'LIMIT 1'); |
|
146 | 146 | |
147 | 147 | # Incio de sesión con éxito |
148 | - if(false !== $query && Strings::chash($query[0]['pass'],$pass)) { |
|
148 | + if (false !== $query && Strings::chash($query[0]['pass'], $pass)) { |
|
149 | 149 | |
150 | 150 | # Restaurar intentos |
151 | 151 | $this->restoreAttempts($email); |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | private function setDefaultAttempts() { |
167 | 167 | global $session; |
168 | 168 | |
169 | - if(null != $session->get('login_user_recentAttempts')) { |
|
169 | + if (null != $session->get('login_user_recentAttempts')) { |
|
170 | 170 | $this->recentAttempts = $session->get('login_user_recentAttempts'); |
171 | 171 | } |
172 | 172 | } |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | * @return void |
180 | 180 | */ |
181 | 181 | private function setNewAttempt(string $email) { |
182 | - if(!array_key_exists($email,$this->recentAttempts)) { |
|
182 | + if (!array_key_exists($email, $this->recentAttempts)) { |
|
183 | 183 | $this->recentAttempts[$email] = array( |
184 | 184 | 'attempts' => 0, # Intentos |
185 | 185 | 'time' => null # Tiempo |
@@ -200,14 +200,14 @@ discard block |
||
200 | 200 | * @return void |
201 | 201 | */ |
202 | 202 | private function maximumAttempts(string $email) { |
203 | - if($this->recentAttempts[$email]['attempts'] >= self::MAX_ATTEMPTS) { |
|
203 | + if ($this->recentAttempts[$email]['attempts'] >= self::MAX_ATTEMPTS) { |
|
204 | 204 | |
205 | 205 | # Colocar timestamp para recuperar más adelante la posibilidad de acceso |
206 | - if(null == $this->recentAttempts[$email]['time']) { |
|
206 | + if (null == $this->recentAttempts[$email]['time']) { |
|
207 | 207 | $this->recentAttempts[$email]['time'] = time() + self::MAX_ATTEMPTS_TIME; |
208 | 208 | } |
209 | 209 | |
210 | - if(time() < $this->recentAttempts[$email]['time']) { |
|
210 | + if (time() < $this->recentAttempts[$email]['time']) { |
|
211 | 211 | # Setear sesión |
212 | 212 | $this->updateSessionAttempts(); |
213 | 213 | # Lanzar excepción |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | $pass = $http->request->get('pass'); |
236 | 236 | |
237 | 237 | # Verificar que no están vacíos |
238 | - if($this->functions->e($email,$pass)) { |
|
238 | + if ($this->functions->e($email, $pass)) { |
|
239 | 239 | throw new ModelsException('Credenciales incompletas.'); |
240 | 240 | } |
241 | 241 | |
@@ -246,13 +246,13 @@ discard block |
||
246 | 246 | $this->maximumAttempts($email); |
247 | 247 | |
248 | 248 | # Autentificar |
249 | - if($this->authentication($email,$pass)) { |
|
249 | + if ($this->authentication($email, $pass)) { |
|
250 | 250 | return array('success' => 1, 'message' => 'Conectado con éxito.'); |
251 | 251 | } |
252 | 252 | |
253 | 253 | throw new ModelsException('Credenciales incorrectas.'); |
254 | 254 | |
255 | - } catch(ModelsException $e) { |
|
255 | + } catch (ModelsException $e) { |
|
256 | 256 | return array('success' => 0, 'message' => $e->getMessage()); |
257 | 257 | } |
258 | 258 | } |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | $pass_repeat = $http->request->get('pass_repeat'); |
274 | 274 | |
275 | 275 | # Verificar que no están vacíos |
276 | - if($this->functions->e($name,$email,$pass,$pass_repeat)) { |
|
276 | + if ($this->functions->e($name, $email, $pass, $pass_repeat)) { |
|
277 | 277 | throw new ModelsException('Todos los datos son necesarios'); |
278 | 278 | } |
279 | 279 | |
@@ -281,10 +281,10 @@ discard block |
||
281 | 281 | $this->checkEmail($email); |
282 | 282 | |
283 | 283 | # Veriricar contraseñas |
284 | - $this->checkPassMatch($pass,$pass_repeat); |
|
284 | + $this->checkPassMatch($pass, $pass_repeat); |
|
285 | 285 | |
286 | 286 | # Registrar al usuario |
287 | - $this->db->insert('users',array( |
|
287 | + $this->db->insert('users', array( |
|
288 | 288 | 'name' => $name, |
289 | 289 | 'email' => $email, |
290 | 290 | 'pass' => Strings::hash($pass) |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | )); |
297 | 297 | |
298 | 298 | return array('success' => 1, 'message' => 'Registrado con éxito.'); |
299 | - } catch(ModelsException $e) { |
|
299 | + } catch (ModelsException $e) { |
|
300 | 300 | return array('success' => 0, 'message' => $e->getMessage()); |
301 | 301 | } |
302 | 302 | } |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | $email = $http->request->get('email'); |
316 | 316 | |
317 | 317 | # Campo lleno |
318 | - if($this->functions->emp($email)) { |
|
318 | + if ($this->functions->emp($email)) { |
|
319 | 319 | throw new ModelsException('El campo email debe estar lleno.'); |
320 | 320 | } |
321 | 321 | |
@@ -323,10 +323,10 @@ discard block |
||
323 | 323 | $email = $this->db->scape($email); |
324 | 324 | |
325 | 325 | # Obtener información del usuario |
326 | - $user_data = $this->db->select('id_user,name','users',"email='$email'",'LIMIT 1'); |
|
326 | + $user_data = $this->db->select('id_user,name', 'users', "email='$email'", 'LIMIT 1'); |
|
327 | 327 | |
328 | 328 | # Verificar correo en base de datos |
329 | - if(false === $user_data) { |
|
329 | + if (false === $user_data) { |
|
330 | 330 | throw new ModelsException('El email no está registrado en el sistema.'); |
331 | 331 | } |
332 | 332 | |
@@ -335,29 +335,29 @@ discard block |
||
335 | 335 | $pass = uniqid(); |
336 | 336 | |
337 | 337 | # Construir mensaje y enviar mensaje |
338 | - $HTML = 'Hola <b>'. $user_data[0]['name'] .'</b>, ha solicitado recuperar su contraseña perdida, si no ha realizado esta acción no necesita hacer nada. |
|
338 | + $HTML = 'Hola <b>' . $user_data[0]['name'] . '</b>, ha solicitado recuperar su contraseña perdida, si no ha realizado esta acción no necesita hacer nada. |
|
339 | 339 | <br /> |
340 | 340 | <br /> |
341 | - Para cambiar su contraseña por <b>'. $pass .'</b> haga <a href="'. $config['site']['url'] . 'lostpass/cambiar/&token='.$token.'&user='.$user_data[0]['id_user'].'" target="_blank">clic aquí</a>.'; |
|
341 | + Para cambiar su contraseña por <b>'. $pass . '</b> haga <a href="' . $config['site']['url'] . 'lostpass/cambiar/&token=' . $token . '&user=' . $user_data[0]['id_user'] . '" target="_blank">clic aquí</a>.'; |
|
342 | 342 | |
343 | 343 | # Enviar el correo electrónico |
344 | 344 | $dest[$email] = $user_data[0]['name']; |
345 | - $email = Emails::send_mail($dest,Emails::plantilla($HTML),'Recuperar contraseña perdida'); |
|
345 | + $email = Emails::send_mail($dest, Emails::plantilla($HTML), 'Recuperar contraseña perdida'); |
|
346 | 346 | |
347 | 347 | # Verificar si hubo algún problema con el envío del correo |
348 | - if(false === $email) { |
|
348 | + if (false === $email) { |
|
349 | 349 | throw new ModelsException('No se ha podido enviar el correo electrónico.'); |
350 | 350 | } |
351 | 351 | |
352 | 352 | # Actualizar datos |
353 | 353 | $id_user = $user_data[0]['id_user']; |
354 | - $this->db->update('users',array( |
|
354 | + $this->db->update('users', array( |
|
355 | 355 | 'tmp_pass' => Strings::hash($pass), |
356 | 356 | 'token' => $token |
357 | - ),"id_user='$id_user'",'LIMIT 1'); |
|
357 | + ), "id_user='$id_user'", 'LIMIT 1'); |
|
358 | 358 | |
359 | 359 | return array('success' => 1, 'message' => 'Se ha enviado un enlace a su correo electrónico.'); |
360 | - } catch(ModelsException $e) { |
|
360 | + } catch (ModelsException $e) { |
|
361 | 361 | return array('success' => 0, 'message' => $e->getMessage()); |
362 | 362 | } |
363 | 363 | } |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | $id_user = $http->query->get('user'); |
381 | 381 | $token = $http->query->get('token'); |
382 | 382 | |
383 | - if(!$this->functions->emp($token) && is_numeric($id_user) && $id_user >= 1) { |
|
383 | + if (!$this->functions->emp($token) && is_numeric($id_user) && $id_user >= 1) { |
|
384 | 384 | # Filtros a los datos |
385 | 385 | $id_user = $this->db->scape($id_user); |
386 | 386 | $token = $this->db->scape($token); |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | public function logout() { |
404 | 404 | global $session; |
405 | 405 | |
406 | - if(null != $session->get('user_id')) { |
|
406 | + if (null != $session->get('user_id')) { |
|
407 | 407 | $session->remove('user_id'); |
408 | 408 | } |
409 | 409 | |
@@ -419,7 +419,7 @@ discard block |
||
419 | 419 | * @return false|array con información del usuario |
420 | 420 | */ |
421 | 421 | public function getUserById(int $id, string $select = '*') { |
422 | - return $this->db->select($select,'users',"id_user='$id'",'LIMIT 1'); |
|
422 | + return $this->db->select($select, 'users', "id_user='$id'", 'LIMIT 1'); |
|
423 | 423 | } |
424 | 424 | |
425 | 425 | /** |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | * @return false|array con información de los usuarios |
431 | 431 | */ |
432 | 432 | public function getUsers(string $select = '*') { |
433 | - return $this->db->select($select,'users'); |
|
433 | + return $this->db->select($select, 'users'); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | /** |
@@ -442,12 +442,12 @@ discard block |
||
442 | 442 | * @return array con datos del usuario conectado |
443 | 443 | */ |
444 | 444 | public function getOwnerUser(string $select = '*') : array { |
445 | - if(null != $this->id_user) { |
|
445 | + if (null != $this->id_user) { |
|
446 | 446 | |
447 | - $user = $this->db->select($select,'users',"id_user='$this->id_user'",'LIMIT 1'); |
|
447 | + $user = $this->db->select($select, 'users', "id_user='$this->id_user'", 'LIMIT 1'); |
|
448 | 448 | |
449 | 449 | # Si se borra al usuario desde la base de datos y sigue con la sesión activa |
450 | - if(false == $user) { |
|
450 | + if (false == $user) { |
|
451 | 451 | $this->logout(); |
452 | 452 | } |
453 | 453 | |
@@ -463,7 +463,7 @@ discard block |
||
463 | 463 | * @throws \RuntimeException si no se puede realizar la query |
464 | 464 | */ |
465 | 465 | public function install() { |
466 | - if(!$this->db->query(" |
|
466 | + if (!$this->db->query(" |
|
467 | 467 | CREATE TABLE IF NOT EXISTS `users` ( |
468 | 468 | `id_user` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, |
469 | 469 | `name` varchar(100) NOT NULL, |