Passed
Branch master (48d769)
by Michael
02:30
created

Field   A

Complexity

Total Complexity 33

Size/Duplication

Total Lines 180
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 180
rs 9.3999
c 0
b 0
f 0
wmc 33

19 Methods

Rating   Name   Duplication   Size   Complexity  
A hasLookup() 0 3 2
A inPie() 0 3 2
A hasSearch() 0 3 2
A searchField() 0 3 1
A getSearchString() 0 3 1
A getSetting() 0 3 1
A isLocked() 0 3 2
A showField() 0 3 1
A inPedigree() 0 3 2
A showValue() 0 5 1
A lookupField() 0 12 2
A addLitter() 0 3 2
A viewField() 0 5 1
A __construct() 0 13 4
A inAdvanced() 0 3 2
A isActive() 0 3 2
A inList() 0 3 2
A generalLitter() 0 3 2
A getId() 0 3 1
1
<?php namespace XoopsModules\Pedigree;
2
3
/*
4
 You may not change or alter any portion of this comment or credits
5
 of supporting developers from this source code or any supporting source code
6
 which is considered copyrighted (c) material of the original comment or credit authors.
7
8
 This program is distributed in the hope that it will be useful,
9
 but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
/**
13
 * Pedigree\Breadcrumb Class
14
 *
15
 * @copyright   {@link https://xoops.org/ XOOPS Project}
16
 * @license     {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
17
 * @author      lucio <[email protected]>
18
 * @package     Pedigree
19
 * @since       1.31
20
 *
21
 */
22
23
use XoopsModules\Pedigree;
24
25
26
/**
27
 * Class Field
28
 */
29
class Field
30
{
31
    protected $id;
32
33
    /**
34
     * @param $fieldnumber
35
     * @param $config
36
     */
37
    public function __construct($fieldnumber, $config)
38
    {
39
        //find key where id = $fieldnumber;
40
        $configCount = count($config);
41
        for ($x = 0; $x < $configCount; ++$x) {
42
            //@todo - figure out if this is suppose to be an assignment or just a compare ('=' or '==')
43
            if ($config[$x]['id'] = $fieldnumber) {
44
                foreach ($config[$x] as $key => $value) {
45
                    $this->$key = $value;
46
                }
47
            }
48
        }
49
        $this->id = $fieldnumber;
50
    }
51
52
    /**
53
     * @return bool
54
     */
55
    public function isActive()
56
    {
57
        return ('1' == $this->getSetting('isactive')) ? true : false;
58
    }
59
60
    /**
61
     * @return bool
62
     */
63
    public function inAdvanced()
64
    {
65
        return ('1' == $this->getSetting('viewinadvanced')) ? true : false;
66
    }
67
68
    /**
69
     * @return bool
70
     */
71
    public function isLocked()
72
    {
73
        return ('1' == $this->getSetting('locked')) ? true : false;
74
    }
75
76
    /**
77
     * @return bool
78
     */
79
    public function hasSearch()
80
    {
81
        return ('1' == $this->getSetting('hassearch')) ? true : false;
82
    }
83
84
    /**
85
     * @return bool
86
     */
87
    public function addLitter()
88
    {
89
        return ('1' == $this->getSetting('litter')) ? true : false;
90
    }
91
92
    /**
93
     * @return bool
94
     */
95
    public function generalLitter()
96
    {
97
        return ('1' == $this->getSetting('generallitter')) ? true : false;
98
    }
99
100
    /**
101
     * @return bool
102
     */
103
    public function hasLookup()
104
    {
105
        return ('1' == $this->getSetting('lookuptable')) ? true : false;
106
    }
107
108
    /**
109
     * @return string
110
     */
111
    public function getSearchString()
112
    {
113
        return '&amp;o=naam&amp;p';
114
    }
115
116
    /**
117
     * @return bool
118
     */
119
    public function inPie()
120
    {
121
        return ('1' == $this->getSetting('viewinpie')) ? true : false;
122
    }
123
124
    /**
125
     * @return bool
126
     */
127
    public function inPedigree()
128
    {
129
        return ('1' == $this->getSetting('viewinpedigree')) ? true : false;
130
    }
131
132
    /**
133
     * @return bool
134
     */
135
    public function inList()
136
    {
137
        return ('1' == $this->getSetting('viewinlist')) ? true : false;
138
    }
139
140
    public function getId()
141
    {
142
        return $this->id;
143
    }
144
145
    /**
146
     * @param $setting
147
     *
148
     * @return mixed
149
     */
150
    public function getSetting($setting)
151
    {
152
        return $this->{$setting};
153
    }
154
155
    /**
156
     * @param $fieldnumber
157
     *
158
     * @return array
159
     */
160
    public function lookupField($fieldnumber)
161
    {
162
        $ret = [];
163
        global $xoopsDB;
164
        $SQL    = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix("pedigree_lookup{$fieldnumber}") . " ORDER BY 'order'";
165
        $result = $GLOBALS['xoopsDB']->query($SQL);
166
        while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
167
            $ret[] = ['id' => $row['id'], 'value' => $row['value']];
168
        }
169
170
        //array_multisort($ret,SORT_ASC);
171
        return $ret;
172
    }
173
174
    /**
175
     * @return \XoopsFormLabel
176
     */
177
    public function viewField()
178
    {
179
        $view = new \XoopsFormLabel($this->fieldname, $this->value);
0 ignored issues
show
Bug introduced by
The type XoopsFormLabel was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
180
181
        return $view;
182
    }
183
184
    /**
185
     * @return string
186
     */
187
    public function showField()
188
    {
189
        return $this->fieldname . ' : ' . $this->value;
190
    }
191
192
    /**
193
     * @return mixed|string
194
     */
195
    public function showValue()
196
    {
197
        global $myts;
198
199
        return $myts->displayTarea($this->value);
200
        //return $this->value;
201
    }
202
203
    /**
204
     * @return string
205
     */
206
    public function searchField()
207
    {
208
        return '<input type="text" name="query" size="20">';
209
    }
210
}
211