Passed
Push — scrutinizer-code-quality ( 09f5a1...c4c5fb )
by Adam
56:05 queued 14:08
created

AOR_Field::AOR_Field()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 1 Features 1
Metric Value
cc 2
eloc 7
c 1
b 1
f 1
nc 2
nop 0
dl 0
loc 10
ccs 0
cts 1
cp 0
crap 6
rs 9.4285
1
<?php
2
3
/**
4
 *
5
 * SugarCRM Community Edition is a customer relationship management program developed by
6
 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
7
 *
8
 * SuiteCRM is an extension to SugarCRM Community Edition developed by SalesAgility Ltd.
9
 * Copyright (C) 2011 - 2016 SalesAgility Ltd.
10
 *
11
 * This program is free software; you can redistribute it and/or modify it under
12
 * the terms of the GNU Affero General Public License version 3 as published by the
13
 * Free Software Foundation with the addition of the following permission added
14
 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
15
 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
16
 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
17
 *
18
 * This program is distributed in the hope that it will be useful, but WITHOUT
19
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20
 * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
21
 * details.
22
 *
23
 * You should have received a copy of the GNU Affero General Public License along with
24
 * this program; if not, see http://www.gnu.org/licenses or write to the Free
25
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26
 * 02110-1301 USA.
27
 *
28
 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
29
 * SW2-130, Cupertino, CA 95014, USA. or at email address [email protected].
30
 *
31
 * The interactive user interfaces in modified source and object code versions
32
 * of this program must display Appropriate Legal Notices, as required under
33
 * Section 5 of the GNU Affero General Public License version 3.
34
 *
35
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
36
 * these Appropriate Legal Notices must retain the display of the "Powered by
37
 * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
38
 * reasonably feasible for  technical reasons, the Appropriate Legal Notices must
39
 * display the words  "Powered by SugarCRM" and "Supercharged by SuiteCRM".
40
 */
41
class AOR_Field extends Basic
42
{
43
    var $new_schema = true;
44
    var $module_dir = 'AOR_Fields';
45
    var $object_name = 'AOR_Field';
46
    var $table_name = 'aor_fields';
47
    var $tracker_visibility = false;
48
    var $importable = true;
49
    var $disable_row_level_security = true;
50
51
    var $id;
52
    var $name;
53
    var $date_entered;
54
    var $date_modified;
55
    var $modified_user_id;
56
    var $modified_by_name;
57
    var $created_by;
58
    var $created_by_name;
59
    var $description;
60
    var $deleted;
61
    var $created_by_link;
62
    var $modified_user_link;
63
    var $field_order;
64
    var $field;
65
    var $display;
66
    var $label;
67
    var $field_function;
68
    var $sort_by;
69
    var $sort_order;
70
    var $group_by;
71
    var $group_order;
72
    var $group_display;
73
    var $aor_report_id;
74
75 13
    function __construct()
76
    {
77 13
        parent::__construct();
78 13
    }
79
80
    /**
81
     * @deprecated deprecated since version 7.6, PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code, use __construct instead
82
     */
83
    function AOR_Field(){
84
        $deprecatedMessage = 'PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code';
85
        if(isset($GLOBALS['log'])) {
86
            $GLOBALS['log']->deprecated($deprecatedMessage);
87
        }
88
        else {
89
            trigger_error($deprecatedMessage, E_USER_DEPRECATED);
90
        }
91
        self::__construct();
92
    }
93
94
95 2
    function save_lines($post_data, $parent, $key = '')
96
    {
97
98 2
        require_once('modules/AOW_WorkFlow/aow_utils.php');
99
100 2
        $line_count = count($post_data[$key . 'field']);
101 2
        for ($i = 0; $i < $line_count; ++$i) {
102
103 2
            if ($post_data[$key . 'deleted'][$i] == 1) {
104
                $this->mark_deleted($post_data[$key . 'id'][$i]);
105
            } else {
106 2
                $field = new AOR_Field();
107 2
                $field->group_display = false;
108
109 2
                if ($key == 'aor_fields_') {
110 1
                    foreach ($post_data['aor_fields_group_display'] as $gdKey => $gdValue) {
111 1
                        if ($gdValue == $i) {
112
                            $field->group_display = $gdKey + 1;
113 1
                            break;
114
                        }
115
                    }
116
                }
117
118 2
                foreach ($this->field_defs as $field_def) {
119 2
                    $field_name = $field_def['name'];
120 2
                    if (is_array($post_data[$key . $field_name])) {
121 2
                        if ($field_name != 'group_display' && isset($post_data[$key . $field_name][$i])) {
122 2
                            if (is_array($post_data[$key . $field_name][$i])) {
123
                                $post_data[$key . $field_name][$i] = base64_encode(serialize($post_data[$key . $field_name][$i]));
124 2
                            } else if ($field_name == 'value') {
125
                                $post_data[$key . $field_name][$i] = fixUpFormatting($_REQUEST['report_module'], $field->field, $post_data[$key . $field_name][$i]);
126
                            }
127 2
                            if ($field_name == 'module_path') {
128 2
                                $post_data[$key . $field_name][$i] = base64_encode(serialize(explode(":", $post_data[$key . $field_name][$i])));
129
                            }
130 2
                            $field->$field_name = $post_data[$key . $field_name][$i];
131
                        }
132 2
                    } else if (is_null($post_data[$key . $field_name])) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
133
                        // do nothing
134
                    } else {
135 2
                        throw new Exception('illegal type in post data at key ' . $key . $field_name . ' ' . gettype($post_data[$key . $field_name]));
136
                    }
137
138
                }
139 2
                if (trim($field->field) != '') {
140 2
                    $field->aor_report_id = $parent->id;
141 2
                    $field->save();
142
                }
143
            }
144
        }
145 2
    }
146
147
}