Edit   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 77
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
B delegate() 0 51 4
1
<?php
2
3
/**
4
 * Pattern for edit action
5
 *
6
 * PHP Version 5
7
 *
8
 * @category  Core
9
 * @package   RAD
10
 * @author    Hans-Joachim Piepereit <[email protected]>
11
 * @copyright 2013 cSphere Team
12
 * @license   http://opensource.org/licenses/bsd-license Simplified BSD License
13
 * @link      http://www.csphere.eu
14
 **/
15
16
namespace csphere\core\rad;
17
18
/**
19
 * Pattern for edit action
20
 *
21
 * @category  Core
22
 * @package   RAD
23
 * @author    Hans-Joachim Piepereit <[email protected]>
24
 * @copyright 2013 cSphere Team
25
 * @license   http://opensource.org/licenses/bsd-license Simplified BSD License
26
 * @link      http://www.csphere.eu
27
 **/
28
29
class Edit extends \csphere\core\rad\Base
30
{
31
    /**
32
     * Action name
33
     **/
34
    protected $action = 'edit';
35
36
    /**
37
     * Template file name
38
     **/
39
    protected $tpl = 'form';
40
41
    /**
42
     * Previous action
43
     **/
44
    protected $previous = 'manage';
45
46
    /**
47
     * Delegate action to run this method
48
     *
49
     * @param integer $rid Record ID if not part of URL
50
     *
51
     * @return void
52
     **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
53
54
    public function delegate($rid = 0)
55
    {
56
        // Get record ID and check for post data
57
        $record  = (int)$rid;
58
        $use_rid = 0;
59
60
        if (empty($rid)) {
61
62
            $record  = (int)\csphere\core\http\Input::get('get', 'id');
63
            $use_rid = $record;
64
        }
65
66
        $post = \csphere\core\http\Input::getAll('post');
67
68
        // Get table model
69
        $dm_table = new \csphere\core\datamapper\Model($this->plugin, $this->table);
70
        $table    = $dm_table->read($record);
71
72
        // Check if record exists
73
        if ($table == []) {
74
75
            $this->message('no_record_found', $use_rid, 'red');
76
77
        } else {
78
79
            // Handle save requests
80
            if (isset($post['csphere_form'])) {
81
82
                // Fill post data into record
83
                $table = $this->form($table, $post);
84
85
                // Get data with record serial
86
                $serial         = $dm_table->serial();
87
                $table[$serial] = $record;
88
89
                $dm_table->update($table);
90
91
                $this->message('record_success', $use_rid, 'green');
92
93
            } else {
94
95
                // Data array
96
                $data = [];
97
98
                $data[$this->schema] = $table;
99
100
                // Send data to view
101
                $this->view($data, $use_rid);
102
            }
103
        }
104
    }
105
}
106