ScaffoldController::editar()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 19

Duplication

Lines 10
Ratio 52.63 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 1
dl 10
loc 19
rs 9.6333
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Controlador base para la construcción de CRUD para modelos rápidamente
5
 *
6
 * @category Kumbia
7
 * @package Controller
8
 */
9
class ScaffoldController extends AdminController
10
{
11
    /** @var string Carpeta en views/_shared/scaffolds/ */
12
    public $scaffold = 'kumbia';
13
    /** @var string Nombre del modelo en CamelCase */
14
    public $model = '';
15
16
    /**
17
     * Resultados paginados
18
     */
19
    public function index($page = 1)
20
    {
21
        $this->data = (new $this->model)->paginate("page: $page", 'order: id desc');
22
    }
23
24
    /**
25
     * Crea un Registro
26
     */
27
    public function crear()
28
    {
29 View Code Duplication
        if (Input::hasPost($this->model)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
30
31
            $obj = new $this->model;
32
            //En caso que falle la operación de guardar
33
            if (!$obj->save(Input::post($this->model))) {
34
                Flash::error('Falló Operación');
35
                //se hacen persistente los datos en el formulario
36
                $this->{$this->model} = $obj;
37
                return;
38
            }
39
            return Redirect::to();
40
        }
41
        // Sólo es necesario para el autoForm
42
        $this->{$this->model} = new $this->model;
43
    }
44
45
    /**
46
     * Edita un Registro
47
     */
48
    public function editar($id)
49
    {
50
        View::select('crear');
51
52
        //se verifica si se ha enviado via POST los datos
53 View Code Duplication
        if (Input::hasPost($this->model)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54
            $obj = new $this->model;
55
            if (!$obj->update(Input::post($this->model))) {
56
                Flash::error('Falló Operación');
57
                //se hacen persistente los datos en el formulario
58
                $this->{$this->model} = Input::post($this->model);
59
            } else {
60
                return Redirect::to();
61
            }
62
        }
63
64
        //Aplicando la autocarga de objeto, para comenzar la edición
65
        $this->{$this->model} = (new $this->model)->find((int) $id);
66
    }
67
68
    /**
69
     * Borra un Registro
70
     */
71
    public function borrar($id)
72
    {
73
        if (!(new $this->model)->delete((int) $id)) {
74
            Flash::error('Falló Operación');
75
        }
76
        //enrutando al index para listar los articulos
77
        Redirect::to();
78
    }
79
80
    /**
81
     * Ver un Registro
82
     */
83
    public function ver($id)
84
    {
85
        $this->data = (new $this->model)->find_first((int) $id);
86
    }
87
}