1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/* |
3
|
|
|
You may not change or alter any portion of this comment or credits |
4
|
|
|
of supporting developers from this source code or any supporting source code |
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
6
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
10
|
|
|
*/ |
11
|
|
|
/** |
12
|
|
|
* Pedigree module for XOOPS |
13
|
|
|
* |
14
|
|
|
* @copyright {@link http://sourceforge.net/projects/thmod/ The TXMod XOOPS Project} |
15
|
|
|
* @copyright {@link http://sourceforge.net/projects/xoops/ The XOOPS Project} |
16
|
|
|
* @license GPL 2.0 or later |
17
|
|
|
* @package pedigree |
18
|
|
|
* @subpackage class |
19
|
|
|
* @author XOOPS Mod Development Team |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
require_once __DIR__ . '/htmlinput.abstract.php'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Class PedigreeSelectBox |
26
|
|
|
*/ |
27
|
|
|
class PedigreeSelectBox extends PedigreeHtmlInputAbstract |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
// Define class variables |
30
|
|
|
private $fieldnumber; |
31
|
|
|
private $fieldname; |
32
|
|
|
private $value; |
33
|
|
|
private $defaultvalue; |
34
|
|
|
private $lookuptable; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Constructor |
38
|
|
|
* |
39
|
|
|
* @param $parentObject |
40
|
|
|
* @param $animalObject |
41
|
|
|
*/ |
42
|
|
View Code Duplication |
public function __construct($parentObject, $animalObject) |
|
|
|
|
43
|
|
|
{ |
44
|
|
|
$this->fieldnumber = $parentObject->getId(); |
45
|
|
|
$this->fieldname = $parentObject->fieldname; |
46
|
|
|
$this->value = $animalObject->{'user' . $this->fieldnumber}; |
47
|
|
|
$this->defaultvalue = $parentObject->defaultvalue; |
48
|
|
|
$this->lookuptable = $parentObject->lookuptable; |
49
|
|
|
if (0 == $this->lookuptable) { |
50
|
|
|
echo "<span style='color: red;'><h3>A lookuptable must be specified for userfield" . $this->fieldnumber . '</h3></span>'; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return XoopsFormSelect |
56
|
|
|
*/ |
57
|
|
View Code Duplication |
public function editField() |
|
|
|
|
58
|
|
|
{ |
59
|
|
|
$select = new XoopsFormSelect('<b>' . $this->fieldname . '</b>', 'user' . $this->fieldnumber, $value = $this->value, $size = 1, $multiple = false); |
60
|
|
|
$lookupcontents = parent::lookupField($this->fieldnumber); |
|
|
|
|
61
|
|
|
$lcCount = count($lookupcontents); |
62
|
|
|
for ($i = 0; $i < $lcCount; ++$i) { |
63
|
|
|
$select->addOption($lookupcontents[$i]['id'], $lookupcontents[$i]['value']); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return $select; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param string $name |
71
|
|
|
* |
72
|
|
|
* @return XoopsFormSelect |
73
|
|
|
*/ |
74
|
|
View Code Duplication |
public function newField($name = '') |
|
|
|
|
75
|
|
|
{ |
76
|
|
|
$select = new XoopsFormSelect('<b>' . $this->fieldname . '</b>', $name . 'user' . $this->fieldnumber, $value = $this->defaultvalue, $size = 1, $multiple = false); |
77
|
|
|
$lookupcontents = parent::lookupField($this->fieldnumber); |
|
|
|
|
78
|
|
|
$lcCount = count($lookupcontents); |
79
|
|
|
for ($i = 0; $i < $lcCount; ++$i) { |
80
|
|
|
$select->addOption($lookupcontents[$i]['id'], $lookupcontents[$i]['value']); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return $select; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return XoopsFormLabel |
88
|
|
|
*/ |
89
|
|
|
public function viewField() |
90
|
|
|
{ |
91
|
|
|
$lookupcontents = parent::lookupField($this->fieldnumber); |
|
|
|
|
92
|
|
|
$lcCount = count($lookupcontents); |
93
|
|
|
for ($i = 0; $i < $lcCount; ++$i) { |
94
|
|
|
if ($lookupcontents[$i]['id'] == $this->value) { |
95
|
|
|
$choosenvalue = $lookupcontents[$i]['value']; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
$view = new XoopsFormLabel($this->fieldname, $choosenvalue); |
|
|
|
|
99
|
|
|
|
100
|
|
|
return $view; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @return string |
105
|
|
|
*/ |
106
|
|
View Code Duplication |
public function showField() |
|
|
|
|
107
|
|
|
{ |
108
|
|
|
$choosenvalue = ''; |
109
|
|
|
$lookupcontents = parent::lookupField($this->fieldnumber); |
|
|
|
|
110
|
|
|
$lcCount = count($lookupcontents); |
111
|
|
|
for ($i = 0; $i < $lcCount; ++$i) { |
112
|
|
|
if ($lookupcontents[$i]['id'] == $this->value) { |
113
|
|
|
$choosenvalue = $lookupcontents[$i]['value']; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
return $this->fieldname . ' : ' . $choosenvalue; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @return string |
122
|
|
|
*/ |
123
|
|
View Code Duplication |
public function showValue() |
|
|
|
|
124
|
|
|
{ |
125
|
|
|
$choosenvalue = ''; |
126
|
|
|
$lookupcontents = parent::lookupField($this->fieldnumber); |
|
|
|
|
127
|
|
|
$lcCount = count($lookupcontents); |
128
|
|
|
for ($i = 0; $i < $lcCount; ++$i) { |
129
|
|
|
if ($lookupcontents[$i]['id'] == $this->value) { |
130
|
|
|
$choosenvalue = $lookupcontents[$i]['value']; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
return $choosenvalue; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @return string HTML <select> for this field |
139
|
|
|
*/ |
140
|
|
View Code Duplication |
public function searchField() |
|
|
|
|
141
|
|
|
{ |
142
|
|
|
$select = "<select size='1' name='query' style='width: 140px;'>"; |
143
|
|
|
$lookupcontents = parent::lookupField($this->fieldnumber); |
|
|
|
|
144
|
|
|
$lcCount = count($lookupcontents); |
145
|
|
|
for ($i = 0; $i < $lcCount; ++$i) { |
146
|
|
|
$select .= "<option value='" . $lookupcontents[$i]['id'] . "'>" . $lookupcontents[$i]['value'] . '</option>'; |
147
|
|
|
} |
148
|
|
|
$select .= '</select>'; |
149
|
|
|
|
150
|
|
|
return $select; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* |
155
|
|
|
*/ |
156
|
|
|
public function getSearchString() |
157
|
|
|
{ |
158
|
|
|
return; |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.