mambax7 /
pedigree
| 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
|
|||
| 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; |
||
| 48 | $this->value = $animalObject->{'user' . $this->fieldnumber}; |
||
| 49 | $this->defaultvalue = $parentObject->defaultvalue; |
||
| 50 | $this->lookuptable = $parentObject->lookuptable; |
||
| 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); |
||
| 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); |
||
| 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); |
||
| 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); |
||
| 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); |
||
| 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); |
||
| 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); |
||
| 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 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare 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.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/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: