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 | * 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; |
||
| 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); |
||
| 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); |
||
| 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); |
||
| 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); |
||
| 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 | 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; |
||
| 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; |
||
| 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 | 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 |
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: