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

RadioButton::editField()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 0
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
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 module for XOOPS
14
 *
15
 * @copyright   {@link http://sourceforge.net/projects/thmod/ The TXMod XOOPS Project}
16
 * @copyright   {@link http://sourceforge.net/projects/xoops/ The XOOPS Project}
17
 * @license     GPL 2.0 or later
18
 * @package     pedigree
19
 * @subpackage  class
20
 * @author      XOOPS Mod Development Team
21
 */
22
23
use XoopsModules\Pedigree;
24
25
/**
26
 * Class Pedigree\RadioButton
27
 */
28
29
/**
30
 * Class Pedigree\RadioButton
31
 */
32
class RadioButton extends Pedigree\HtmlInputAbstract
33
{
34
    // Define class variables
35
    private $fieldnumber;
36
    private $fieldname;
37
    private $value;
38
    private $defaultvalue;
39
    private $lookuptable;
40
41
    /**
42
     * Constructor
43
     *
44
     * @todo move hard coded language string to language file
45
     *
46
     * @param Pedigree\Field  $parentObject
47
     * @param Pedigree\Animal $animalObject
48
     */
49
    public function __construct(Pedigree\Field $parentObject, Pedigree\Animal $animalObject)
50
    {
51
        $this->fieldnumber  = $parentObject->getId();
52
        $this->fieldname    = $parentObject->fieldname;
53
        $this->value        = $animalObject->{'user' . $this->fieldnumber};
54
        $this->defaultvalue = $parentObject->defaultvalue;
55
        $this->lookuptable  = $parentObject->LookupTable;
0 ignored issues
show
Bug introduced by
The property LookupTable does not seem to exist on XoopsModules\Pedigree\Field.
Loading history...
56
        if (0 == $this->lookuptable) {
57
            echo "<span style='color: red;'><h3>A lookuptable must be specified for userfield" . $this->fieldnumber . '</h3></span>';
58
        }
59
    }
60
61
    /**
62
     * @return object {@see XoopsFormRadio}
63
     */
64
    public function editField()
65
    {
66
        $radio          = new \XoopsFormRadio('<b>' . $this->fieldname . '</b>', 'user' . $this->fieldnumber, $value = $this->value);
0 ignored issues
show
Bug introduced by
The type XoopsFormRadio 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...
67
        $lookupcontents = parent::lookupField($this->fieldnumber);
68
        $lcCount        = count($lookupcontents);
69
        for ($i = 0; $i < $lcCount; ++$i) {
70
            $radio->addOption($lookupcontents[$i]['id'], $lookupcontents[$i]['value']);
71
        }
72
73
        return $radio;
74
    }
75
76
    /**
77
     * @param string $name
78
     *
79
     * @return object {@see XoopsFormRadio)
80
     */
81
    public function newField($name = '')
82
    {
83
        $radio          = new \XoopsFormRadio('<b>' . $this->fieldname . '</b>', "{$name}user" . $this->fieldnumber, $value = $this->defaultvalue);
84
        $lookupcontents = parent::lookupField($this->fieldnumber);
85
        $lcCount        = count($lookupcontents);
86
        for ($i = 0; $i < $lcCount; ++$i) {
87
            $radio->addOption($lookupcontents[$i]['id'], $lookupcontents[$i]['value']);
88
        }
89
90
        return $radio;
91
    }
92
93
    /**
94
     * @return object {@see XoopsFormLabel}
95
     */
96
    public function viewField()
97
    {
98
        $lookupcontents = parent::lookupField($this->fieldnumber);
99
        $lcCount        = count($lookupcontents);
100
        for ($i = 0; $i < $lcCount; ++$i) {
101
            if ($lookupcontents[$i]['id'] == $this->value) {
102
                $choosenvalue = $lookupcontents[$i]['value'];
103
            }
104
        }
105
        $view = new \XoopsFormLabel($this->fieldname, $choosenvalue);
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...
Comprehensibility Best Practice introduced by
The variable $choosenvalue does not seem to be defined for all execution paths leading up to this point.
Loading history...
106
107
        return $view;
108
    }
109
110
    /**
111
     *
112
     * @todo error checking
113
     * @return string
114
     */
115
    public function showField()
116
    {
117
        $lookupcontents = parent::lookupField($this->fieldnumber);
118
        $lcCount        = count($lookupcontents);
119
        for ($i = 0; $i < $lcCount; ++$i) {
120
            if ($lookupcontents[$i]['id'] == $this->value) {
121
                $choosenvalue = $lookupcontents[$i]['value'];
122
            }
123
        }
124
125
        return $this->fieldname . ' : ' . $choosenvalue;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $choosenvalue does not seem to be defined for all execution paths leading up to this point.
Loading history...
126
    }
127
128
    /**
129
     * @return mixed
130
     */
131
    public function showValue()
132
    {
133
        $lookupcontents = parent::lookupField($this->fieldnumber);
134
        for ($i = 0, $iMax = count($lookupcontents); $i < $iMax; ++$i) {
135
            if ($lookupcontents[$i]['id'] == $this->value) {
136
                $choosenvalue = $lookupcontents[$i]['value'];
137
            }
138
        }
139
140
        return $choosenvalue;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $choosenvalue does not seem to be defined for all execution paths leading up to this point.
Loading history...
141
    }
142
143
    /**
144
     * @return string HTML <select> for this field
145
     */
146
    public function searchField()
147
    {
148
        $select         = "<select size='1' name='query' style='width: 140px;'>";
149
        $lookupcontents = parent::lookupField($this->fieldnumber);
150
        $lcCount        = count($lookupcontents);
151
        for ($i = 0; $i < $lcCount; ++$i) {
152
            $select .= "<option value='" . $lookupcontents[$i]['id'] . "'>" . $lookupcontents[$i]['value'] . '</option>';
153
        }
154
        $select .= '</select>';
155
156
        return $select;
157
    }
158
159
    /**
160
     *
161
     */
162
    public function getSearchString()
163
    {
164
    }
165
}
166