Passed
Push — master ( 48d769...5ccf6e )
by Michael
07:14
created

class/Field.php (6 issues)

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);
0 ignored issues
show
The assignment to $configCount is dead and can be removed.
Loading history...
41
        foreach ($config as $x => $xValue) {
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');
58
    }
59
60
    /**
61
     * @return bool
62
     */
63
    public function inAdvanced()
64
    {
65
        return '1' == $this->getSetting('viewinadvanced');
66
    }
67
68
    /**
69
     * @return bool
70
     */
71
    public function isLocked()
72
    {
73
        return '1' == $this->getSetting('locked');
74
    }
75
76
    /**
77
     * @return bool
78
     */
79
    public function hasSearch()
80
    {
81
        return '1' == $this->getSetting('hassearch');
82
    }
83
84
    /**
85
     * @return bool
86
     */
87
    public function addLitter()
88
    {
89
        return '1' == $this->getSetting('litter');
90
    }
91
92
    /**
93
     * @return bool
94
     */
95
    public function generalLitter()
96
    {
97
        return ('1' == $this->getSetting('generallitter'));
98
    }
99
100
    /**
101
     * @return bool
102
     */
103
    public function hasLookup()
104
    {
105
        return ('1' == $this->getSetting('lookuptable'));
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'));
122
    }
123
124
    /**
125
     * @return bool
126
     */
127
    public function inPedigree()
128
    {
129
        return ('1' == $this->getSetting('viewinpedigree'));
130
    }
131
132
    /**
133
     * @return bool
134
     */
135
    public function inList()
136
    {
137
        return '1' == $this->getSetting('viewinlist');
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 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...
180
181
        return $view;
182
    }
183
184
    /**
185
     * @return string
186
     */
187
    public function showField()
188
    {
189
        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...
190
    }
191
192
    /**
193
     * @return mixed|string
194
     */
195
    public function showValue()
196
    {
197
        global $myts;
198
199
        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...
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