Field::isLocked()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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