1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Controlador para las acciones y vistas con el usuario |
5
|
|
|
*/ |
6
|
|
|
class UserController extends AppController |
7
|
|
|
{ |
8
|
|
|
|
9
|
|
|
public function index() |
10
|
|
|
{ |
11
|
|
|
$this->data = (new User)->find(); |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
public function create() |
15
|
|
|
{ |
16
|
|
|
//se verifica si se ha enviado via POST los datos |
17
|
|
|
if (Input::hasPost('user')) { |
18
|
|
|
$obj = new User; |
19
|
|
|
//Intenta guardar el usuario junto con la foto |
20
|
|
|
if ($obj->saveWithPhoto(Input::post('user'))) { |
21
|
|
|
//Mensaje de éxito y retorna al listado |
22
|
|
|
Flash::valid('Usuario creado'); |
23
|
|
|
return Redirect::to(); |
|
|
|
|
24
|
|
|
} |
25
|
|
|
//Si falla se hacen persistentes los datos en el formulario |
26
|
|
|
$this->data = Input::post('user'); |
27
|
|
|
return; |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
|
31
|
|
View Code Duplication |
public function edit(int $id)//validación 'int' con php7 |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
//Carga los datos del usuario |
34
|
|
|
$this->user = (new User)->find($id); |
|
|
|
|
35
|
|
|
//se verifica si se ha enviado via POST los datos |
36
|
|
|
if (Input::hasPost('user')) { |
37
|
|
|
//Intenta guardar los cambios |
38
|
|
|
if ($this->user->update(Input::post('user'))) { |
39
|
|
|
//Mensaje de éxito y retorna al listado |
40
|
|
|
Flash::valid('Usuario actualizado'); |
41
|
|
|
return Redirect::to(); |
|
|
|
|
42
|
|
|
} |
43
|
|
|
//Si falla se hacen persistentes los datos en el formulario |
44
|
|
|
$this->user = Input::post('user'); |
45
|
|
|
return; |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
View Code Duplication |
public function update_photo(int $id)//validación 'int' con php7 |
|
|
|
|
50
|
|
|
{ |
51
|
|
|
//Carga los datos del usuario |
52
|
|
|
$this->user = (new User)->find($id); |
|
|
|
|
53
|
|
|
//se verifica si se ha enviado via POST los datos |
54
|
|
|
if (Input::hasPost('user')) { |
55
|
|
|
//Si falla al intentar actualizar |
56
|
|
|
if ($this->user->updatePhoto()) { |
|
|
|
|
57
|
|
|
//Mensaje de éxito y retorna al listado |
58
|
|
|
Flash::valid('Foto de usuario actualizada'); |
59
|
|
|
return Redirect::to(); |
|
|
|
|
60
|
|
|
} |
61
|
|
|
//se hacen persistentes los datos en el formulario |
62
|
|
|
$this->user = Input::post('user'); |
63
|
|
|
return; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.