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

SelectBox   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 132
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 54
dl 0
loc 132
rs 10
c 0
b 0
f 0
wmc 18

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getSearchString() 0 3 1
A showField() 0 12 3
A searchField() 0 11 2
A newField() 0 10 2
A showValue() 0 12 3
A __construct() 0 9 2
A viewField() 0 12 3
A editField() 0 10 2
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
/**
27
 * Class Pedigree\SelectBox
28
 */
29
class SelectBox extends Pedigree\HtmlInputAbstract
30
{
31
    // Define class variables
32
    private $fieldnumber;
33
    private $fieldname;
34
    private $value;
35
    private $defaultvalue;
36
    private $lookuptable;
37
38
    /**
39
     * Constructor
40
     *
41
     * @param Pedigree\Field  $parentObject
42
     * @param Pedigree\Animal $animalObject
43
     */
44
    public function __construct(Pedigree\Field $parentObject, Pedigree\Animal $animalObject)
45
    {
46
        $this->fieldnumber  = $parentObject->getId();
47
        $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...
48
        $this->value        = $animalObject->{'user' . $this->fieldnumber};
49
        $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...
50
        $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...
51
        if (0 == $this->lookuptable) {
52
            echo "<span style='color: red;'><h3>A lookuptable must be specified for userfield" . $this->fieldnumber . '</h3></span>';
53
        }
54
    }
55
56
    /**
57
     * @return \XoopsFormSelect
58
     */
59
    public function editField()
60
    {
61
        $select         = new \XoopsFormSelect('<b>' . $this->fieldname . '</b>', 'user' . $this->fieldnumber, $value = $this->value, $size = 1, $multiple = false);
62
        $lookupcontents = parent::lookupField($this->fieldnumber);
63
        $lcCount        = count($lookupcontents);
0 ignored issues
show
Unused Code introduced by
The assignment to $lcCount is dead and can be removed.
Loading history...
64
        foreach ($lookupcontents as $i => $iValue) {
65
            $select->addOption($lookupcontents[$i]['id'], $lookupcontents[$i]['value']);
66
        }
67
68
        return $select;
69
    }
70
71
    /**
72
     * @param string $name
73
     *
74
     * @return \XoopsFormSelect
75
     */
76
    public function newField($name = '')
77
    {
78
        $select         = new \XoopsFormSelect('<b>' . $this->fieldname . '</b>', $name . 'user' . $this->fieldnumber, $value = $this->defaultvalue, $size = 1, $multiple = false);
79
        $lookupcontents = parent::lookupField($this->fieldnumber);
80
        $lcCount        = count($lookupcontents);
0 ignored issues
show
Unused Code introduced by
The assignment to $lcCount is dead and can be removed.
Loading history...
81
        foreach ($lookupcontents as $i => $iValue) {
82
            $select->addOption($lookupcontents[$i]['id'], $lookupcontents[$i]['value']);
83
        }
84
85
        return $select;
86
    }
87
88
    /**
89
     * @return \XoopsFormLabel
90
     */
91
    public function viewField()
92
    {
93
        $lookupcontents = parent::lookupField($this->fieldnumber);
94
        $lcCount        = count($lookupcontents);
0 ignored issues
show
Unused Code introduced by
The assignment to $lcCount is dead and can be removed.
Loading history...
95
        foreach ($lookupcontents as $i => $iValue) {
96
            if ($lookupcontents[$i]['id'] == $this->value) {
97
                $choosenvalue = $lookupcontents[$i]['value'];
98
            }
99
        }
100
        $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...
101
102
        return $view;
103
    }
104
105
    /**
106
     * @return string
107
     */
108
    public function showField()
109
    {
110
        $choosenvalue   = '';
111
        $lookupcontents = parent::lookupField($this->fieldnumber);
112
        $lcCount        = count($lookupcontents);
0 ignored issues
show
Unused Code introduced by
The assignment to $lcCount is dead and can be removed.
Loading history...
113
        foreach ($lookupcontents as $i => $iValue) {
114
            if ($lookupcontents[$i]['id'] == $this->value) {
115
                $choosenvalue = $lookupcontents[$i]['value'];
116
            }
117
        }
118
119
        return $this->fieldname . ' : ' . $choosenvalue;
120
    }
121
122
    /**
123
     * @return string
124
     */
125
    public function showValue()
126
    {
127
        $choosenvalue   = '';
128
        $lookupcontents = parent::lookupField($this->fieldnumber);
129
        $lcCount        = count($lookupcontents);
0 ignored issues
show
Unused Code introduced by
The assignment to $lcCount is dead and can be removed.
Loading history...
130
        foreach ($lookupcontents as $i => $iValue) {
131
            if ($lookupcontents[$i]['id'] == $this->value) {
132
                $choosenvalue = $lookupcontents[$i]['value'];
133
            }
134
        }
135
136
        return $choosenvalue;
137
    }
138
139
    /**
140
     * @return string HTML <select> for this field
141
     */
142
    public function searchField()
143
    {
144
        $select         = "<select size='1' name='query' style='width: 140px;'>";
145
        $lookupcontents = parent::lookupField($this->fieldnumber);
146
        $lcCount        = count($lookupcontents);
0 ignored issues
show
Unused Code introduced by
The assignment to $lcCount is dead and can be removed.
Loading history...
147
        foreach ($lookupcontents as $i => $iValue) {
148
            $select .= "<option value='" . $lookupcontents[$i]['id'] . "'>" . $lookupcontents[$i]['value'] . '</option>';
149
        }
150
        $select .= '</select>';
151
152
        return $select;
153
    }
154
155
    /**
156
     *
157
     */
158
    public function getSearchString()
159
    {
160
        return null;
161
    }
162
}
163