Conditions | 13 |
Paths | 98 |
Total Lines | 95 |
Code Lines | 69 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
84 | function edit($id = 0) |
||
85 | { |
||
86 | global $xoopsTpl, $xoopsDB, $moduleConfig; |
||
87 | if (isset($_GET['id'])) { |
||
88 | $id = $_GET['id']; |
||
89 | } |
||
90 | include XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
91 | |||
92 | $sql = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' WHERE id=' . $id; |
||
93 | $result = $GLOBALS['xoopsDB']->query($sql); |
||
94 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
95 | $form = new \XoopsThemeForm('Edit ' . $row['naam'], 'dogname', 'edit.php?f=save', 'post', true); |
||
96 | $form->addElement(new \XoopsFormHiddenToken($name = 'XOOPS_TOKEN_REQUEST', $timeout = 360)); |
||
97 | $form->addElement(new \XoopsFormHidden('id', $id)); |
||
98 | //name |
||
99 | $naam = htmlentities(stripslashes($row['naam']), ENT_QUOTES); |
||
100 | $form->addElement(new \XoopsFormText('<b>' . _MA_PEDIGREE_FLD_NAME . '</b>', 'naam', $size = 50, $maxsize = 255, $value = $naam)); |
||
101 | //gender |
||
102 | $roft = $row['roft']; |
||
103 | $gender_radio = new \XoopsFormRadio('<b>' . _MA_PEDIGREE_FLD_GEND . '</b>', 'roft', $value = $roft); |
||
104 | $gender_radio->addOptionArray([ |
||
105 | '0' => strtr(_MA_PEDIGREE_FLD_MALE, ['[male]' => $moduleConfig['male']]), |
||
106 | '1' => strtr(_MA_PEDIGREE_FLD_FEMA, ['[female]' => $moduleConfig['female']]), |
||
107 | ]); |
||
108 | $form->addElement($gender_radio); |
||
109 | //father |
||
110 | $sql = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE id='" . $row['father'] . "'"; |
||
111 | $resfather = $GLOBALS['xoopsDB']->query($sql); |
||
112 | $numfields = $GLOBALS['xoopsDB']->getRowsNum($resfather); |
||
113 | if ('0' == !$numfields) { |
||
114 | while (false !== ($rowfetch = $GLOBALS['xoopsDB']->fetchArray($resfather))) { |
||
115 | $form->addElement(new \XoopsFormLabel('<b>' . strtr(_MA_PEDIGREE_FLD_FATH, ['[father]' => $moduleConfig['father']]) . '</b>', '<img src="assets/images/male.gif"><a href="seldog.php?curval=' . $row['id'] . '&gend=0&letter=a">' . $rowfetch['naam'] . '</a>')); |
||
116 | } |
||
117 | } else { |
||
118 | $form->addElement(new \XoopsFormLabel('<b>' . strtr(_MA_PEDIGREE_FLD_FATH, ['[father]' => $moduleConfig['father']]) . '</b>', '<img src="assets/images/male.gif"><a href="seldog.php?curval=' . $row['id'] . '&gend=0&letter=a">Unknown</a>')); |
||
119 | } |
||
120 | //mother |
||
121 | $sql = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE id='" . $row['mother'] . "'"; |
||
122 | $resmother = $GLOBALS['xoopsDB']->query($sql); |
||
123 | $numfields = $GLOBALS['xoopsDB']->getRowsNum($resmother); |
||
124 | if ('0' == !$numfields) { |
||
125 | while (false !== ($rowfetch = $GLOBALS['xoopsDB']->fetchArray($resmother))) { |
||
126 | $form->addElement(new \XoopsFormLabel('<b>' . strtr(_MA_PEDIGREE_FLD_MOTH, ['[mother]' => $moduleConfig['mother']]) . '</b>', '<img src="assets/images/female.gif"><a href="seldog.php?curval=' . $row['id'] . '&gend=1&letter=a">' . $rowfetch['naam'] . '</a>')); |
||
127 | } |
||
128 | } else { |
||
129 | $form->addElement(new \XoopsFormLabel('<b>' . strtr(_MA_PEDIGREE_FLD_MOTH, ['[mother]' => $moduleConfig['mother']]) . '</b>', '<img src="assets/images/female.gif"><a href="seldog.php?curval=' . $row['id'] . '&gend=1&letter=a">Unknown</a>')); |
||
130 | } |
||
131 | //owner/breeder |
||
132 | if ('1' == $moduleConfig['ownerbreeder']) { |
||
133 | $owner_select = new \XoopsFormSelect('<b>' . _MA_PEDIGREE_FLD_OWNE . '</b>', $name = 'id_owner', $value = $row['id_owner'], $size = 1, $multiple = false); |
||
134 | $queryeig = 'SELECT id, lastname, firstname FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_owner') . ' ORDER BY "lastname"'; |
||
135 | $reseig = $GLOBALS['xoopsDB']->query($queryeig); |
||
136 | $owner_select->addOption(0, $name = _MA_PEDIGREE_UNKNOWN); |
||
137 | while (false !== ($roweig = $GLOBALS['xoopsDB']->fetchArray($reseig))) { |
||
138 | $owner_select->addOption($roweig['id'], $name = $roweig['lastname'] . ', ' . $roweig['firstname']); |
||
139 | } |
||
140 | $form->addElement($owner_select); |
||
141 | //breeder |
||
142 | $breeder_select = new \XoopsFormSelect('<b>' . _MA_PEDIGREE_FLD_BREE . '</b>', $name = 'id_breeder', $value = $row['id_breeder'], $size = 1, $multiple = false); |
||
143 | $queryfok = 'SELECT id, lastname, firstname FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_owner') . ' ORDER BY "lastname"'; |
||
144 | $resfok = $GLOBALS['xoopsDB']->query($queryfok); |
||
145 | $breeder_select->addOption(0, $name = _MA_PEDIGREE_UNKNOWN); |
||
146 | while (false !== ($rowfok = $GLOBALS['xoopsDB']->fetchArray($resfok))) { |
||
147 | $breeder_select->addOption($rowfok['id'], $name = $rowfok['lastname'] . ', ' . $rowfok['firstname']); |
||
148 | } |
||
149 | $form->addElement($breeder_select); |
||
150 | } |
||
151 | //picture |
||
152 | if ('' != $row['foto']) { |
||
153 | $picture = '<img src=' . PEDIGREE_UPLOAD_URL . '/images/thumbnails/' . $row['foto'] . '_400.jpeg>'; |
||
154 | $form->addElement(new \XoopsFormLabel('<b>Picture</b>', $picture)); |
||
155 | } else { |
||
156 | $picture = ''; |
||
157 | } |
||
158 | $form->setExtra("enctype='multipart/form-data'"); |
||
159 | $img_box = new \XoopsFormFile('<b>Image</b>', 'photo', 1024000); |
||
160 | $img_box->setExtra("size ='50'"); |
||
161 | $form->addElement($img_box); |
||
162 | //userfields |
||
163 | //create animal object |
||
164 | $animal = new Pedigree\Animal($id); |
||
165 | //test to find out how many user fields there are.. |
||
166 | $fields = $animal->getNumOfFields(); |
||
167 | for ($i = 0, $iMax = count($fields); $i < $iMax; ++$i) { |
||
168 | $userField = new Pedigree\Field($fields[$i], $animal->getConfig()); |
||
169 | if ($userField->isActive()) { |
||
170 | $fieldType = $userField->getSetting('FieldType'); |
||
171 | $fieldObject = new $fieldType($userField, $animal); |
||
172 | $edditable[$i] = $fieldObject->editField(); |
||
173 | $form->addElement($edditable[$i]); |
||
174 | } |
||
175 | } |
||
176 | } |
||
177 | $form->addElement(new \XoopsFormButton('', 'button_id', _MA_PEDIGREE_BUT_SUB, 'submit')); |
||
178 | $xoopsTpl->assign('form', $form->render()); |
||
179 | } |
||
183 |