Conditions | 24 |
Paths | > 20000 |
Total Lines | 212 |
Code Lines | 131 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
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 |
||
37 | $GLOBALS['xoopsTpl']->assign('page_title', _MA_PEDIGREE_VIRTUAL_PAGETITLE); |
||
38 | |||
39 | $f = Request::getCmd('f', '', 'GET'); |
||
40 | |||
41 | switch($f) { |
||
42 | case 'dam': |
||
43 | $pages = ''; |
||
44 | $st = Request::getString('st', 0, 'GET'); |
||
45 | $l = Request::getString('l', 'a', 'GET'); |
||
46 | $selsire = Request::getInt('selsire', 0, 'GET'); |
||
47 | |||
48 | $GLOBALS['xoopsTpl']->assign('sire', '1'); |
||
49 | //create list of males dog to select from |
||
50 | $perPage = $helper->getConfig('perpage'); |
||
51 | $perPage = (int)$perPage > 0 ? (int)$perPage : 10; // make sure $perPage is 'valid' |
||
52 | |||
53 | //Count total number of dogs |
||
54 | $numDog = 'SELECT COUNT(d.id) FROM ' |
||
55 | . $GLOBALS['xoopsDB']->prefix('pedigree_tree') |
||
56 | . ' d LEFT JOIN ' |
||
57 | . $GLOBALS['xoopsDB']->prefix('pedigree_tree') |
||
58 | . ' m ON m.id = d.mother LEFT JOIN ' |
||
59 | . $GLOBALS['xoopsDB']->prefix('pedigree_tree') |
||
60 | // . " f ON f.id = d.father WHERE d.roft = '1' and d.mother != '0' and d.father != '0' and m.mother != '0' and m.father != '0' and f.mother != '0' and f.father != '0' and d.naam LIKE '" . $l . "%'"; |
||
61 | . " f ON f.id = d.father WHERE d.roft = '1' AND d.mother != '0' AND d.father != '0' AND m.mother != '0' AND m.father != '0' AND f.mother != '0' AND f.father != '0' AND d.naam LIKE '" |
||
62 | . $GLOBALS['xoopsDB']->escape($l) |
||
63 | . "%'"; |
||
64 | |||
65 | $numRes = $GLOBALS['xoopsDB']->query($numDog); |
||
66 | |||
67 | //total number of dogs the query will find |
||
68 | list($numResults) = $GLOBALS['xoopsDB']->fetchRow($numRes); |
||
69 | //total number of pages |
||
70 | $numPages = floor($numResults / $perPage) + 1; |
||
71 | if (($numPages * $perPage) == ($numResults + $perPage)) { |
||
72 | --$numPages; |
||
73 | } |
||
74 | //find current page |
||
75 | $currentPage = floor($st / $perPage) + 1; |
||
76 | |||
77 | //create the alphabet |
||
78 | $pages .= "<a href=\"" . $helper->url("virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=a") . "\">A</a> "; |
||
79 | $pages .= "<a href=\"" . $helper->url("virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=b") . "\">B</a> "; |
||
80 | $pages .= "<a href=\"" . $helper->url("virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=c") . "\">C</a> "; |
||
81 | $pages .= "<a href=\"" . $helper->url("virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=d") . "\">D</a> "; |
||
82 | $pages .= "<a href=\"" . $helper->url("virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=e") . "\">E</a> "; |
||
83 | $pages .= "<a href=\"" . $helper->url("virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=f") . "\">F</a> "; |
||
84 | $pages .= "<a href=\"" . $helper->url("virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=g") . "\">G</a> "; |
||
85 | $pages .= "<a href=\"" . $helper->url("virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=h") . "\">H</a> "; |
||
86 | $pages .= "<a href=\"" . $helper->url("virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=i") . "\">I</a> "; |
||
87 | $pages .= "<a href=\"" . $helper->url("virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=j") . "\">J</a> "; |
||
88 | $pages .= "<a href=\"" . $helper->url("virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=k") . "\">K</a> "; |
||
89 | $pages .= "<a href=\"" . $helper->url("virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=l") . "\">L</a> "; |
||
90 | $pages .= "<a href=\"" . $helper->url("virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=m") . "\">M</a> "; |
||
91 | $pages .= "<a href=\"" . $helper->url("virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=n") . "\">N</a> "; |
||
92 | $pages .= "<a href=\"" . $helper->url("virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=o") . "\">O</a> "; |
||
93 | $pages .= "<a href=\"" . $helper->url("virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=p") . "\">P</a> "; |
||
94 | $pages .= "<a href=\"" . $helper->url("virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=q") . "\">Q</a> "; |
||
95 | $pages .= "<a href=\"" . $helper->url("virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=r") . "\">R</a> "; |
||
96 | $pages .= "<a href=\"" . $helper->url("virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=s") . "\">S</a> "; |
||
97 | $pages .= "<a href=\"" . $helper->url("virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=t") . "\">T</a> "; |
||
98 | $pages .= "<a href=\"" . $helper->url("virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=u") . "\">U</a> "; |
||
99 | $pages .= "<a href=\"" . $helper->url("virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=v") . "\">V</a> "; |
||
100 | $pages .= "<a href=\"" . $helper->url("virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=w") . "\">W</a> "; |
||
101 | $pages .= "<a href=\"" . $helper->url("virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=x") . "\">X</a> "; |
||
102 | $pages .= "<a href=\"" . $helper->url("virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=y") . "\">Y</a> "; |
||
103 | $pages .= "<a href=\"" . $helper->url("virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=z") . "\">Z</a> "; |
||
104 | $pages .= "- "; |
||
105 | $pages .= "<a href=\"" . $helper->url("virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=Ã…") . "\">Ã…</a> "; |
||
106 | $pages .= "<a href=\"" . $helper->url("virtual.php?f=dam&selsire=" . $selsire . "&st=0&l=Ö") . "\">Ö</a> "; |
||
107 | //create linebreak |
||
108 | $pages .= '<br>'; |
||
109 | //create previous button |
||
110 | if ($numPages > 1) { |
||
111 | if ($currentPage > 1) { |
||
112 | $pages .= "<a href=\"" . $helper->url("virtual.php?f=dam&selsire={$selsire}&l={$l}&st=" . ($st - $perPage)) . "\">" . _MA_PEDIGREE_PREVIOUS . "</a>  "; |
||
113 | } |
||
114 | } |
||
115 | //create numbers |
||
116 | for ($x = 1; $x < ($numPages + 1); ++$x) { |
||
117 | //create line break after 20 number |
||
118 | if (0 == ($x % 20)) { |
||
119 | $pages .= '<br>'; |
||
120 | } |
||
121 | if ($x != $currentPage) { |
||
122 | $pages .= "<a href=\"" . $helper->url("virtual.php?f=dam&selsire={$selsire}&l={$l}&st=" . ($perPage * ($x - 1))) . "\">{$x}</a> "; |
||
123 | } else { |
||
124 | $pages .= $x . '  '; |
||
125 | } |
||
126 | } |
||
127 | //create next button |
||
128 | if ($numPages > 1) { |
||
129 | if ($currentPage < $numPages) { |
||
130 | $pages .= "<a href=\"" . $helper->url("virtual.php?f=dam&selsire={$selsire}&l={$l}&st=" . ($st + $perPage)) . "\">" . _MA_PEDIGREE_NEXT . "</a>  "; |
||
131 | } |
||
132 | } |
||
133 | |||
134 | //query |
||
135 | $queryString = 'SELECT d.*, d.id AS d_id, d.naam AS d_naam FROM ' |
||
136 | . $GLOBALS['xoopsDB']->prefix('pedigree_tree') |
||
137 | . ' d LEFT JOIN ' |
||
138 | . $GLOBALS['xoopsDB']->prefix('pedigree_tree') |
||
139 | . ' m ON m.id = d.mother LEFT JOIN ' |
||
140 | . $GLOBALS['xoopsDB']->prefix('pedigree_tree') |
||
141 | . " f ON f.id = d.father WHERE d.roft = '1' AND d.mother != '0' AND d.father != '0' AND m.mother != '0' AND m.father != '0' AND f.mother != '0' AND f.father != '0' AND d.naam LIKE '" |
||
142 | . $l |
||
143 | . "%' ORDER BY d.naam LIMIT " |
||
144 | . $st |
||
145 | . ', ' |
||
146 | . $perPage; |
||
147 | $result = $GLOBALS['xoopsDB']->query($queryString); |
||
148 | |||
149 | $animal = new Pedigree\Animal(); |
||
150 | //test to find out how many user fields there are... |
||
151 | $fields = $animal->getNumOfFields(); |
||
152 | $numOfColumns = 1; |
||
153 | $columns[] = ['columnname' => 'Name']; |
||
154 | foreach ($fields as $i => $iValue) { |
||
155 | $userField = new Pedigree\Field($fields[$i], $animal->getConfig()); |
||
156 | $fieldType = $userField->getSetting('FieldType'); |
||
157 | $fieldObject = new $fieldType($userField, $animal); |
||
158 | //create empty string |
||
159 | $lookupValues = ''; |
||
160 | if ($userField->isActive() && $userField->inList()) { |
||
161 | if ($userField->hasLookup()) { |
||
162 | $lookupValues = $userField->lookupField($fields[$i]); |
||
163 | //debug information |
||
164 | //print_r($lookupValues); |
||
165 | } |
||
166 | $columns[] = [ |
||
167 | 'columnname' => $fieldObject->fieldname, |
||
168 | 'columnnumber' => $userField->getId(), |
||
169 | 'lookupval' => $lookupValues, |
||
170 | ]; |
||
171 | ++$numOfColumns; |
||
172 | unset($lookupValues); |
||
173 | } |
||
174 | } |
||
175 | |||
176 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
177 | //create picture information |
||
178 | if ('' != $row['foto']) { |
||
179 | $camera = ' <img src="' . PEDIGREE_UPLOAD_URL . '/images/dog-icon25.png">'; |
||
|
|||
180 | } else { |
||
181 | $camera = ''; |
||
182 | } |
||
183 | $name = stripslashes($row['d_naam']) . $camera; |
||
184 | //empty array |
||
185 | unset($columnvalue); |
||
186 | //fill array |
||
187 | for ($i = 1; $i < $numOfColumns; ++$i) { |
||
188 | $x = $columns[$i]['columnnumber']; |
||
189 | //echo $x."columnnumber"; |
||
190 | if (is_array($columns[$i]['lookupval'])) { |
||
191 | foreach ($columns[$i]['lookupval'] as $key => $keyValue) { |
||
192 | if ($keyValue['id'] == $row['user' . $x]) { |
||
193 | //echo "key:".$row['user5']."<br>"; |
||
194 | $value = $keyValue['value']; |
||
195 | } |
||
196 | } |
||
197 | //debug information |
||
198 | ///echo $columns[$i]['columnname']."is an array !"; |
||
199 | } //format value - cant use object because of query count |
||
200 | elseif (0 === strncmp($row['user' . $x], 'http://', 7)) { |
||
201 | $value = '<a href="' . $row['user' . $x] . '">' . $row['user' . $x] . '</a>'; |
||
202 | } else { |
||
203 | $value = $row['user' . $x]; |
||
204 | } |
||
205 | $columnvalue[] = ['value' => $value]; |
||
206 | unset($value); |
||
207 | } |
||
208 | $dogs[] = [ |
||
209 | 'id' => $row['d_id'], |
||
210 | 'name' => $name, |
||
211 | 'gender' => '<img src="assets/images/female.gif">', |
||
212 | 'link' => "<a href=\"" / $helper->url("virtual.php?f=check&selsire={$selsire}&seldam={$row['d_id']}") . "\">{$name}</a>", |
||
213 | 'colour' => '', |
||
214 | 'number' => '', |
||
215 | 'usercolumns' => isset($columnvalue) ? $columnvalue : 0, |
||
216 | ]; |
||
217 | } |
||
218 | |||
219 | //add data to smarty template |
||
220 | $GLOBALS['xoopsTpl']->assign([ |
||
221 | 'dogs' => $dogs, |
||
222 | 'columns' => $columns, |
||
223 | 'numofcolumns' => $numOfColumns, |
||
224 | 'tsarray' => Pedigree\Utility::sortTable($numOfColumns), |
||
225 | 'nummatch' => strtr(_MA_PEDIGREE_ADD_SELDAM, ['[mother]' => $helper->getConfig('mother')]), |
||
226 | 'pages' => $pages, |
||
227 | 'virtualtitle' => _MA_PEDIGREE_VIRUTALTIT, |
||
228 | 'virtualstory' => strtr(_MA_PEDIGREE_VIRUTALSTO, [ |
||
229 | '[mother]' => $helper->getConfig('mother'), |
||
230 | '[father]' => $helper->getConfig('father'), |
||
231 | '[children]' => $helper->getConfig('children')]), |
||
232 | 'nextaction' => '<span style="font-weight: bold;">' . strtr(_MA_PEDIGREE_VIRT_DAM, ['[mother]' => $helper->getConfig('mother')]) . '</span>', |
||
233 | 'virtualsiretitle' => strtr(_MA_PEDIGREE_VIRTUALSTIT, ['[father]' => $helper->getConfig('father')]) |
||
234 | ]); |
||
235 | |||
236 | //Find Father |
||
237 | //@todo - this looks wrong, shouldn't this be looking at 'father' field, not 'id' |
||
238 | $sireArray = $treeHandler->get($selsire); |
||
239 | $vsire = $sireArray instanceof Pedigree\Tree ? $sireArray->getVar('naam') : ''; |
||
240 | /* |
||
241 | $query = 'SELECT id, naam FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' WHERE id=' . $selsire; |
||
242 | $result = $GLOBALS['xoopsDB']->query($query); |
||
243 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
244 | $vsire = stripslashes($row['naam']); |
||
245 | } |
||
246 | */ |
||
247 | $GLOBALS['xoopsTpl']->assign('virtualsire', $vsire); |
||
248 | |||
249 | //mb ========= MOTHER LETTERS=============================== |
||
496 |