Passed
Push — master ( b847d6...d6d54c )
by Michael
09:34 queued 05:00
created

RadioButton::searchField()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 0
dl 0
loc 11
rs 10
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;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, XoopsModules\Pedigree\Pedigree. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
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;
0 ignored issues
show
Bug introduced by
The property fieldname does not seem to exist on XoopsModules\Pedigree\Field.
Loading history...
53
        $this->value        = $animalObject->{'user' . $this->fieldnumber};
54
        $this->defaultvalue = $parentObject->defaultvalue;
0 ignored issues
show
Bug introduced by
The property defaultvalue does not seem to exist on XoopsModules\Pedigree\Field.
Loading history...
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);
67
        $lookupcontents = parent::lookupField($this->fieldnumber);
68
        $lcCount        = count($lookupcontents);
0 ignored issues
show
Unused Code introduced by
The assignment to $lcCount is dead and can be removed.
Loading history...
69
        foreach ($lookupcontents as $i => $iValue) {
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);
0 ignored issues
show
Unused Code introduced by
The assignment to $lcCount is dead and can be removed.
Loading history...
86
        foreach ($lookupcontents as $i => $iValue) {
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);
0 ignored issues
show
Unused Code introduced by
The assignment to $lcCount is dead and can be removed.
Loading history...
100
        foreach ($lookupcontents as $i => $iValue) {
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
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);
0 ignored issues
show
Unused Code introduced by
The assignment to $lcCount is dead and can be removed.
Loading history...
119
        foreach ($lookupcontents as $i => $iValue) {
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
        foreach ($lookupcontents as $i => $iValue) {
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);
0 ignored issues
show
Unused Code introduced by
The assignment to $lcCount is dead and can be removed.
Loading history...
151
        foreach ($lookupcontents as $i => $iValue) {
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